/*! Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one or more contributor license agreements. * Licensed under the Elastic License 2.0; you may not use this file except in compliance with the Elastic License 2.0. */ (window.osquery_bundle_jsonpfunction=window.osquery_bundle_jsonpfunction||[]).push([[11],{171:function(e,u,r){"use strict";r.r(u),r.d(u,"default",(function(){return v}));var c=r(1),s=r.n(c),a=r(6),t=r(16),n=r(15),i=r(79),o=r(100),p=r(4),d=r(115),l=r(123),j=r(0);const b=({defaultValues:e,onError:u,onChange:r})=>{const b=Object(t.useForm)({mode:"all",defaultValues:e?{...Object(n.omit)(e,["ecsMapping","packId"]),ecs_mapping:e.ecsMapping,packId:e.packId?[e.packId]:[],queryType:e.packId?"pack":"query"}:{ecs_mapping:{},queryType:"query"}}),{watch:v,register:y,formState:k,control:O}=b,[q,f,m]=v(["packId","queryType","queries"]),{data:I}=Object(i.a)({packId:null==q?void 0:q[0],skip:!(null!=q&&q[0])}),{replace:g}=Object(t.useFieldArray)({name:"queries",control:O});Object(c.useEffect)((()=>{if(null!=I&&I.queries){const e=Object(n.map)(null==I?void 0:I.queries,((e,u)=>({...e,id:u})));g(e)}}),[I,g]),Object(c.useEffect)((()=>{u(k.errors)}),[u,k]),Object(c.useEffect)((()=>{y("savedQueryId")}),[y]),Object(c.useEffect)((()=>{const e=v((e=>{var u;r("pack"===e.queryType?{packId:null!=e&&null!==(u=e.packId)&&void 0!==u&&u.length?null==e?void 0:e.packId[0]:void 0,queries:e.queries}:{savedQueryId:e.savedQueryId,query:e.query,ecsMapping:e.ecs_mapping})}));return()=>e.unsubscribe()}),[r,I,v]);const Q=Object(p.e)().services.application.capabilities.osquery,w=Object(c.useMemo)((()=>!(!Q.runSavedQueries&&!Q.writeLiveQueries||!Q.readPacks)),[Q]),_=Object(c.useMemo)((()=>!!(Q.writeLiveQueries||Q.runSavedQueries&&Q.readSavedQueries)),[Q]),x=Object(c.useMemo)((()=>({queries:m,agents:[]})),[m]);return Object(j.jsx)(s.a.Fragment,null,Object(j.jsx)(t.FormProvider,b,Object(j.jsx)(o.a,{canRunPacks:w,canRunSingleQuery:_}),Object(j.jsx)(a.EuiSpacer,{size:"m"}),"query"===f&&Object(j.jsx)(d.LiveQueryQueryField,null),"pack"===f&&Object(j.jsx)(l.a,{liveQueryDetails:m&&!I?x:void 0})))},v=s.a.memo(b)},79:function(e,u,r){"use strict";r.d(u,"a",(function(){return t}));var c=r(11),s=r(2),a=r(4);const t=({packId:e,skip:u=!1})=>{const{http:r}=Object(a.e)().services;return Object(c.useQuery)(["pack",{packId:e}],(()=>r.get(`/api/osquery/packs/${e}`,{version:s.a.public.v1})),{select:e=>null==e?void 0:e.data,keepPreviousData:!0,enabled:!(u||!e)})}}}]);