/*! 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([[4],{42:function(e,t,n){"use strict";n.d(t,"a",(function(){return u}));var a=n(17),i=n.n(a),s=n(35),c=n(5),o=n(34),l=n(38);const u=e=>{const t=e.rRule.dtstart,n=i()(t).add(e.duration),a=Object(c.has)(e,"rRule.interval"),u={title:e.title,startDate:t,endDate:n.toISOString(),timezone:[e.rRule.tzid],recurring:a};if(!a)return u;const b=e.rRule,d=r(b),j=b.freq,m=b.until?o.d.ON_DATE:b.count?o.d.AFTER_X:o.d.NEVER,p={frequency:d?"CUSTOM":j,interval:b.interval,ends:m};return d&&(p.customFrequency=j),b.until&&(p.until=b.until),b.count&&(p.count=b.count),j!==s.a.MONTHLY&&b.byweekday&&(p.byweekday=Object(l.a)(b.byweekday,i()(t))),j===s.a.MONTHLY&&(b.byweekday?p.bymonth="weekday":b.bymonthday&&(p.bymonth="day")),u.recurringSchedule=p,u},r=e=>{const t=e.freq;return!(!(e.interval&&e.interval>1)&&(!t||t!==s.a.DAILY||e.byweekday)&&!(t&&t===s.a.WEEKLY&&e.byweekday&&e.byweekday.length>1)&&(!t||t!==s.a.MONTHLY||!e.bymonthday))}},43:function(e,t,n){"use strict";n.d(t,"a",(function(){return s})),n(14);var a=n(16),i=n(15);const s=({size:e})=>Object(i.jsx)(a.EuiFlexGroup,{"data-test-subj":"center-justified-spinner",justifyContent:"center"},Object(i.jsx)(a.EuiFlexItem,{grow:!1},Object(i.jsx)(a.EuiLoadingSpinner,{size:e||"xl"})))},59:function(e,t,n){"use strict";n.r(t),n.d(t,"MaintenanceWindowsPage",(function(){return U})),n.d(t,"default",(function(){return U}));var a=n(14),i=n.n(a),s=n(16),c=n(33),o=n(39),l=n(32),u=n(15);const r=Object(u.jsx)("h2",null,l.cb),b=Object(u.jsx)("p",null,l.ab),d=i.a.memo((({onClickCreate:e,showCreateButton:t=!0,docLinks:n})=>{const i=Object(a.useMemo)((()=>t?[Object(u.jsx)(s.EuiButton,{key:"create-action",fill:!0,onClick:e},l.Z),Object(u.jsx)(s.EuiButtonEmpty,{key:"documentation-button",target:"_blank",href:n.alerting.maintenanceWindows,iconType:"help"},l.bb)]:null),[t,e,n]);return Object(u.jsx)(s.EuiPageTemplate.EmptyPrompt,{"data-test-subj":"mw-empty-prompt",title:r,body:b,actions:i})}));d.displayName="EmptyPrompt";var j=n(36),m=n(35);let p;m.a.YEARLY,m.a.MONTHLY,m.a.WEEKLY,m.a.DAILY,function(e){e.asc="asc",e.desc="desc"}(p||(p={}));var O=n(34),x=n(17),E=n.n(x),g=n(5),h=n(2),v=n(47),y=n(41),w=n(42);const f=i.a.memo((({maintenanceWindowFindResponse:e})=>{const[t,n]=Object(a.useState)(!1),i=Object(a.useCallback)((()=>{n((e=>!e))}),[]),c=Object(a.useCallback)((()=>{n(!1)}),[]),{startDate:o,recurringSchedule:r,topEvents:b,presets:d}=Object(a.useMemo)((()=>{const t=Object(w.a)(e),n=E()(t.startDate),a=Object(g.findIndex)(e.events,(t=>t.gte===e.eventStartTime&&t.lte===e.eventEndTime));return{startDate:n,recurringSchedule:t.recurringSchedule,topEvents:e.events.slice(a+1,a+4),presets:Object(y.a)(n)}}),[e]);return Object(u.jsx)(s.EuiPopover,{button:Object(u.jsx)(s.EuiButtonIcon,{"data-test-subj":"upcoming-events-icon-button",color:"text",display:"base",iconType:"calendar",size:"s","aria-label":"Upcoming events",onClick:i}),isOpen:t,closePopover:c,anchorPosition:"downCenter"},Object(u.jsx)(s.EuiPopoverTitle,{"data-test-subj":"upcoming-events-popover-title"},l.M(Object(v.a)(o,r,d))),Object(u.jsx)(s.EuiFlexGroup,{direction:"column",responsive:!1,gutterSize:"none"},Object(u.jsx)(s.EuiFlexItem,{grow:!1},Object(u.jsx)(s.EuiText,{style:{fontWeight:700},color:"subdued",size:"s"},l.Bb),Object(u.jsx)(s.EuiSpacer,{size:"m"})),b.map(((e,t)=>Object(u.jsx)(s.EuiFlexItem,{"data-test-subj":"upcoming-events-popover-item",key:`startDate.${t}`,grow:!1},Object(u.jsx)(s.EuiFlexGroup,{responsive:!1,alignItems:"center",justifyContent:"flexStart",style:{width:"300px"}},Object(u.jsx)(s.EuiFlexItem,{grow:!1},Object(u.jsx)(s.EuiIcon,{color:"subdued",type:"calendar"})),Object(u.jsx)(s.EuiFlexItem,{grow:!1},Object(u.jsx)(s.EuiText,{color:"subdued",size:"s"},Object(s.formatDate)(e.gte,h.MAINTENANCE_WINDOW_DATE_FORMAT)))),t{const[n,c]=Object(a.useState)([]),[o,r]=Object(a.useState)(!1),b=Object(a.useCallback)((a=>()=>{const i=n.includes(a)?n.filter((e=>e!==a)):[...n,a];c(i);let s=e.removeSimpleFieldClauses("status").removeOrFieldClauses("status");i.length>0&&(s=i.reduce(((e,t)=>e.addOrFieldValue("status",t,!0,"eq")),s)),null==t||t(s)}),[e,t,n]),d=Object(a.useCallback)((()=>{r((e=>!e))}),[r]),j=Object(a.useCallback)((()=>{r(!1)}),[r]);return Object(u.jsx)(s.EuiFilterGroup,null,Object(u.jsx)(s.EuiPopover,{isOpen:o,closePopover:j,button:Object(u.jsx)(s.EuiFilterButton,{"data-test-subj":"status-filter-button",iconType:"arrowDown",hasActiveFilters:n.length>0,numActiveFilters:n.length,numFilters:n.length,onClick:d},l.ub)},Object(u.jsx)(i.a.Fragment,null,O.i.map((e=>Object(u.jsx)(s.EuiFilterSelectItem,{key:e.value,"data-test-subj":`status-filter-${e.value}`,onClick:b(e.value),checked:n.includes(e.value)?"on":void 0},e.name))))))}));C.displayName="StatusFilter";var T=n(37),k=n.n(T);const I=i.a.memo((({id:e,status:t,onEdit:n,onCancel:c,onArchive:o,onCancelAndArchive:r})=>{const[b,d]=Object(a.useState)(!1),[j,m]=Object(a.useState)(!1),[p,O]=Object(a.useState)(),x=Object(a.useCallback)((()=>{d((e=>!e))}),[]),E=Object(a.useCallback)((()=>{d(!1)}),[]),g=Object(a.useCallback)((()=>m(!1)),[]),h=Object(a.useCallback)((e=>{O(e),m(!0)}),[]),v=Object(a.useMemo)((()=>{const t={cancel:{props:{title:l.j,onConfirm:()=>{g(),c(e)},cancelButtonText:l.h,confirmButtonText:l.j},subtitle:l.i},cancelAndArchive:{props:{title:l.g,onConfirm:()=>{g(),r(e)},cancelButtonText:l.h,confirmButtonText:l.g},subtitle:l.f},archive:{props:{title:l.d,onConfirm:()=>{g(),o(e,!0)},cancelButtonText:l.e,confirmButtonText:l.d},subtitle:l.c},unarchive:{props:{title:l.Ab,onConfirm:()=>{g(),o(e,!1)},cancelButtonText:l.e,confirmButtonText:l.Ab},subtitle:l.zb}};let n;if(j&&p){const e=t[p];n=Object(u.jsx)(s.EuiConfirmModal,k()({},e.props,{style:{width:600},onCancel:g,defaultFocusedButton:"confirm",buttonColor:"danger"}),Object(u.jsx)("p",null,e.subtitle))}return n}),[e,p,j,g,o,c,r]),y=Object(a.useMemo)((()=>{const a={edit:Object(u.jsx)(s.EuiContextMenuItem,{"data-test-subj":"table-actions-edit",key:"edit",icon:"pencil",onClick:()=>{E(),n(e)}},l.qb),cancel:Object(u.jsx)(s.EuiContextMenuItem,{"data-test-subj":"table-actions-cancel",key:"cancel",icon:"stopSlash",onClick:()=>{E(),h("cancel")}},l.ob),cancelAndArchive:Object(u.jsx)(s.EuiContextMenuItem,{"data-test-subj":"table-actions-cancel-and-archive",key:"cancel-and-archive",icon:"trash",onClick:()=>{E(),h("cancelAndArchive")}},l.pb),archive:Object(u.jsx)(s.EuiContextMenuItem,{"data-test-subj":"table-actions-archive",key:"archive",icon:"trash",onClick:()=>{E(),h("archive")}},l.a),unarchive:Object(u.jsx)(s.EuiContextMenuItem,{"data-test-subj":"table-actions-unarchive",key:"unarchive",icon:"exit",onClick:()=>{E(),h("unarchive")}},l.rb)};return{running:["edit","cancel","cancelAndArchive"],upcoming:["edit","archive"],finished:["edit","archive"],archived:["unarchive"]}[t].map((e=>a[e]))}),[e,t,n,E,h]),w=Object(a.useMemo)((()=>Object(u.jsx)(s.EuiButtonIcon,{"data-test-subj":"table-actions-icon-button",iconType:"boxesHorizontal",size:"s","aria-label":"Upcoming events",onClick:x})),[x]);return Object(u.jsx)(i.a.Fragment,null,Object(u.jsx)(s.EuiFlexGroup,{justifyContent:"flexEnd",alignItems:"center"},Object(u.jsx)(s.EuiFlexItem,{grow:!1},Object(u.jsx)(s.EuiPopover,{button:w,isOpen:b,closePopover:E,panelPaddingSize:"none",anchorPosition:"downCenter","data-test-subj":"table-actions-popover"},Object(u.jsx)(s.EuiContextMenuPanel,{items:y})))),v)}));I.displayName="TableActionsPopover";var A=n(1),F=n(18);const _=({r_rule:e,...t})=>({...t,rRule:e});async function M({http:e,maintenanceWindowId:t}){const n=await e.post(`${h.INTERNAL_BASE_ALERTING_API_PATH}/rules/maintenance_window/${encodeURIComponent(t)}/_finish`);return _(n)}var N=n(49),S=n(50);const W=[{field:"title",name:l.ib,truncateText:!0},{field:"status",name:l.ub,"data-test-subj":"maintenance-windows-column-status",render:e=>Object(u.jsx)(s.EuiBadge,{color:O.h[e].color},O.h[e].label),sortable:({status:e})=>O.j[e]},{field:"eventStartTime",name:l.tb,dataType:"date",render:(e,t)=>Object(u.jsx)(s.EuiFlexGroup,{responsive:!1,alignItems:"center"},Object(u.jsx)(s.EuiFlexItem,{grow:!1},Object(s.formatDate)(e,h.MAINTENANCE_WINDOW_DATE_FORMAT)),t.events.length>1?Object(u.jsx)(s.EuiFlexItem,{grow:!1},Object(u.jsx)(f,{maintenanceWindowFindResponse:t})):null),sortable:!0},{field:"eventEndTime",name:l.sb,dataType:"date",render:e=>Object(s.formatDate)(e,h.MAINTENANCE_WINDOW_DATE_FORMAT)}],D={sort:{field:"status",direction:p.asc}},P=e=>({className:e.status,"data-test-subj":"list-item"}),L=i.a.memo((({loading:e,items:t,readOnly:n,refreshData:i})=>{const o={filters:[{type:"custom_component",component:C}],toolsRight:Object(u.jsx)(s.EuiButton,{"data-test-subj":"refresh-button",iconType:"refresh",onClick:i},l.lb)},{euiTheme:r}=Object(s.useEuiTheme)(),{navigateToEditMaintenanceWindows:b}=Object(j.b)(),d=Object(a.useCallback)((e=>b(e)),[b]),{mutate:m,isLoading:p}=function(){const{http:e,notifications:{toasts:t}}=Object(c.a)().services;return Object(F.useMutation)((t=>M({http:e,maintenanceWindowId:t})),{onSuccess:e=>{t.addSuccess(A.i18n.translate("xpack.alerting.maintenanceWindowsFinishedSuccess",{defaultMessage:"Cancelled running maintenance window '{title}'",values:{title:e.title}}))},onError:()=>{t.addDanger(A.i18n.translate("xpack.alerting.maintenanceWindowsFinishedFailure",{defaultMessage:"Failed to cancel maintenance window."}))}})}(),O=Object(a.useCallback)((e=>m(e,{onSuccess:()=>i()})),[m,i]),{mutate:x,isLoading:E}=Object(N.a)(),g=Object(a.useCallback)(((e,t)=>x({maintenanceWindowId:e,archive:t},{onSuccess:()=>i()})),[x,i]),{mutate:h,isLoading:v}=function(){const{http:e,notifications:{toasts:t}}=Object(c.a)().services;return Object(F.useMutation)((async t=>(await M({http:e,maintenanceWindowId:t}),Object(S.a)({http:e,maintenanceWindowId:t,archive:!0}))),{onSuccess:e=>{t.addSuccess(A.i18n.translate("xpack.alerting.maintenanceWindowsFinishedAndArchiveSuccess",{defaultMessage:"Cancelled and archived running maintenance window '{title}'",values:{title:e.title}}))},onError:()=>{t.addDanger(A.i18n.translate("xpack.alerting.maintenanceWindowsFinishedAndArchiveFailure",{defaultMessage:"Failed to cancel and archive maintenance window."}))}})}(),y=Object(a.useCallback)((e=>h(e,{onSuccess:()=>i()})),[h,i]),w=Object(a.useMemo)((()=>Object(u.css)(".euiTableRow{&.running{background-color:",r.colors.highlight,";}}","")),[r.colors.highlight]),f=Object(a.useMemo)((()=>[{name:"",render:({status:e,id:t})=>Object(u.jsx)(I,{id:t,status:e,onEdit:d,onCancel:O,onArchive:g,onCancelAndArchive:y})}]),[g,O,y,d]),T=Object(a.useMemo)((()=>n?W:W.concat(f)),[f,n]);return Object(u.jsx)(s.EuiInMemoryTable,{"data-test-subj":"maintenance-windows-table",css:w,itemId:"id",loading:e||p||E||v,tableCaption:"Maintenance Windows List",items:t,columns:T,pagination:!0,sorting:D,rowProps:P,search:o,hasActions:!0})}));L.displayName="MaintenanceWindowsList";const B=({expiration_date:e,r_rule:t,event_start_time:n,event_end_time:a,created_by:i,updated_by:s,created_at:c,updated_at:o,...l})=>({...l,expirationDate:e,rRule:t,eventStartTime:n,eventEndTime:a,createdBy:i,updatedBy:s,createdAt:c,updatedAt:o}),R=e=>{const{enabled:t=!0}=e||{},{http:n,notifications:{toasts:a}}=Object(c.a)().services,{isLoading:i,isFetching:s,data:o=[],refetch:l}=Object(F.useQuery)({queryKey:["findMaintenanceWindows"],queryFn:()=>async function({http:e}){const t=await e.get(`${h.INTERNAL_BASE_ALERTING_API_PATH}/rules/maintenance_window/_find`);return t.data.map((e=>B(e)))}({http:n}),onError:e=>{e&&a.addDanger(A.i18n.translate("xpack.alerting.maintenanceWindowsListFailure",{defaultMessage:"Unable to load maintenance windows."}))},refetchOnWindowFocus:!1,retry:!1,cacheTime:0,enabled:t});return{maintenanceWindows:o,isLoading:t&&(i||s),refetch:l}};var z=n(43),G=n(44),H=n(45);const Y=Object(u.jsx)("h2",{"data-test-subj":"license-prompt-title"},l.Db),q=i.a.memo((()=>{const{application:e}=Object(c.a)().services;return Object(u.jsx)(s.EuiPageTemplate.EmptyPrompt,{"data-test-subj":"mw-license-prompt",title:Y,body:Object(u.jsx)(s.EuiFlexGroup,{direction:"column"},Object(u.jsx)(s.EuiFlexItem,null,Object(u.jsx)(s.EuiText,{color:"subdued"},Object(u.jsx)("p",null,l.Eb))),Object(u.jsx)(s.EuiFlexItem,null,Object(u.jsx)(s.EuiFlexGroup,{justifyContent:"center"},Object(u.jsx)(s.EuiFlexItem,{grow:!1},Object(u.jsx)(s.EuiButtonEmpty,{"data-test-subj":"license-prompt-upgrade",key:"upgrade-subscription-button",target:"_blank",href:"https://www.elastic.co/subscriptions"},l.Cb)),Object(u.jsx)(s.EuiFlexItem,{grow:!1},Object(u.jsx)(s.EuiButton,{fill:!0,"data-test-subj":"license-prompt-trial",key:"start-trial-button",target:"_blank",href:e.getUrlForApp("management",{path:"stack/license_management/home"})},l.nb)))))})}));q.displayName="LicensePrompt";const U=i.a.memo((()=>{const{application:{capabilities:e},chrome:t,docLinks:n}=Object(c.a)().services,{isAtLeastPlatinum:r}=Object(H.a)(),b=r(),{navigateToCreateMaintenanceWindow:m}=Object(j.a)(),{isLoading:p,maintenanceWindows:O,refetch:x}=R({enabled:b});Object(o.a)(h.MAINTENANCE_WINDOW_DEEP_LINK_IDS.maintenanceWindows);const E=Object(a.useCallback)((()=>{m()}),[m]),g=Object(a.useCallback)((()=>x()),[x]),v=e[h.MAINTENANCE_WINDOW_FEATURE_ID].show,y=e[h.MAINTENANCE_WINDOW_FEATURE_ID].save,w=!p&&0===O.length&&v&&y,f=v&&!y,C=Object(a.useCallback)((()=>{f&&t.setBadge({text:l.jb,tooltip:l.kb,iconType:"glasses"})}),[t,f]);return Object(a.useEffect)((()=>(C(),()=>{t.setBadge()})),[C,t]),p?Object(u.jsx)(z.a,null):Object(u.jsx)(i.a.Fragment,null,Object(u.jsx)(s.EuiPageHeader,{bottomBorder:!0,alignItems:"top"},Object(u.jsx)(s.EuiPageHeaderSection,null,Object(u.jsx)(s.EuiFlexGroup,{alignItems:"baseline",gutterSize:"m",responsive:!1},Object(u.jsx)(s.EuiFlexItem,{grow:!1},Object(u.jsx)(s.EuiTitle,{size:"l"},Object(u.jsx)("h1",null,l.fb))),Object(u.jsx)(s.EuiFlexItem,{grow:!1},Object(u.jsx)(G.a,null))),Object(u.jsx)(s.EuiSpacer,null),Object(u.jsx)(s.EuiText,{size:"m"},Object(u.jsx)("p",null,l.gb))),!w&&b&&y?Object(u.jsx)(s.EuiPageHeaderSection,null,Object(u.jsx)(s.EuiButton,{"data-test-subj":"mw-create-button",onClick:E,iconType:"plusInCircle",fill:!0},l.X)):null),b?w?Object(u.jsx)(d,{onClickCreate:E,docLinks:n.links}):Object(u.jsx)(i.a.Fragment,null,Object(u.jsx)(s.EuiSpacer,{size:"xl"}),Object(u.jsx)(L,{readOnly:f,refreshData:g,loading:p,items:O})):Object(u.jsx)(q,null))}));U.displayName="MaintenanceWindowsPage"}}]);