/*! 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.spaces_bundle_jsonpfunction=window.spaces_bundle_jsonpfunction||[]).push([[2],{108:function(e,t,s){switch(window.__kbnThemeTag__){case"v8dark":return s(109);case"v8light":return s(111)}},109:function(e,t,s){var o=s(42),a=s(110);"string"==typeof(a=a.__esModule?a.default:a)&&(a=[[e.i,a,""]]);o(a,{insert:"head",singleton:!1}),e.exports=a.locals||{}},110:function(e,t,s){(t=s(43)(!1)).push([e.i,".spcCopyToSpace__spacesList{margin-top:4px}",""]),e.exports=t},111:function(e,t,s){var o=s(42),a=s(112);"string"==typeof(a=a.__esModule?a.default:a)&&(a=[[e.i,a,""]]);o(a,{insert:"head",singleton:!1}),e.exports=a.locals||{}},112:function(e,t,s){(t=s(43)(!1)).push([e.i,".spcCopyToSpace__spacesList{margin-top:4px}",""]),e.exports=t},113:function(e,t,s){switch(window.__kbnThemeTag__){case"v8dark":return s(114);case"v8light":return s(116)}},114:function(e,t,s){var o=s(42),a=s(115);"string"==typeof(a=a.__esModule?a.default:a)&&(a=[[e.i,a,""]]);o(a,{insert:"head",singleton:!1}),e.exports=a.locals||{}},115:function(e,t,s){(t=s(43)(!1)).push([e.i,".spcCopyToSpaceResult{border-bottom:1px solid #343741;padding-bottom:8px}",""]),e.exports=t},116:function(e,t,s){var o=s(42),a=s(117);"string"==typeof(a=a.__esModule?a.default:a)&&(a=[[e.i,a,""]]);o(a,{insert:"head",singleton:!1}),e.exports=a.locals||{}},117:function(e,t,s){(t=s(43)(!1)).push([e.i,".spcCopyToSpaceResult{border-bottom:1px solid #d3dae6;padding-bottom:8px}",""]),e.exports=t},118:function(e,t,s){switch(window.__kbnThemeTag__){case"v8dark":return s(119);case"v8light":return s(121)}},119:function(e,t,s){var o=s(42),a=s(120);"string"==typeof(a=a.__esModule?a.default:a)&&(a=[[e.i,a,""]]);o(a,{insert:"head",singleton:!1}),e.exports=a.locals||{}},120:function(e,t,s){(t=s(43)(!1)).push([e.i,".spcCopyToSpace__missingReferencesIcon,.spcCopyToSpace__summaryCountBadge{margin-left:4px}",""]),e.exports=t},121:function(e,t,s){var o=s(42),a=s(122);"string"==typeof(a=a.__esModule?a.default:a)&&(a=[[e.i,a,""]]);o(a,{insert:"head",singleton:!1}),e.exports=a.locals||{}},122:function(e,t,s){(t=s(43)(!1)).push([e.i,".spcCopyToSpace__missingReferencesIcon,.spcCopyToSpace__summaryCountBadge{margin-left:4px}",""]),e.exports=t},123:function(e,t,s){switch(window.__kbnThemeTag__){case"v8dark":return s(124);case"v8light":return s(126)}},124:function(e,t,s){var o=s(42),a=s(125);"string"==typeof(a=a.__esModule?a.default:a)&&(a=[[e.i,a,""]]);o(a,{insert:"head",singleton:!1}),e.exports=a.locals||{}},125:function(e,t,s){(t=s(43)(!1)).push([e.i,".spcCopyToSpace__resolveAllConflictsLink{font-size:14px;margin-right:8px}",""]),e.exports=t},126:function(e,t,s){var o=s(42),a=s(127);"string"==typeof(a=a.__esModule?a.default:a)&&(a=[[e.i,a,""]]);o(a,{insert:"head",singleton:!1}),e.exports=a.locals||{}},127:function(e,t,s){(t=s(43)(!1)).push([e.i,".spcCopyToSpace__resolveAllConflictsLink{font-size:14px;margin-right:8px}",""]),e.exports=t},128:function(e,t,s){switch(window.__kbnThemeTag__){case"v8dark":return s(129);case"v8light":return s(131)}},129:function(e,t,s){var o=s(42),a=s(130);"string"==typeof(a=a.__esModule?a.default:a)&&(a=[[e.i,a,""]]);o(a,{insert:"head",singleton:!1}),e.exports=a.locals||{}},130:function(e,t,s){(t=s(43)(!1)).push([e.i,".spcCopyToSpaceResultDetails{margin-top:8px;padding-left:24px}.spcCopyToSpaceResultDetails__row{margin-bottom:4px}.spcCopyToSpaceResultDetails__savedObjectName{min-width:0}.spcCopyToSpaceResultDetails__selectControl{margin-left:24px}.spcCopyToSpaceResultDetails__selectControl__childWrapper{height:0;opacity:0;overflow:hidden;transform:translatez(0);transition:height .25s cubic-bezier(.694,.0482,.335,1),opacity .25s cubic-bezier(.694,.0482,.335,1);visibility:hidden}.spcCopyToSpaceResultDetails__selectControl.spcCopyToSpaceResultDetails__selectControl-isOpen .spcCopyToSpaceResultDetails__selectControl__childWrapper{height:auto;opacity:1;visibility:visible}",""]),e.exports=t},131:function(e,t,s){var o=s(42),a=s(132);"string"==typeof(a=a.__esModule?a.default:a)&&(a=[[e.i,a,""]]);o(a,{insert:"head",singleton:!1}),e.exports=a.locals||{}},132:function(e,t,s){(t=s(43)(!1)).push([e.i,".spcCopyToSpaceResultDetails{margin-top:8px;padding-left:24px}.spcCopyToSpaceResultDetails__row{margin-bottom:4px}.spcCopyToSpaceResultDetails__savedObjectName{min-width:0}.spcCopyToSpaceResultDetails__selectControl{margin-left:24px}.spcCopyToSpaceResultDetails__selectControl__childWrapper{height:0;opacity:0;overflow:hidden;transform:translatez(0);transition:height .25s cubic-bezier(.694,.0482,.335,1),opacity .25s cubic-bezier(.694,.0482,.335,1);visibility:hidden}.spcCopyToSpaceResultDetails__selectControl.spcCopyToSpaceResultDetails__selectControl-isOpen .spcCopyToSpaceResultDetails__selectControl__childWrapper{height:auto;opacity:1;visibility:visible}",""]),e.exports=t},155:function(e,t,s){"use strict";s.r(t),s.d(t,"CopyToSpaceFlyoutInternal",(function(){return q}));var o=s(5),a=s(15),c=s(1),n=s.n(c),i=s(2),r=s(37),l=s(0);const p=({error:{type:e}})=>["conflict","ambiguous_conflict","missing_references"].includes(e),u=e=>!p(e),d=e=>{const{copyInProgress:t,conflictResolutionInProgress:s,initialCopyFinished:a,copyResult:n,retries:d}=e;let j={successCount:0,pendingCount:0,skippedCount:0,errorCount:0};n&&(j=Object.entries(n).reduce(((e,t)=>{const[s,o]=t;let a=0,c=0,n=0,i=0;if(!0===o.success)a=o.successfulImports.length;else{const e=o.failedImports.filter(p).reduce(((e,{obj:{type:t,id:s}})=>e.add(`${t}:${s}`)),new Set);c=(d[s]||[]).length,n=e.size+o.successfulImports.length-c,i=o.failedImports.filter(u).length}return{loading:!1,successCount:e.successCount+a,pendingCount:e.pendingCount+c,skippedCount:e.skippedCount+n,errorCount:e.errorCount+i}}),j));const b=()=>{let c;if(a){const t=j.pendingCount>0?Object(l.jsx)(r.FormattedMessage,{id:"xpack.spaces.management.copyToSpace.finishPendingOverwritesCopyToSpacesButton",defaultMessage:"Copy {overwriteCount} objects",values:{overwriteCount:j.pendingCount}}):Object(l.jsx)(r.FormattedMessage,{id:"xpack.spaces.management.copyToSpace.finishCopyToSpacesButton",defaultMessage:"Finish"});c=Object(l.jsx)(o.EuiButton,{fill:!0,isLoading:s,"aria-live":"assertive","aria-label":s?i.i18n.translate("xpack.spaces.management.copyToSpace.inProgressButtonLabel",{defaultMessage:"Copy is in progress. Please wait."}):i.i18n.translate("xpack.spaces.management.copyToSpace.finishedButtonLabel",{defaultMessage:"Copy finished."}),onClick:()=>e.onCopyFinish(),"data-test-subj":"cts-finish-button"},t)}else c=Object(l.jsx)(o.EuiButton,{fill:!0,isLoading:t,onClick:()=>e.onCopyStart(),"data-test-subj":"cts-initiate-button",disabled:0===e.numberOfSelectedSpaces||t},e.numberOfSelectedSpaces>0?Object(l.jsx)(r.FormattedMessage,{id:"xpack.spaces.management.copyToSpace.copyToSpacesButton",defaultMessage:"Copy to {spaceCount} {spaceCount, plural, one {space} other {spaces}}",values:{spaceCount:e.numberOfSelectedSpaces}}):Object(l.jsx)(r.FormattedMessage,{id:"xpack.spaces.management.copyToSpace.disabledCopyToSpacesButton",defaultMessage:"Copy"}));return Object(l.jsx)(o.EuiFlexGroup,{justifyContent:"spaceBetween"},Object(l.jsx)(o.EuiFlexItem,{grow:!1},Object(l.jsx)(o.EuiButtonEmpty,{onClick:()=>e.onClose(),"data-test-subj":"cts-cancel-button",disabled:t&&!a||s||j.successCount>0},Object(l.jsx)(r.FormattedMessage,{id:"xpack.spaces.management.copyToSpace.cancelButton",defaultMessage:"Cancel"}))),Object(l.jsx)(o.EuiFlexItem,{grow:!1},c))};return t?Object(l.jsx)(c.Fragment,null,Object(l.jsx)(o.EuiFlexGroup,null,Object(l.jsx)(o.EuiFlexItem,null,Object(l.jsx)(o.EuiStat,{"data-test-subj":"cts-summary-success-count",title:j.successCount,titleSize:"s",titleColor:a?"success":"subdued",isLoading:!a,textAlign:"center",description:Object(l.jsx)(r.FormattedMessage,{id:"xpack.spaces.management.copyToSpaceFlyoutFooter.successCount",defaultMessage:"Copied"})})),Object(l.jsx)(o.EuiFlexItem,null,Object(l.jsx)(o.EuiStat,{"data-test-subj":"cts-summary-pending-count",title:j.pendingCount,titleSize:"s",titleColor:j.pendingCount>0?"primary":"subdued",isLoading:!a,textAlign:"center",description:Object(l.jsx)(r.FormattedMessage,{id:"xpack.spaces.management.copyToSpaceFlyoutFooter.pendingCount",defaultMessage:"Pending"})})),Object(l.jsx)(o.EuiFlexItem,null,Object(l.jsx)(o.EuiStat,{"data-test-subj":"cts-summary-skipped-count",title:j.skippedCount,titleSize:"s",titleColor:j.skippedCount>0?"primary":"subdued",isLoading:!a,textAlign:"center",description:Object(l.jsx)(r.FormattedMessage,{id:"xpack.spaces.management.copyToSpaceFlyoutFooter.skippedCount",defaultMessage:"Skipped"})})),Object(l.jsx)(o.EuiFlexItem,null,Object(l.jsx)(o.EuiStat,{"data-test-subj":"cts-summary-error-count",title:j.errorCount,titleSize:"s",titleColor:j.errorCount>0?"danger":"subdued",isLoading:!a,textAlign:"center",description:Object(l.jsx)(r.FormattedMessage,{id:"xpack.spaces.management.copyToSpaceFlyoutFooter.errorCount",defaultMessage:"Errors"})}))),Object(l.jsx)(o.EuiHorizontalRule,null),b()):b()},j={id:"createNewCopiesDisabled",text:i.i18n.translate("xpack.spaces.management.copyToSpace.copyModeControl.createNewCopies.disabledTitle",{defaultMessage:"Check for existing objects"}),tooltip:i.i18n.translate("xpack.spaces.management.copyToSpace.copyModeControl.createNewCopies.disabledText",{defaultMessage:"Check if objects were previously copied or imported into the space."})},b={id:"createNewCopiesEnabled",text:i.i18n.translate("xpack.spaces.management.copyToSpace.copyModeControl.createNewCopies.enabledTitle",{defaultMessage:"Create new objects with random IDs"}),tooltip:i.i18n.translate("xpack.spaces.management.copyToSpace.copyModeControl.createNewCopies.enabledText",{defaultMessage:"Use this option to create one or more copies of the object in the same space."})},g={id:"overwriteEnabled",label:i.i18n.translate("xpack.spaces.management.copyToSpace.copyModeControl.overwrite.enabledLabel",{defaultMessage:"Automatically overwrite conflicts"})},m={id:"overwriteDisabled",label:i.i18n.translate("xpack.spaces.management.copyToSpace.copyModeControl.overwrite.disabledLabel",{defaultMessage:"Request action on conflict"})},f={id:"includeRelated",text:i.i18n.translate("xpack.spaces.management.copyToSpace.copyModeControl.includeRelated.title",{defaultMessage:"Include related objects"}),tooltip:i.i18n.translate("xpack.spaces.management.copyToSpace.copyModeControl.includeRelated.text",{defaultMessage:"Copy this object and its related objects. For dashboards, related visualizations, index patterns, and saved searches are also copied."})},x=i.i18n.translate("xpack.spaces.management.copyToSpace.copyModeControl.copyOptionsTitle",{defaultMessage:"Copy options"}),y=i.i18n.translate("xpack.spaces.management.copyToSpace.copyModeControl.relationshipOptionsTitle",{defaultMessage:"Relationship"}),O=({text:e,tooltip:t})=>Object(l.jsx)(o.EuiFlexGroup,null,Object(l.jsx)(o.EuiFlexItem,null,Object(l.jsx)(o.EuiText,null,e)),Object(l.jsx)(o.EuiFlexItem,{grow:!1},Object(l.jsx)(o.EuiIconTip,{content:t,position:"left",type:"iInCircle"}))),h=({initialValues:e,updateSelection:t})=>{const[s,a]=Object(c.useState)(e.createNewCopies),[i,r]=Object(c.useState)(e.overwrite),p=e=>{void 0!==e.createNewCopies?a(e.createNewCopies):void 0!==e.overwrite&&r(e.overwrite),t({createNewCopies:s,overwrite:i,...e})};return Object(l.jsx)(n.a.Fragment,null,Object(l.jsx)(o.EuiFormFieldset,{legend:{children:Object(l.jsx)(o.EuiTitle,{size:"xs"},Object(l.jsx)("span",null,x))}},Object(l.jsx)(o.EuiCheckableCard,{id:b.id,label:O(b),checked:s,onChange:()=>p({createNewCopies:!0})}),Object(l.jsx)(o.EuiSpacer,{size:"s"}),Object(l.jsx)(o.EuiCheckableCard,{id:j.id,label:O(j),checked:!s,onChange:()=>p({createNewCopies:!1})},Object(l.jsx)(o.EuiRadioGroup,{options:[g,m],idSelected:i?g.id:m.id,onChange:e=>p({overwrite:e===g.id}),disabled:s,"data-test-subj":"cts-copyModeControl-overwriteRadioGroup"}))),Object(l.jsx)(o.EuiSpacer,{size:"m"}),Object(l.jsx)(o.EuiFormFieldset,{legend:{children:Object(l.jsx)(o.EuiTitle,{size:"xs"},Object(l.jsx)("span",null,y))}},Object(l.jsx)(o.EuiCheckableCard,{id:f.id,label:O(f),checkableType:"checkbox",checked:!0,onChange:()=>{},disabled:!0})))};s(108);var C=s(17),v=s(9);const S=Object(c.lazy)((()=>Object(v.a)().then((e=>({default:e}))))),w=e=>{if(0===e.spaces.length)return Object(l.jsx)(o.EuiLoadingSpinner,null);const t=Object(l.jsx)(o.EuiIconTip,{content:Object(l.jsx)(r.FormattedMessage,{id:"xpack.spaces.management.copyToSpace.selectSpacesControl.disabledTooltip",defaultMessage:"The object already exists in this space."}),position:"left",type:"iInCircle"}),s=e.spaces.map((s=>{const o=e.disabledSpaceIds.has(s.id);return{label:s.name,prepend:Object(l.jsx)(S,{space:s,size:"s"}),append:o?t:null,checked:e.selectedSpaceIds.includes(s.id)?"on":void 0,disabled:o,"data-space-id":s.id,"data-test-subj":`cts-space-selector-row-${s.id}`}}));return Object(l.jsx)(c.Suspense,{fallback:Object(l.jsx)(o.EuiLoadingSpinner,null)},Object(l.jsx)(o.EuiSelectable,{options:s,onChange:t=>function(t){if(e.disabled)return;const s=t.filter((e=>e.checked)).map((e=>e["data-space-id"]));e.onChange(s)}(t),listProps:{bordered:!0,rowHeight:40,className:"spcCopyToSpace__spacesList","data-test-subj":"cts-form-space-selector"},searchable:s.length>C.SPACE_SEARCH_COUNT_THRESHOLD},((e,t)=>Object(l.jsx)(n.a.Fragment,null,t,e))))},T=e=>{const{savedObjectTarget:t,spaces:s,onUpdate:a,copyOptions:c}=e,n=e=>e?new Set:t.namespaces.reduce(((e,t)=>e.add(t)),new Set);return Object(l.jsx)("div",{"data-test-subj":"copy-to-space-form"},Object(l.jsx)(h,{initialValues:c,updateSelection:e=>(({createNewCopies:e,overwrite:t})=>{const s=n(e),o=c.selectedSpaceIds.filter((e=>!s.has(e)));a({...c,createNewCopies:e,overwrite:t,selectedSpaceIds:o})})(e)}),Object(l.jsx)(o.EuiSpacer,{size:"m"}),Object(l.jsx)(o.EuiFormRow,{label:Object(l.jsx)(o.EuiTitle,{size:"xs"},Object(l.jsx)("span",null,Object(l.jsx)(r.FormattedMessage,{id:"xpack.spaces.management.copyToSpace.selectSpacesLabel",defaultMessage:"Select spaces"}))),fullWidth:!0},Object(l.jsx)(w,{spaces:s,selectedSpaceIds:c.selectedSpaceIds,disabledSpaceIds:n(c.createNewCopies),onChange:e=>{return t=e,a({...c,selectedSpaceIds:t});var t}})))};s(113),s(118);var M=s(4),E=s.n(M);s(123);const _=[{id:"overwrite",text:i.i18n.translate("xpack.spaces.management.copyToSpace.overwriteAllConflictsText",{defaultMessage:"Overwrite all"})},{id:"skip",text:i.i18n.translate("xpack.spaces.management.copyToSpace.skipAllConflictsText",{defaultMessage:"Skip all"})}];class resolve_all_conflicts_ResolveAllConflicts extends c.Component{constructor(...e){super(...e),E()(this,"state",{isPopoverOpen:!1}),E()(this,"onSelect",(e=>{const{summarizedCopyResult:t,retries:s,onRetriesChange:o,onDestinationMapChange:a}=this.props,c="overwrite"===e;if(c){const e=s.filter((e=>!0===e.overwrite)),a=t.objects.reduce(((t,{type:s,id:o,conflict:a})=>{if(a&&!e.some((e=>e.type===s&&e.id===o))){const{error:e}=a,n="conflict"===e.type?e.destinationId:e.destinations[0].id;return[...t,{type:s,id:o,overwrite:c,...n&&{destinationId:n}}]}return t}),new Array);o([...s,...a])}else{const e=t.objects.reduce(((e,{type:t,id:s,conflict:o})=>o?e.add(`${t}:${s}`):e),new Set);o(s.filter((({type:t,id:s})=>!e.has(`${t}:${s}`)))),a(void 0)}this.setState({isPopoverOpen:!1})})),E()(this,"onButtonClick",(()=>{this.setState({isPopoverOpen:!this.state.isPopoverOpen})})),E()(this,"closePopover",(()=>{this.setState({isPopoverOpen:!1})}))}render(){const e=Object(l.jsx)(o.EuiLink,{onClick:this.onButtonClick,className:"spcCopyToSpace__resolveAllConflictsLink"},Object(l.jsx)(r.FormattedMessage,{id:"xpack.spaces.management.copyToSpace.resolveAllConflictsLink",defaultMessage:"(resolve all)"})),t=_.map((e=>Object(l.jsx)(o.EuiContextMenuItem,{"data-test-subj":`cts-resolve-all-conflicts-${e.id}`,key:e.id,onClick:()=>{this.onSelect(e.id)}},e.text)));return Object(l.jsx)(o.EuiPopover,{id:"resolveAllConflictsVisibilityPopover",button:e,isOpen:this.state.isPopoverOpen,closePopover:this.closePopover,panelPaddingSize:"none",anchorPosition:"downLeft"},Object(l.jsx)(o.EuiContextMenuPanel,{items:t}))}}const k=e=>{const{summarizedCopyResult:t}=e;return Object(l.jsx)(c.Fragment,null,(e=>{const{space:t,summarizedCopyResult:s,conflictResolutionInProgress:a,retries:n,onRetriesChange:i,onDestinationMapChange:p}=e,u=e=>`cts-summary-indicator-${e}-${t.id}`;if(s.processing||a)return Object(l.jsx)(o.EuiLoadingSpinner,{"data-test-subj":u("loading")});const{successful:d,hasUnresolvableErrors:j,hasMissingReferences:b,hasConflicts:g}=s;if(d)return Object(l.jsx)(o.EuiIconTip,{type:"checkInCircleFilled",color:"success",iconProps:{"data-test-subj":u("success")},content:Object(l.jsx)(r.FormattedMessage,{id:"xpack.spaces.management.copyToSpace.copyStatusSummary.successMessage",defaultMessage:"Copy to the {space} space was successful.",values:{space:t.name}})});if(j)return Object(l.jsx)(o.EuiIconTip,{type:"alert",color:"danger",iconProps:{"data-test-subj":u("failed")},content:Object(l.jsx)(r.FormattedMessage,{id:"xpack.spaces.management.copyToSpace.copyStatusSummary.failedMessage",defaultMessage:"Copy to the {space} space failed. Expand this section for details.",values:{space:t.name}})});const m=b?Object(l.jsx)("span",{className:"spcCopyToSpace__missingReferencesIcon"},Object(l.jsx)(o.EuiIconTip,{type:"link",color:"warning",iconProps:{"data-test-subj":u("missingReferences")},content:Object(l.jsx)(r.FormattedMessage,{id:"xpack.spaces.management.copyToSpace.copyStatusSummary.missingReferencesMessage",defaultMessage:"Missing references detected in the {space} space. Expand this section for details.",values:{space:t.name}})})):null;return g?Object(l.jsx)(c.Fragment,null,Object(l.jsx)(resolve_all_conflicts_ResolveAllConflicts,{summarizedCopyResult:s,retries:n,onRetriesChange:i,onDestinationMapChange:p}),Object(l.jsx)(o.EuiIconTip,{type:"alert",color:"warning",iconProps:{"data-test-subj":u("conflicts")},content:Object(l.jsx)(r.FormattedMessage,{id:"xpack.spaces.management.copyToSpace.copyStatusSummary.conflictsMessage",defaultMessage:"Conflicts detected in the {space} space. Expand this section to resolve.",values:{space:t.name}})}),m):m})(e),Object(l.jsx)(o.EuiBadge,{color:"#DDD",className:"spcCopyToSpace__summaryCountBadge"},t.objects.length))};s(128);var R=s(41),I=s.n(R);const F=e=>{const{summarizedCopyResult:t,conflictResolutionInProgress:s,pendingObjectRetry:a}=e;if(t.processing||s)return Object(l.jsx)(o.EuiLoadingSpinner,null);const n=t.objects.find((t=>t.type===e.object.type&&t.id===e.object.id)),{conflict:i,hasMissingReferences:p,hasUnresolvableErrors:u,overwrite:d}=n,j=i&&!(null!=a&&a.overwrite),b=!p&&!u&&!j;if(b&&!a){const e=d?Object(l.jsx)(r.FormattedMessage,{id:"xpack.spaces.management.copyToSpace.copyStatus.successAutomaticOverwriteMessage",defaultMessage:"Object was overwritten."}):Object(l.jsx)(r.FormattedMessage,{id:"xpack.spaces.management.copyToSpace.copyStatus.successMessage",defaultMessage:"Object was copied."});return Object(l.jsx)(o.EuiIconTip,{type:"checkInCircleFilled",color:"success",content:e})}if(b&&a){const e=d?Object(l.jsx)(r.FormattedMessage,{id:"xpack.spaces.management.copyToSpace.copyStatus.pendingAutomaticOverwriteMessage",defaultMessage:"Object will be overwritten."}):null!=a&&a.overwrite?Object(l.jsx)(r.FormattedMessage,{id:"xpack.spaces.management.copyToSpace.copyStatus.pendingOverwriteMessage",defaultMessage:"Object will be overwritten. Disable 'Overwrite' to skip."}):Object(l.jsx)(r.FormattedMessage,{id:"xpack.spaces.management.copyToSpace.copyStatus.pendingMessage",defaultMessage:"Object will be copied."});return Object(l.jsx)(o.EuiIconTip,{type:"check",color:"warning",content:e})}if(u)return Object(l.jsx)(o.EuiIconTip,{type:"alert",color:"danger","data-test-subj":`cts-object-result-error-${n.id}`,content:Object(l.jsx)(r.FormattedMessage,{id:"xpack.spaces.management.copyToSpace.copyStatus.unresolvableErrorMessage",defaultMessage:"An error occurred copying this object."})});if(j)switch(i.error.type){case"conflict":return Object(l.jsx)(o.EuiIconTip,{type:"alert",color:"warning",content:Object(l.jsx)(c.Fragment,null,Object(l.jsx)(r.FormattedMessage,{id:"xpack.spaces.management.copyToSpace.copyStatus.conflictMessage",defaultMessage:"This conflicts with an existing object. Enable ‘Overwrite’ to replace it."}))});case"ambiguous_conflict":return Object(l.jsx)(o.EuiIconTip,{type:"alert",color:"warning",content:Object(l.jsx)(c.Fragment,null,Object(l.jsx)(r.FormattedMessage,{id:"xpack.spaces.management.copyToSpace.copyStatus.ambiguousConflictMessage",defaultMessage:"This conflicts with multiple existing objects. Enable ‘Overwrite’ to replace one."}))})}return p?Object(l.jsx)(o.EuiIconTip,{type:"link",color:"warning","data-test-subj":`cts-object-result-missing-references-${n.id}`,content:d?Object(l.jsx)(r.FormattedMessage,{id:"xpack.spaces.management.copyToSpace.copyStatus.missingReferencesAutomaticOverwriteMessage",defaultMessage:"Object will be overwritten, but one or more references are missing."}):i?Object(l.jsx)(r.FormattedMessage,{id:"xpack.spaces.management.copyToSpace.copyStatus.missingReferencesOverwriteMessage",defaultMessage:"Object will be overwritten, but one or more references are missing. Disable 'Overwrite' to skip."}):Object(l.jsx)(r.FormattedMessage,{id:"xpack.spaces.management.copyToSpace.copyStatus.missingReferencesMessage",defaultMessage:"Object will be copied, but one or more references are missing."})}):null};function z(e){switch(e){case"index-pattern":case"index-patterns":case"indexPatterns":return"index patterns";default:return e}}const N=e=>"ambiguous_conflict"===e.type,L=e=>{const{destinationMap:t,onDestinationMapChange:s,summarizedCopyResult:a}=e,{objects:n}=a;return Object(l.jsx)("div",{className:"spcCopyToSpaceResultDetails"},n.map(((a,n)=>{const{type:r,id:p,name:u,icon:d,conflict:j}=a,b=e.retries.find((e=>e.type===r&&e.id===p)),g=Boolean(null==b?void 0:b.overwrite),m={show:j&&!e.conflictResolutionInProgress,label:i.i18n.translate("xpack.spaces.management.copyToSpace.copyDetail.overwriteSwitch",{defaultMessage:"Overwrite?"}),onChange:({target:{checked:o}})=>{const a=e.retries.filter((e=>e.type!==r||e.id!==p)),{error:c}=j;if(o){const s=N(c)?t.get(`${r}:${p}`):c.destinationId,o={type:r,id:p,overwrite:!0,...s&&{destinationId:s}};e.onRetriesChange([...a,o])}else if(e.onRetriesChange(a),N(c)){const e=c.destinations[0].id;s(new Map(t.set(`${r}:${p}`,e)))}}},f={options:null!=j&&j.error&&N(j.error)?j.error.destinations.map((e=>{var t;const s=null!==(t=e.title)&&void 0!==t?t:`${r} [id=${e.id}]`,a=e.updatedAt?I()(e.updatedAt).fromNow():"never";return{value:e.id,inputDisplay:e.id,dropdownDisplay:Object(l.jsx)(c.Fragment,null,Object(l.jsx)("strong",null,s),Object(l.jsx)(o.EuiText,{size:"s",color:"subdued"},Object(l.jsx)("p",null,"ID: ",e.id,Object(l.jsx)("br",null),"Last updated: ",a)))}})):[],onChange:o=>{s(new Map(t.set(`${r}:${p}`,o)));const a=e.retries.filter((e=>e.type!==r||e.id!==p)),c={type:r,id:p,overwrite:!0,destinationId:o};e.onRetriesChange([...a,c])}},x=f.options.length>0&&g?" spcCopyToSpaceResultDetails__selectControl-isOpen":"";return Object(l.jsx)(c.Fragment,{key:n},Object(l.jsx)(o.EuiFlexGroup,{responsive:!1,key:n,alignItems:"center",gutterSize:"s",className:"spcCopyToSpaceResultDetails__row"},Object(l.jsx)(o.EuiFlexItem,{grow:!1},Object(l.jsx)(o.EuiToolTip,{position:"top",content:z(r)},Object(l.jsx)(o.EuiIcon,{"aria-label":z(r),type:d,size:"s"}))),Object(l.jsx)(o.EuiFlexItem,{grow:5,className:"spcCopyToSpaceResultDetails__savedObjectName"},Object(l.jsx)(o.EuiText,{size:"s"},Object(l.jsx)("p",{className:"eui-textTruncate",title:u},u))),m.show&&Object(l.jsx)(o.EuiFlexItem,{grow:!1},Object(l.jsx)(o.EuiSwitch,{label:m.label,compressed:!0,checked:g,onChange:m.onChange,"data-test-subj":`cts-overwrite-conflict-${r}:${p}`})),Object(l.jsx)(o.EuiFlexItem,{className:"spcCopyToSpaceResultDetails__statusIndicator",grow:!1},Object(l.jsx)("div",{className:"eui-textRight"},Object(l.jsx)(F,{summarizedCopyResult:e.summarizedCopyResult,object:a,pendingObjectRetry:b,conflictResolutionInProgress:e.conflictResolutionInProgress&&g})))),Object(l.jsx)("div",{className:"spcCopyToSpaceResultDetails__selectControl"+x},Object(l.jsx)("div",{className:"spcCopyToSpaceResultDetails__selectControl__childWrapper"},Object(l.jsx)(o.EuiSuperSelect,{options:f.options,valueOfSelected:t.get(`${r}:${p}`),onChange:f.onChange,prepend:i.i18n.translate("xpack.spaces.management.copyToSpace.copyDetail.selectControlLabel",{defaultMessage:"Object ID"}),hasDividers:!0,fullWidth:!0,compressed:!0}))))})))},D=Object(c.lazy)((()=>Object(v.a)().then((e=>({default:e}))))),P=e=>e.reduce(((e,{type:t,id:s,conflict:o})=>("ambiguous_conflict"===(null==o?void 0:o.error.type)&&e.set(`${t}:${s}`,o.error.destinations[0].id),e)),new Map),$=e=>{const{space:t}=e;return Object(l.jsx)(o.EuiAccordion,{id:`copyToSpace-${t.id}`,"data-test-subj":`cts-space-result-${t.id}`,className:"spcCopyToSpaceResult",buttonContent:Object(l.jsx)(o.EuiFlexGroup,{responsive:!1},Object(l.jsx)(o.EuiFlexItem,{grow:!1},Object(l.jsx)(c.Suspense,{fallback:Object(l.jsx)(o.EuiLoadingSpinner,null)},Object(l.jsx)(D,{space:t,size:"s"}))),Object(l.jsx)(o.EuiFlexItem,null,Object(l.jsx)(o.EuiText,null,t.name))),extraAction:Object(l.jsx)(o.EuiLoadingSpinner,null)},Object(l.jsx)(o.EuiSpacer,{size:"s"}),Object(l.jsx)(o.EuiLoadingSpinner,null))},A=e=>{const{space:t,summarizedCopyResult:s,retries:a,onRetriesChange:n,conflictResolutionInProgress:i}=e,{objects:r}=s,p=a.some((e=>e.overwrite)),[u,d]=Object(c.useState)(P(r)),j=e=>{d(e||P(r))};return Object(l.jsx)(o.EuiAccordion,{id:`copyToSpace-${t.id}`,"data-test-subj":`cts-space-result-${t.id}`,className:"spcCopyToSpaceResult",buttonContent:Object(l.jsx)(o.EuiFlexGroup,{responsive:!1},Object(l.jsx)(o.EuiFlexItem,{grow:!1},Object(l.jsx)(c.Suspense,{fallback:Object(l.jsx)(o.EuiLoadingSpinner,null)},Object(l.jsx)(D,{space:t,size:"s"}))),Object(l.jsx)(o.EuiFlexItem,null,Object(l.jsx)(o.EuiText,null,t.name))),extraAction:Object(l.jsx)(k,{space:t,retries:a,onRetriesChange:n,onDestinationMapChange:j,summarizedCopyResult:s,conflictResolutionInProgress:i&&p})},Object(l.jsx)(o.EuiSpacer,{size:"s"}),Object(l.jsx)(L,{summarizedCopyResult:s,space:t,retries:a,onRetriesChange:n,destinationMap:u,onDestinationMapChange:j,conflictResolutionInProgress:i&&p}))};function B(e){const{success:t,errors:s=[],successResults:o=[]}=e;return{success:t,failedImports:s.map((({error:e,...t})=>({obj:t,error:e}))),successfulImports:o}}const G=e=>"conflict"===e.error.type||"ambiguous_conflict"===e.error.type,U=e=>"missing_references"===e.error.type,H=(e,t)=>e.type>t.type?1:e.typeObject(l.jsx)("div",{"data-test-subj":"copy-to-space-processing"},(({createNewCopies:e,overwrite:t,includeRelated:s})=>{const a=e?Object(l.jsx)(r.FormattedMessage,{id:"xpack.spaces.management.copyToSpace.createNewCopiesLabel",defaultMessage:"Create new objects with random IDs"}):Object(l.jsx)(r.FormattedMessage,{id:"xpack.spaces.management.copyToSpace.dontCreateNewCopiesLabel",defaultMessage:"Check for existing objects"});return Object(l.jsx)(o.EuiListGroup,{className:"spcCopyToSpaceOptionsView",flush:!0},Object(l.jsx)(o.EuiListGroupItem,{iconType:"copy",label:a}),!e&&Object(l.jsx)(o.EuiListGroupItem,{iconType:t?"check":"cross",label:Object(l.jsx)(r.FormattedMessage,{id:"xpack.spaces.management.copyToSpace.overwriteLabel",defaultMessage:"Automatically overwrite conflicts"})}),Object(l.jsx)(o.EuiListGroupItem,{iconType:s?"check":"cross",label:Object(l.jsx)(r.FormattedMessage,{id:"xpack.spaces.management.copyToSpace.includeRelatedLabel",defaultMessage:"Include related saved objects"})}))})(e.copyOptions),Object(l.jsx)(o.EuiHorizontalRule,{margin:"m"}),Object(l.jsx)(o.EuiText,{size:"s"},Object(l.jsx)("h5",null,Object(l.jsx)(r.FormattedMessage,{id:"xpack.spaces.management.copyToSpace.copyResultsLabel",defaultMessage:"Results"}))),Object(l.jsx)(o.EuiSpacer,{size:"m"}),e.copyOptions.selectedSpaceIds.map((t=>{const s=e.spaces.find((e=>e.id===t)),a=e.copyResult[s.id],n=function(e,t){var s,o,a,c,n;const i=null!==(s=null==t?void 0:t.failedImports.filter(G))&&void 0!==s?s:[],r=null!==(o=null==t?void 0:t.failedImports.filter(U))&&void 0!==o?o:[],l=null!==(a=null==t?void 0:t.failedImports.filter((e=>{return!G(t=e)&&!U(t);var t})))&&void 0!==a?a:[],p=({type:e,id:s})=>{const o=i.find((({obj:t})=>t.type===e&&t.id===s)),a=r.find((({obj:t})=>t.type===e&&t.id===s));return{conflict:o,hasMissingReferences:void 0!==a,hasUnresolvableErrors:l.some((({obj:t})=>t.type===e&&t.id===s)),overwrite:!o&&(a?!0===a.obj.overwrite:!0===(null==t?void 0:t.successfulImports.some((t=>t.type===e&&t.id===s&&t.overwrite))))}},u=new Map;u.set(`${e.type}:${e.id}`,{type:e.type,id:e.id,name:e.title,icon:e.icon,...p(e)});const d=e=>{e.forEach((e=>{const{type:t,id:s,meta:o}=e;u.set(`${t}:${s}`,{type:t,id:s,name:o.title||`${t} [id=${s}]`,icon:o.icon||"apps",...p(e)})}))};if(d((null!==(c=null==t?void 0:t.failedImports)&&void 0!==c?c:[]).map((({obj:e})=>e)).sort(H)),d((null!==(n=null==t?void 0:t.successfulImports)&&void 0!==n?n:[]).sort(H)),void 0===t)return{processing:!0,objects:Array.from(u.values())};const j=Boolean(t&&0===t.failedImports.length);if(j)return{successful:j,hasConflicts:!1,objects:Array.from(u.values()),hasMissingReferences:!1,hasUnresolvableErrors:!1,processing:!1};const b=i.length>0,g=r.length>0,m=l.length>0;return{successful:j,hasConflicts:b,objects:Array.from(u.values()),hasMissingReferences:g,hasUnresolvableErrors:m,processing:!1}}(e.savedObjectTarget,a);return Object(l.jsx)(c.Fragment,{key:t},n.processing?Object(l.jsx)($,{space:s}):Object(l.jsx)(A,{space:s,summarizedCopyResult:n,retries:e.retries[s.id]||[],onRetriesChange:t=>{return o=s.id,a=t,void e.onRetriesChange({...e.retries,[o]:a});var o,a},conflictResolutionInProgress:e.conflictResolutionInProgress}),Object(l.jsx)(o.EuiSpacer,{size:"s"}))})));var V=s(14);const q=e=>{const{spacesManager:t,spacesDataPromise:s,services:n}=Object(V.b)(),{notifications:p}=n,u=p.toasts,{onClose:j=(()=>null),savedObjectTarget:b}=e,g=Object(c.useMemo)((()=>({type:b.type,id:b.id,namespaces:b.namespaces,icon:b.icon||"apps",title:b.title||`${b.type} [id=${b.id}]`})),[b]),[m,f]=Object(c.useState)({includeRelated:!0,createNewCopies:!0,overwrite:!0,selectedSpaceIds:[]}),[{isLoading:x,spaces:y},O]=Object(c.useState)({isLoading:!0,spaces:[]});Object(c.useEffect)((()=>{s.then((({spacesMap:e})=>{O({isLoading:!1,spaces:[...e.values()].filter((({isActiveSpace:e,isAuthorizedForPurpose:t})=>!e&&t("copySavedObjectsIntoSpace")))})})).catch((e=>{u.addError(e,{title:i.i18n.translate("xpack.spaces.management.copyToSpace.spacesLoadErrorTitle",{defaultMessage:"Error loading available spaces"})})}))}),[s,u]);const[h,C]=Object(c.useState)(!1),[v,S]=Object(c.useState)(!1),[w,M]=Object(c.useState)({}),[E,_]=Object(c.useState)({}),k=Object.values(w).length>0;return Object(l.jsx)(o.EuiFlyout,{onClose:j,maxWidth:600,"data-test-subj":"copy-to-space-flyout"},Object(l.jsx)(o.EuiFlyoutHeader,{hasBorder:!0},Object(l.jsx)(o.EuiFlexGroup,{alignItems:"center",gutterSize:"m"},Object(l.jsx)(o.EuiFlexItem,{grow:!1},Object(l.jsx)(o.EuiIcon,{size:"m",type:"copy"})),Object(l.jsx)(o.EuiFlexItem,null,Object(l.jsx)(o.EuiTitle,{size:"m"},Object(l.jsx)("h2",null,Object(l.jsx)(r.FormattedMessage,{id:"xpack.spaces.management.copyToSpaceFlyoutHeader",defaultMessage:"Copy to spaces"})))))),Object(l.jsx)(o.EuiFlyoutBody,null,Object(l.jsx)(o.EuiFlexGroup,{alignItems:"center",gutterSize:"m"},Object(l.jsx)(o.EuiFlexItem,{grow:!1},Object(l.jsx)(o.EuiIcon,{type:g.icon})),Object(l.jsx)(o.EuiFlexItem,null,Object(l.jsx)(o.EuiText,null,Object(l.jsx)("p",null,g.title)))),Object(l.jsx)(o.EuiHorizontalRule,{margin:"m"}),x?Object(l.jsx)(o.EuiLoadingSpinner,null):0===y.length?Object(l.jsx)(o.EuiEmptyPrompt,{body:Object(l.jsx)("p",null,Object(l.jsx)(r.FormattedMessage,{id:"xpack.spaces.management.copyToSpace.noSpacesBody",defaultMessage:"There are no eligible spaces to copy into."})),title:Object(l.jsx)("h3",null,Object(l.jsx)(r.FormattedMessage,{id:"xpack.spaces.management.copyToSpace.noSpacesTitle",defaultMessage:"No spaces available"}))}):h?Object(l.jsx)(W,{savedObjectTarget:g,copyInProgress:h,conflictResolutionInProgress:v,copyResult:w,spaces:y,copyOptions:m,retries:E,onRetriesChange:e=>{_(e)}}):Object(l.jsx)(T,{savedObjectTarget:g,spaces:y,copyOptions:m,onUpdate:f})),Object(l.jsx)(o.EuiFlyoutFooter,null,Object(l.jsx)(d,{copyInProgress:h,conflictResolutionInProgress:v,initialCopyFinished:k,copyResult:w,numberOfSelectedSpaces:m.selectedSpaceIds.length,retries:E,onClose:j,onCopyStart:async function(){C(!0),M({});try{const e=await t.copySavedObjects([{type:g.type,id:g.id}],m.selectedSpaceIds,m.includeRelated,m.createNewCopies,m.overwrite),s=Object(a.mapValues)(e,B);M(s);const o=e=>{const{failedImports:t,successfulImports:s}=e;if(!t.length)return[];const o=t.filter((({error:e})=>"missing_references"!==e.type)).reduce(((e,{obj:{type:t,id:s}})=>e.add(`${t}:${s}`)),new Set),a=t.filter((({obj:{type:e,id:t},error:s})=>"missing_references"===s.type&&!o.has(`${e}:${t}`)));return[...s.map((({type:e,id:t,overwrite:s,destinationId:o,createNewCopy:a})=>({type:e,id:t,overwrite:!0===s,destinationId:o,createNewCopy:a}))),...a.map((({obj:{type:e,id:t}})=>({type:e,id:t,overwrite:!1,ignoreMissingReferences:!0})))]},c=Object(a.mapValues)(s,o);_(c)}catch(e){C(!1),u.addError(e,{title:i.i18n.translate("xpack.spaces.management.copyToSpace.copyErrorTitle",{defaultMessage:"Error copying saved object"})})}},onCopyFinish:async function(){if(Object.values(E).some((e=>e.length))){S(!0);try{await t.resolveCopySavedObjectsErrors([{type:g.type,id:g.id}],E,m.includeRelated,m.createNewCopies),u.addSuccess(i.i18n.translate("xpack.spaces.management.copyToSpace.resolveCopySuccessTitle",{defaultMessage:"Copy successful"})),j()}catch(e){C(!1),u.addError(e,{title:i.i18n.translate("xpack.spaces.management.copyToSpace.resolveCopyErrorTitle",{defaultMessage:"Error resolving saved object conflicts"})})}}else j()}})))}},42:function(e,t,s){"use strict";var o,a=function(){var e={};return function(t){if(void 0===e[t]){var s=document.querySelector(t);if(window.HTMLIFrameElement&&s instanceof window.HTMLIFrameElement)try{s=s.contentDocument.head}catch(e){s=null}e[t]=s}return e[t]}}(),c=[];function n(e){for(var t=-1,s=0;s