/*! 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.alerting_bundle_jsonpfunction=window.alerting_bundle_jsonpfunction||[]).push([[1],{51:function(e,t,n){"use strict";n.d(t,"a",(function(){return J}));var a=n(14),i=n.n(a),l=n(17),s=n.n(l),o=n(19),u=n(24),r=n(16),c=n(23);const d=[...n.n(c).a.tz.names().filter((e=>!["America/Nuuk","EST","HST","ROC","MST"].includes(e)))];var b=n(31),m=n(35),j=n(32),O=n(34);const{emptyField:p}=b.fieldValidators,f={title:{type:o.FIELD_TYPES.TEXT,label:j.ib,validations:[{validator:p(j.J)}]},startDate:{},endDate:{},timezone:{},recurring:{type:o.FIELD_TYPES.TOGGLE,label:j.N,defaultValue:!1},recurringSchedule:{frequency:{type:o.FIELD_TYPES.SELECT,label:j.N,defaultValue:m.a.DAILY},interval:{type:o.FIELD_TYPES.NUMBER,label:"",defaultValue:1,validations:[{validator:p(j.H)}]},ends:{type:o.FIELD_TYPES.BUTTON_GROUP,label:j.t,defaultValue:O.d.NEVER,validations:[]},until:{},count:{label:"",type:o.FIELD_TYPES.TEXT,defaultValue:1,validations:[{validator:p(j.n)}]},customFrequency:{type:o.FIELD_TYPES.SELECT,label:"",defaultValue:m.a.WEEKLY},byweekday:{},bymonth:{type:o.FIELD_TYPES.BUTTON_GROUP,label:"",validations:[],defaultValue:"day"}}};var x=n(40),g=n(15),h=n(38);const E=Object(o.getUseField)({component:u.Field}),S={flexField:{name:"162yvs7",styles:".euiFormRow__labelWrapper{margin-bottom:unset;}"}},y=i.a.memo((()=>{const[{startDate:e,recurringSchedule:t}]=Object(o.useFormData)({watch:["startDate","recurringSchedule.frequency","recurringSchedule.interval","recurringSchedule.customFrequency"]}),n=Object(a.useMemo)((()=>Object(O.a)(null==t?void 0:t.interval)),[null==t?void 0:t.interval]),l=Object(a.useMemo)((()=>{if(!e)return[];const t=s()(e),{dayOfWeek:n,nthWeekdayOfMonth:a,isLastOfMonth:i}=Object(x.a)(t,"ddd");return[{id:"day",label:j.s(t)},{id:"weekday",label:j.S(n)[i?0:a]}]}),[e]),u=Object(a.useMemo)((()=>Object(h.a)([],s()(e))),[e]);return Object(g.jsx)(i.a.Fragment,null,(null==t?void 0:t.frequency)!==m.a.DAILY?Object(g.jsx)(i.a.Fragment,null,Object(g.jsx)(r.EuiSpacer,{size:"s"}),Object(g.jsx)(r.EuiFlexGroup,{gutterSize:"s",alignItems:"flexStart"},Object(g.jsx)(r.EuiFlexItem,null,Object(g.jsx)(E,{path:"recurringSchedule.interval",css:S.flexField,componentProps:{"data-test-subj":"interval-field",id:"interval",euiFieldProps:{min:1,prepend:Object(g.jsx)(r.EuiFormLabel,{htmlFor:"interval"},j.G)}}})),Object(g.jsx)(r.EuiFlexItem,null,Object(g.jsx)(E,{path:"recurringSchedule.customFrequency",componentProps:{"data-test-subj":"custom-frequency-field",euiFieldProps:{options:n}}}))),Object(g.jsx)(r.EuiSpacer,{size:"s"})):null,Number(null==t?void 0:t.customFrequency)===m.a.WEEKLY||(null==t?void 0:t.frequency)===m.a.DAILY?Object(g.jsx)(E,{path:"recurringSchedule.byweekday",config:{type:o.FIELD_TYPES.MULTI_BUTTON_GROUP,label:"",validations:[{validator:({value:e})=>{if(Object.values(e).every((e=>!1===e)))return{message:j.k}}}],defaultValue:u},componentProps:{"data-test-subj":"byweekday-field",euiFieldProps:{legend:"Repeat on weekday",options:O.k}}}):null,Number(null==t?void 0:t.customFrequency)===m.a.MONTHLY?Object(g.jsx)(E,{path:"recurringSchedule.bymonth",componentProps:{"data-test-subj":"bymonth-field",euiFieldProps:{legend:"Repeat on weekday or month day",options:l}}}):null)}));y.displayName="CustomRecurringSchedule";var F=n(47),v=n(41);const w=Object(o.getUseField)({component:u.Field}),D=e=>s()(e),I=e=>e.toISOString(),T=i.a.memo((()=>{const[e]=Object(a.useState)(s()()),[{startDate:t,endDate:n,timezone:l,recurringSchedule:u}]=Object(o.useFormData)({watch:["startDate","endDate","timezone","recurringSchedule.frequency","recurringSchedule.interval","recurringSchedule.ends","recurringSchedule.until","recurringSchedule.count","recurringSchedule.customFrequency","recurringSchedule.byweekday","recurringSchedule.bymonth"]}),{options:c,presets:d}=Object(a.useMemo)((()=>{if(!t)return{options:O.b,presets:O.c};const e=s()(t),{dayOfWeek:n,nthWeekdayOfMonth:a,isLastOfMonth:i}=Object(x.a)(e);return{options:[{text:j.y,value:m.a.DAILY},{text:j.D(n),value:m.a.WEEKLY},{text:j.A(n)[i?0:a],value:m.a.MONTHLY},{text:j.F(e),value:m.a.YEARLY},{text:j.x,value:"CUSTOM"}],presets:Object(v.a)(e)}}),[t]);return Object(g.jsx)(r.EuiSplitPanel.Outer,{hasShadow:!1,hasBorder:!0},Object(g.jsx)(r.EuiSplitPanel.Inner,{color:"subdued"},Object(g.jsx)(w,{path:"recurringSchedule.frequency",componentProps:{"data-test-subj":"frequency-field",euiFieldProps:{options:c}}}),(null==u?void 0:u.frequency)===m.a.DAILY||"CUSTOM"===(null==u?void 0:u.frequency)?Object(g.jsx)(y,{"data-test-subj":"custom-recurring-form"}):null,Object(g.jsx)(w,{path:"recurringSchedule.ends",componentProps:{"data-test-subj":"ends-field",euiFieldProps:{legend:"Recurrence ends",options:O.f}}}),(null==u?void 0:u.ends)===O.d.ON_DATE?Object(g.jsx)(i.a.Fragment,null,Object(g.jsx)(r.EuiSpacer,{size:"m"}),Object(g.jsx)(r.EuiFlexGroup,{alignItems:"flexEnd"},Object(g.jsx)(r.EuiFlexItem,{grow:3},Object(g.jsx)(w,{path:"recurringSchedule.until",config:{type:o.FIELD_TYPES.DATE_PICKER,label:"",defaultValue:s()(n).endOf("day").toISOString(),validations:[],serializer:I,deserializer:D},componentProps:{"data-test-subj":"until-field",euiFieldProps:{showTimeSelect:!1,minDate:e}}})),l?Object(g.jsx)(r.EuiFlexItem,{grow:1},Object(g.jsx)(r.EuiComboBox,{"data-test-subj":"disabled-timezone-field",id:"disabled-timezone",isDisabled:!0,singleSelection:{asPlainText:!0},selectedOptions:[{label:l[0]}],isClearable:!1,prepend:Object(g.jsx)(r.EuiFormLabel,{htmlFor:"disabled-timezone"},j.Q)})):null)):null,(null==u?void 0:u.ends)===O.d.AFTER_X?Object(g.jsx)(w,{path:"recurringSchedule.count",componentProps:{"data-test-subj":"count-field",id:"count",euiFieldProps:{type:"number",min:1,prepend:Object(g.jsx)(r.EuiFormLabel,{htmlFor:"count"},j.l),append:Object(g.jsx)(r.EuiFormLabel,{htmlFor:"count"},j.m)}}}):null),Object(g.jsx)(r.EuiHorizontalRule,{margin:"none"}),Object(g.jsx)(r.EuiSplitPanel.Inner,null,j.M(Object(F.a)(s()(t),u,d))))}));T.displayName="RecurringSchedule";const P=i.a.memo((({isLoading:e,editMode:t})=>{const{submit:n,isSubmitting:a}=Object(o.useFormContext)();return Object(g.jsx)(r.EuiButton,{"data-test-subj":"create-submit",fill:!0,isDisabled:e||a,isLoading:e||a,onClick:n},t?j.mb:j.V)}));P.displayName="SubmitButton";var L=n(48);const C=(e,t,n)=>{var a;const i=Object(v.a)(e),l={dtstart:e.toISOString(),tzid:t};if(!n)return{...l,freq:m.a.YEARLY,count:1};let s=n;"CUSTOM"!==n.frequency&&(s={...n,...i[n.frequency]});const o=null!==(a=s.customFrequency)&&void 0!==a?a:s.frequency;if(l.freq=o,l.interval=s.interval,s.until&&(l.until=s.until),s.count&&(l.count=s.count),s.byweekday){const e=s.byweekday;l.byweekday=Object.keys(e).filter((t=>!0===e[t])).map((e=>O.e[Number(e)]))}return s.bymonth&&("day"===s.bymonth?l.bymonthday=[e.date()]:"weekday"===s.bymonth&&(l.byweekday=[Object(L.a)(e)])),o===m.a.YEARLY&&(l.bymonth=[e.month()+1],l.bymonthday=[e.date()]),l};var _=n(1),z=n(18),k=n(33),R=n(2);const M=({rRule:e,...t})=>({...t,r_rule:e}),W=({r_rule:e,...t})=>({...t,rRule:e});const N=({rRule:e,...t})=>({...t,r_rule:e}),Y=({r_rule:e,...t})=>({...t,rRule:e});var A=n(37),q=n.n(A),B=n(5);function U(e,t,n){const a=Object(B.get)(e,t);let i=s()();a&&s()(a).isValid()&&(i=s()(a));const l=n&&n.length>0?s()().tz(n[0]).year(i.year()).month(i.month()).date(i.date()).hour(i.hour()).minute(i.minute()).second(i.second()).millisecond(i.millisecond()).utcOffset():i.utcOffset();return{selected:i.clone().utcOffset(l),utcOffset:l}}const V=i.a.memo((({fields:e,timezone:t,showTimeSelect:n=!0,...l})=>{const[u]=Object(a.useState)(s()()),{setFieldValue:c}=Object(o.useFormContext)(),[d]=Object(o.useFormData)({watch:[e.startDate.path,e.endDate.path]}),{selected:b,utcOffset:m}=U(d,e.startDate.path,t),{selected:O,utcOffset:p}=U(d,e.endDate.path,t),f=Object(a.useCallback)((t=>{if(t&&t.isAfter(O)){const n=s()(t).add(30,"minutes");c(e.endDate.path,n)}c(e.startDate.path,t?t.toISOString():t)}),[c,O,e.endDate.path,e.startDate.path]),x=Object(a.useCallback)((t=>{c(e.endDate.path,t?t.toISOString():t)}),[c,e.endDate.path]),h=b.isAfter(O);return Object(g.jsx)(i.a.Fragment,null,Object(g.jsx)(r.EuiFormRow,q()({label:e.startDate.label},l,{fullWidth:!0}),Object(g.jsx)(r.EuiDatePickerRange,{isInvalid:h,startDateControl:Object(g.jsx)(r.EuiDatePicker,{selected:b,onChange:e=>e&&f(e),startDate:b,endDate:O,"aria-label":"Start date",showTimeSelect:n,minDate:u,utcOffset:m}),endDateControl:Object(g.jsx)(r.EuiDatePicker,{selected:O,onChange:e=>e&&x(e),startDate:b,endDate:O,"aria-label":"End date",showTimeSelect:n,minDate:u,utcOffset:p}),fullWidth:!0})),h?Object(g.jsx)(i.a.Fragment,null,Object(g.jsx)(r.EuiSpacer,{size:"xs"}),Object(g.jsx)(r.EuiText,{size:"xs",color:"danger"},j.P)):null)}));V.displayName="DatePickerRangeField";var G,H=n(49);const K=Object(o.getUseField)({component:u.Field}),X=null!==(G=d.map((e=>({label:e}))))&&void 0!==G?G:[{label:"UTC"}],J=i.a.memo((({onCancel:e,onSuccess:t,initialValue:n,maintenanceWindowId:i})=>{const[l]=Object(a.useState)(s()().toISOString()),[u]=Object(a.useState)(s()().add(30,"minutes").toISOString()),[c,d]=Object(a.useState)(!1),{defaultTimezone:b,isBrowser:m}=(()=>{const e=Object(k.b)("dateFormat:tz");var t,n;return e&&"Browser"!==e?{defaultTimezone:e,isBrowser:!1}:{defaultTimezone:null!==(t=null===(n=s.a.tz)||void 0===n?void 0:n.guess())&&void 0!==t?t:"UTC",isBrowser:!0}})(),O=void 0!==n&&void 0!==i,{mutate:p,isLoading:x}=function(){const{http:e,notifications:{toasts:t}}=Object(k.a)().services;return Object(z.useMutation)((t=>async function({http:e,maintenanceWindow:t}){const n=await e.post(`${R.INTERNAL_BASE_ALERTING_API_PATH}/rules/maintenance_window`,{body:JSON.stringify(M(t))});return W(n)}({http:e,maintenanceWindow:t})),{onSuccess:e=>{t.addSuccess(_.i18n.translate("xpack.alerting.maintenanceWindowsCreateSuccess",{defaultMessage:"Created maintenance window '{title}'",values:{title:e.title}}))},onError:()=>{t.addDanger(_.i18n.translate("xpack.alerting.maintenanceWindowsCreateFailure",{defaultMessage:"Failed to create maintenance window."}))}})}(),{mutate:h,isLoading:E}=function(){const{http:e,notifications:{toasts:t}}=Object(k.a)().services;return Object(z.useMutation)((({maintenanceWindowId:t,maintenanceWindow:n})=>async function({http:e,maintenanceWindowId:t,maintenanceWindow:n}){const a=await e.post(`${R.INTERNAL_BASE_ALERTING_API_PATH}/rules/maintenance_window/${encodeURIComponent(t)}`,{body:JSON.stringify(N(n))});return Y(a)}({http:e,maintenanceWindowId:t,maintenanceWindow:n})),{onSuccess:e=>{t.addSuccess(_.i18n.translate("xpack.alerting.maintenanceWindowsUpdateSuccess",{defaultMessage:"Updated maintenance window '{title}'",values:{title:e.title}}))},onError:()=>{t.addDanger(_.i18n.translate("xpack.alerting.maintenanceWindowsUpdateFailure",{defaultMessage:"Failed to update maintenance window."}))}})}(),{mutate:S}=Object(H.a)(),y=Object(a.useCallback)((async(e,n)=>{if(n){const n=s()(e.startDate),a=s()(e.endDate),l={title:e.title,duration:a.diff(n),rRule:C(n,e.timezone?e.timezone[0]:b,e.recurringSchedule)};O?h({maintenanceWindowId:i,maintenanceWindow:l},{onSuccess:t}):p(l,{onSuccess:t})}}),[O,i,h,p,t,b]),{form:F}=Object(o.useForm)({defaultValue:n,options:{stripEmptyFields:!1},schema:f,onSubmit:y}),[{recurring:v,timezone:w}]=Object(o.useFormData)({form:F,watch:["recurring","timezone"]}),D=v||!1,I=m||void 0!==(null==n?void 0:n.timezone),L=Object(a.useCallback)((()=>d(!1)),[]),A=Object(a.useCallback)((()=>d(!0)),[]),q=Object(a.useMemo)((()=>{let e;return c&&(e=Object(g.jsx)(r.EuiConfirmModal,{title:j.d,onCancel:L,onConfirm:()=>{L(),S({maintenanceWindowId:i,archive:!0},{onSuccess:t})},cancelButtonText:j.e,confirmButtonText:j.d,defaultFocusedButton:"confirm",buttonColor:"danger"},Object(g.jsx)("p",null,j.b))),e}),[L,S,c,i,t]);return Object(g.jsx)(o.Form,{form:F},Object(g.jsx)(r.EuiFlexGroup,{direction:"column",responsive:!1},Object(g.jsx)(r.EuiFlexItem,null,Object(g.jsx)(K,{path:"title",componentProps:{"data-test-subj":"title-field",euiFieldProps:{autoFocus:!0}}})),Object(g.jsx)(r.EuiFlexItem,null,Object(g.jsx)(r.EuiFlexGroup,{alignItems:"flexEnd",responsive:!1},Object(g.jsx)(r.EuiFlexItem,{grow:3},Object(g.jsx)(o.UseMultiFields,{fields:{startDate:{path:"startDate",config:{label:j.O,defaultValue:l,validations:[]}},endDate:{path:"endDate",config:{label:"",defaultValue:u,validations:[]}}}},(e=>Object(g.jsx)(V,{fields:e,timezone:null!=w?w:[b],"data-test-subj":"date-field"})))),I?Object(g.jsx)(r.EuiFlexItem,{grow:1},Object(g.jsx)(K,{path:"timezone",config:{type:o.FIELD_TYPES.COMBO_BOX,validations:[],defaultValue:[b]},componentProps:{"data-test-subj":"timezone-field",id:"timezone",euiFieldProps:{fullWidth:!0,options:X,singleSelection:{asPlainText:!0},isClearable:!1,noSuggestions:!1,placeholder:"",prepend:Object(g.jsx)(r.EuiFormLabel,{htmlFor:"timezone"},j.Q)}}})):null)),Object(g.jsx)(r.EuiFlexItem,null,Object(g.jsx)(K,{path:"recurring",componentProps:{"data-test-subj":"recurring-field"}})),Object(g.jsx)(r.EuiFlexItem,null,D?Object(g.jsx)(T,{"data-test-subj":"recurring-form"}):null)),O?Object(g.jsx)(r.EuiCallOut,{title:j.d,color:"danger",iconType:"trash"},Object(g.jsx)("p",null,j.c),Object(g.jsx)(r.EuiButton,{fill:!0,color:"danger",onClick:A},j.a),q):null,Object(g.jsx)(r.EuiHorizontalRule,{margin:"xl"}),Object(g.jsx)(r.EuiFlexGroup,{alignItems:"center",justifyContent:"flexEnd",gutterSize:"l",responsive:!1},Object(g.jsx)(r.EuiFlexItem,{grow:!1},Object(g.jsx)(r.EuiButtonEmpty,{onClick:e,size:"s","data-test-subj":"cancelMaintenanceWindow"},j.e)),Object(g.jsx)(r.EuiFlexItem,{grow:!1},Object(g.jsx)(P,{isLoading:x||E,editMode:O}))))}));J.displayName="CreateMaintenanceWindowForm"}}]);