/*! 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.ml_bundle_jsonpfunction=window.ml_bundle_jsonpfunction||[]).push([[20],{169:function(e,t,a){"use strict";a.d(t,"a",(function(){return l}));var s=a(21);const l=()=>Object(s.useKibana)()},260:function(e,t,a){"use strict";a.d(t,"a",(function(){return c})),a(2);var s=a(11),l=a(10),o=a(21),i=a(135),n=a(190),r=a(4);function c(e,t,a,c,d,b,u){const{http:j,theme:m,i18n:x,overlays:O,application:{currentAppId$:g}}=a;return new Promise((async(p,E)=>{try{const E=()=>{S.close(),p()},S=O.openFlyout(Object(i.a)(Object(r.jsx)(o.KibanaContextProvider,{services:{...a,share:c,data:d,lens:u,dashboardService:b,mlServices:Object(n.getMlGlobalServices)(j)}},Object(r.jsx)(e,{embeddable:t,onClose:()=>{E(),p()}})),{theme:m,i18n:x}),{"data-test-subj":"mlFlyoutLayerSelector",ownFocus:!0,onClose:E,size:"35vw"});g.pipe(Object(s.skip)(1),Object(s.takeUntil)(Object(l.from)(S.onClose)),Object(s.distinctUntilChanged)()).subscribe((()=>{S.close()}))}catch(e){E(e)}}))}},261:function(e,t,a){"use strict";a.d(t,"a",(function(){return E}));var s,l=a(2),o=a.n(l),i=a(160),n=a.n(i),r=a(28),c=a(6),d=a(15),b=a(107),u=a(105),j=a(106),m=a(42),x=a(147),O=a(1),g=a(169),p=a(4);!function(e){e[e.DEFAULT=0]="DEFAULT",e[e.VALIDATING=1]="VALIDATING",e[e.SAVING=2]="SAVING",e[e.SAVE_SUCCESS=3]="SAVE_SUCCESS",e[e.SAVE_FAILED=4]="SAVE_FAILED"}(s||(s={}));const E=({children:e,createADJobInWizard:t,createADJob:a,layer:i,layerIndex:b,embeddable:E,incomingCreateError:y})=>{var F;const{services:{share:f,application:I,mlServices:{mlApiServices:C}}}=Object(g.a)(),[h,v]=Object(l.useState)(""),[w,A]=Object(l.useState)(!0),[k,M]=Object(l.useState)(!0),[T,L]=Object(l.useState)(u.b),[J,_]=Object(l.useState)(""),[V,z]=Object(l.useState)(""),[D,G]=Object(l.useState)(s.DEFAULT),[N,R]=Object(l.useState)(null),B=null!==(F=null==i?void 0:i.jobType)&&void 0!==F?F:u.f.GEO,U=Object(l.useCallback)((async e=>{const{timeRange:t}=E.getInput(),a=f.url.locators.get(O.a);if(a){const s=w?e===u.f.MULTI_METRIC||e===u.f.GEO?O.b.ANOMALY_EXPLORER:O.b.SINGLE_METRIC_VIEWER:O.b.ANOMALY_DETECTION_JOBS_MANAGE,l=w?{jobIds:[h],timeRange:t}:{jobId:h},o=await a.getUrl({page:s,pageState:l});I.navigateToUrl(o)}}),[h,E,f,I,w]);return n()((function(){if(void 0===h||""===h)return;_(""),z("");const e=Object(j.e)({job_id:h,analysis_config:{detectors:[],bucket_span:T}},void 0,{max_model_memory_limit:"",effective_max_model_memory_limit:""},!0);e.contains("job_id_invalid")?_(c.i18n.translate("xpack.ml.newJob.wizard.validateJob.jobNameAllowedCharactersDescription",{defaultMessage:"Job ID can contain lowercase alphanumeric (a-z and 0-9), hyphens or underscores; must start and end with an alphanumeric character"})):e.contains("job_id_invalid_max_length")?_(c.i18n.translate("xpack.ml.newJob.wizard.validateJob.jobIdInvalidMaxLengthErrorMessage",{defaultMessage:"Job ID must be no more than {maxLength, plural, one {# character} other {# characters}} long.",values:{maxLength:m.b}})):C.jobs.jobsExist([h]).then((e=>{e[h].exists&&_(c.i18n.translate("xpack.ml.newJob.wizard.validateJob.jobNameAlreadyExists",{defaultMessage:"Job ID already exists. A job ID cannot be the same as an existing job or group."}))})).catch((e=>{console.error("Could not validate whether job ID exists")})),e.contains("bucket_span_invalid")&&z(Object(x.a)(T)),G(s.DEFAULT)}),500,[h,T]),Object(p.jsx)(o.a.Fragment,null,D!==s.SAVE_SUCCESS&&D!==s.SAVING||y?Object(p.jsx)(o.a.Fragment,null,null!=e?e:null,Object(p.jsx)(r.EuiSpacer,{size:"m"}),Object(p.jsx)(r.EuiForm,null,Object(p.jsx)(r.EuiFormRow,{label:c.i18n.translate("xpack.ml.newJob.wizard.jobDetailsStep.jobId.title",{defaultMessage:"Job ID"}),error:J,isInvalid:""!==J},Object(p.jsx)(r.EuiFieldText,{"data-test-subj":`mlLensLayerJobIdInput_${b}`,value:h,onChange:e=>{v(e.target.value),G(s.VALIDATING)}})),Object(p.jsx)(r.EuiSpacer,{size:"s"}),Object(p.jsx)(r.EuiAccordion,{"data-test-subj":`mlLensLayerAdditionalSettingsButton_${b}`,id:"additional-section",buttonContent:c.i18n.translate("xpack.ml.embeddables.lensLayerFlyout.createJobCallout.additionalSettings.title",{defaultMessage:"Additional settings"})},Object(p.jsx)(r.EuiSpacer,{size:"s"}),Object(p.jsx)(r.EuiFormRow,{label:c.i18n.translate("xpack.ml.newJob.wizard.pickFieldsStep.bucketSpan.placeholder",{defaultMessage:"Bucket span"}),error:V,isInvalid:""!==V},Object(p.jsx)(r.EuiFieldText,{"data-test-subj":`mlLensLayerBucketSpanInput_${b}`,value:T,onChange:e=>{L(e.target.value),G(s.VALIDATING)}})),Object(p.jsx)(r.EuiSpacer,{size:"l"}),Object(p.jsx)(r.EuiFormRow,null,Object(p.jsx)(r.EuiCheckbox,{id:"startJob","data-test-subj":`mlLensLayerStartJobCheckbox_${b}`,checked:w,onChange:e=>{return t=e.target.checked,A(t),void M(t&&k);var t},label:c.i18n.translate("xpack.ml.embeddables.lensLayerFlyout.createJobCallout.additionalSettings.start",{defaultMessage:"Start the job after saving"})})),Object(p.jsx)(r.EuiSpacer,{size:"s"}),Object(p.jsx)(r.EuiFormRow,null,Object(p.jsx)(r.EuiCheckbox,{id:"realTime",disabled:!1===w,"data-test-subj":`mlLensLayerRealTimeCheckbox_${b}`,checked:k,onChange:e=>M(e.target.checked),label:c.i18n.translate("xpack.ml.embeddables.lensLayerFlyout.createJobCallout.additionalSettings.realTime",{defaultMessage:"Leave the job running for new data"})})),Object(p.jsx)(r.EuiSpacer,{size:"m"}))),Object(p.jsx)(r.EuiSpacer,{size:"m"}),Object(p.jsx)(r.EuiFlexGroup,null,Object(p.jsx)(r.EuiFlexItem,null,Object(p.jsx)(r.EuiButton,{disabled:D===s.VALIDATING||""===h||""!==J||""!==V,onClick:async function(){if(void 0===h||""===h)return;G(s.SAVING),R(null);const e=await a({jobId:h,bucketSpan:T,embeddable:E,startJob:w,runInRealTime:k}),t=S(e);null===t?G(s.SAVE_SUCCESS):(G(s.SAVE_FAILED),R(t))}.bind(null,b),size:"s","data-test-subj":`mlLensLayerCreateJobButton_${b}`},Object(p.jsx)(d.FormattedMessage,{id:"xpack.ml.embeddables.lensLayerFlyout.createJobButton.saving",defaultMessage:"Create job"}))),Object(p.jsx)(r.EuiFlexItem,{grow:!1},Object(p.jsx)(r.EuiButtonEmpty,{onClick:t.bind(null,b),size:"s",iconType:"popout",iconSide:"right","data-test-subj":`mlLensLayerCreateWithWizardButton_${b}`},Object(p.jsx)(d.FormattedMessage,{id:"xpack.ml.embeddables.lensLayerFlyout.createJobButton",defaultMessage:"Create job using wizard"}))))):null,D===s.SAVE_SUCCESS?Object(p.jsx)(o.a.Fragment,null,Object(p.jsx)(r.EuiFlexGroup,{gutterSize:"s","data-test-subj":`mlLensLayerCompatible.jobCreated.success_${b}`},Object(p.jsx)(r.EuiFlexItem,{grow:!1},Object(p.jsx)(r.EuiText,{size:"s"},Object(p.jsx)(r.EuiIcon,{type:"checkInCircleFilled",color:"success"}))),Object(p.jsx)(r.EuiFlexItem,null,Object(p.jsx)(r.EuiText,{size:"s"},Object(p.jsx)(d.FormattedMessage,{id:"xpack.ml.embeddables.flyout.flyoutAdditionalSettings.saveSuccess",defaultMessage:"Job created"})))),Object(p.jsx)(r.EuiSpacer,{size:"s"}),Object(p.jsx)(r.EuiButtonEmpty,{onClick:U.bind(null,B),flush:"left","data-test-subj":`mlLensLayerResultsButton_${b}`},!1===w?Object(p.jsx)(d.FormattedMessage,{id:"xpack.ml.embeddables.flyoutAdditionalSettings.saveSuccess.resultsLink.jobList",defaultMessage:"View in job management page"}):B===u.f.MULTI_METRIC||B===u.f.GEO?Object(p.jsx)(d.FormattedMessage,{id:"xpack.ml.embeddables.flyoutAdditionalSettings.saveSuccess.resultsLink.multiMetric",defaultMessage:"View results in Anomaly Explorer"}):Object(p.jsx)(d.FormattedMessage,{id:"xpack.ml.embeddables.flyoutAdditionalSettings.saveSuccess.resultsLink.singleMetric",defaultMessage:"View results in Single Metric Viewer"}))):null,D===s.SAVING&&void 0===y?Object(p.jsx)(o.a.Fragment,null,Object(p.jsx)(r.EuiFlexGroup,null,Object(p.jsx)(r.EuiFlexItem,{grow:!1},Object(p.jsx)(d.FormattedMessage,{id:"xpack.ml.embeddables.flyoutAdditionalSettings.creatingJob",defaultMessage:"Creating job"})),Object(p.jsx)(r.EuiFlexItem,{grow:!1},Object(p.jsx)(r.EuiLoadingSpinner,null)))):null,D===s.SAVE_FAILED&&null!==N?Object(p.jsx)(o.a.Fragment,null,Object(p.jsx)(r.EuiSpacer,null),Object(p.jsx)(r.EuiCallOut,{color:"danger",title:N.text},N.errorText)):null,y?Object(p.jsx)(o.a.Fragment,null,Object(p.jsx)(r.EuiSpacer,null),Object(p.jsx)(r.EuiCallOut,{color:"danger",title:y.text},y.errorText)):null)},S=e=>e.jobCreated.error?{text:c.i18n.translate("xpack.ml.embeddables.flyoutAdditionalSettings.jobCreateError.jobCreated",{defaultMessage:"Job could not be created."}),errorText:Object(b.b)(e.jobCreated.error)}:e.datafeedCreated.error?{text:c.i18n.translate("xpack.ml.embeddables.flyoutAdditionalSettings.jobCreateError.datafeedCreated",{defaultMessage:"Job created but datafeed could not be created."}),errorText:Object(b.b)(e.datafeedCreated.error)}:e.jobOpened.error?{text:c.i18n.translate("xpack.ml.embeddables.flyoutAdditionalSettings.jobCreateError.jobOpened",{defaultMessage:"Job and datafeed created but the job could not be opened."}),errorText:Object(b.b)(e.jobOpened.error)}:e.datafeedStarted.error?{text:c.i18n.translate("xpack.ml.embeddables.flyoutAdditionalSettings.jobCreateError.datafeedStarted",{defaultMessage:"Job and datafeed created but the datafeed could not be started."}),errorText:Object(b.b)(e.datafeedStarted.error)}:null},678:function(e,t,a){"use strict";a.r(t),a.d(t,"showMapVisToADJobFlyout",(function(){return g}));var s=a(4),l=a(2),o=a.n(l),i=a(15),n=a(28),r=a(6),c=a(216),d=a(169),b=a(261);const u=({embeddable:e,layer:t,layerIndex:a})=>{var u,j,m;const[x,O]=Object(l.useState)(null),[g,p]=Object(l.useState)(),{services:{data:E,share:S,uiSettings:y,dashboardService:F,mlServices:{mlApiServices:f}}}=Object(d.a)(),I=Object(l.useMemo)((()=>new c.QuickGeoJobCreator(y,E.query.timefilter.timefilter,F,f)),[E,y]),C=Object(l.useCallback)((()=>{Object(c.redirectToGeoJobWizard)(e,t.dataView.id,t.geoField,t.query,x,S)}),[null==t||null===(u=t.dataView)||void 0===u?void 0:u.id,e,x]),h=Object(l.useCallback)((async({jobId:e,bucketSpan:a,embeddable:s,startJob:l,runInRealTime:o})=>{try{return await I.createAndSaveGeoJob({jobId:e,bucketSpan:a,embeddable:s,startJob:l,runInRealTime:o,sourceDataView:t.dataView,geoField:t.geoField,layerLevelQuery:t.query,splitField:x})}catch(e){var i;return console.error(e),p({text:r.i18n.translate("xpack.ml.embeddables.geoJobFlyout.jobCreationError",{defaultMessage:"Job could not be created."}),errorText:null!==(i=e.message)&&void 0!==i?i:e}),{jobCreated:{success:!1},datafeedCreated:{success:!1},jobOpened:{success:!1},datafeedStarted:{success:!1}}}}),[I,e,x]),v=Object(l.useMemo)((()=>{const e=[];return x&&e.push({label:x,field:x}),e}),[x]),w=Object(l.useCallback)((e=>{const t=e[0];O(void 0!==t?t.field:null)}),[]);return Object(s.jsx)(o.a.Fragment,null,Object(s.jsx)(b.a,{layerIndex:a,createADJob:h,createADJobInWizard:C,embeddable:e,incomingCreateError:g},Object(s.jsx)(o.a.Fragment,null,Object(s.jsx)(n.EuiFlexGroup,{gutterSize:"s","data-test-subj":"mlMapLayerCompatible"},Object(s.jsx)(n.EuiFlexItem,{grow:!1},Object(s.jsx)(n.EuiText,{size:"s"},Object(s.jsx)(n.EuiIcon,{type:"checkInCircleFilled",color:"success"}))),Object(s.jsx)(n.EuiFlexItem,null,Object(s.jsx)(n.EuiText,{size:"s"},Object(s.jsx)(i.FormattedMessage,{id:"xpack.ml.embeddables.geoJobFlyout.createJobCalloutTitle.multiMetric",defaultMessage:"The {geoField} field can be used to create a geo job for {sourceDataViewTitle}",values:{geoField:t.geoField,sourceDataViewTitle:null===(j=t.dataView)||void 0===j?void 0:j.getIndexPattern()}})))),null!==(m=t.splitFieldOptions)&&void 0!==m&&m.length?Object(s.jsx)(o.a.Fragment,null,Object(s.jsx)(n.EuiSpacer,{size:"m"}),Object(s.jsx)(n.EuiAccordion,{"data-test-subj":"mlGeoJobAdditionalSettingsButton",id:"additional-section",buttonContent:r.i18n.translate("xpack.ml.embeddables.geoJobFlyout.createJobCallout.splitField.title",{defaultMessage:"Optionally select a field to split the data"})},Object(s.jsx)(n.EuiFormRow,{label:Object(s.jsx)(i.FormattedMessage,{id:"xpack.ml.embeddables.geoJobFlyout.selectSplitField",defaultMessage:"Split field"})},Object(s.jsx)(n.EuiComboBox,{singleSelection:{asPlainText:!0},options:t.splitFieldOptions,selectedOptions:v,onChange:w,isClearable:!0,"data-test-subj":"mlGeoJobSplitFieldSelect"})))):null)))},j=({noDataView:e})=>Object(s.jsx)(n.EuiFlexGroup,{gutterSize:"s",color:"subdued","data-test-subj":"mlMapLayerIncompatible"},Object(s.jsx)(n.EuiFlexItem,{grow:!1},Object(s.jsx)(n.EuiText,{size:"s"},Object(s.jsx)(n.EuiIcon,{type:"error",color:"subdued"}))),Object(s.jsx)(n.EuiFlexItem,null,Object(s.jsx)(n.EuiText,{color:"subdued",size:"s"},!0===e?Object(s.jsx)(i.FormattedMessage,{id:"xpack.ml.embeddables.geoJobFlyout.noDataViewError",defaultMessage:"There is no source data view for this layer. It cannot be used to create an anomaly detection job"}):Object(s.jsx)(i.FormattedMessage,{id:"xpack.ml.embeddables.geoJobFlyout.noTimeFieldError",defaultMessage:"The source data view for this layer does not contain a timestamp field. It cannot be used to create an anomaly detection job"})))),m=({layer:e,layerIndex:t,embeddable:a})=>{var l;return Object(s.jsx)(o.a.Fragment,null,Object(s.jsx)(n.EuiSplitPanel.Outer,{grow:!0},Object(s.jsx)(n.EuiSplitPanel.Inner,null,Object(s.jsx)(n.EuiFlexGroup,{gutterSize:"s",alignItems:"center",responsive:!1},Object(s.jsx)(n.EuiFlexItem,{grow:!1},Object(s.jsx)(n.EuiIcon,{type:"tokenGeo"})),Object(s.jsx)(n.EuiFlexItem,{grow:!0},Object(s.jsx)(n.EuiText,{color:null!==(l=e.dataView)&&void 0!==l&&l.timeFieldName?"":"subdued"},Object(s.jsx)("h5",null,e.layerDisplayName))))),Object(s.jsx)(n.EuiHorizontalRule,{margin:"none"}),Object(s.jsx)(n.EuiSplitPanel.Inner,{grow:!1,color:"plain"},e.dataView&&e.dataView.timeFieldName?Object(s.jsx)(u,{embeddable:a,layer:e,layerIndex:t}):Object(s.jsx)(j,{noDataView:void 0===e.dataView}))),Object(s.jsx)(n.EuiSpacer,null))},x=({onClose:e,embeddable:t})=>{const{euiTheme:a}=Object(n.useEuiTheme)(),[r,d]=Object(l.useState)([]);return Object(l.useEffect)((()=>{(new c.VisualizationExtractor).getResultLayersFromEmbeddable(t).then(d).catch((t=>{console.error("Layers could not be extracted from embeddable",t),e()}))}),[t,e]),Object(s.jsx)(o.a.Fragment,null,Object(s.jsx)(n.EuiFlyoutHeader,{hasBorder:!0},Object(s.jsx)(n.EuiTitle,{size:"s"},Object(s.jsx)("h3",null,Object(s.jsx)(i.FormattedMessage,{id:"xpack.ml.embeddables.geoJobFlyout.title",defaultMessage:"Create anomaly detection job"}))),Object(s.jsx)(n.EuiSpacer,{size:"m"}),Object(s.jsx)(n.EuiText,{size:"s"},Object(s.jsx)(i.FormattedMessage,{id:"xpack.ml.embeddables.geoJobFlyout.secondTitle",defaultMessage:"Create an anomaly detection lat_long job from map visualization {title}.",values:{title:t.getTitle()}}))),Object(s.jsx)(n.EuiFlyoutBody,{css:Object(s.css)({backgroundColor:a.colors.lightestShade},"","")},r.map(((e,a)=>Object(s.jsx)(m,{key:`${e.layerId}`,layer:e,layerIndex:a,embeddable:t})))),Object(s.jsx)(n.EuiFlyoutFooter,null,Object(s.jsx)(n.EuiFlexGroup,{justifyContent:"spaceBetween"},Object(s.jsx)(n.EuiFlexItem,{grow:!1},Object(s.jsx)(n.EuiButtonEmpty,{iconType:"cross",onClick:e,flush:"left"},Object(s.jsx)(i.FormattedMessage,{id:"xpack.ml.embeddables.geoJobFlyout.closeButton",defaultMessage:"Close"}))))))};var O=a(260);async function g(e,t,a,s,l){return Object(O.a)(x,e,t,a,s,l)}}}]);