/*! 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. */!function(e){function t(t){for(var n,a,s=t[0],i=t[1],c=0,u=[];c{const{SpaceAvatarInternal:e}=await n.e(9).then(n.bind(null,150));return t=>Object(r.jsx)(e,t)};var s=n(20)},function(e,t){e.exports=__kbnSharedDeps__.ReactDom},function(e,t,n){n.r(t);var r=__kbnBundles__.get("plugin/kibanaReact/public");Object.defineProperties(t,Object.getOwnPropertyDescriptors(r))},function(e,t){e.exports=__kbnSharedDeps__.TsLib},function(e,t,n){"use strict";n.d(t,"b",(function(){return s})),n.d(t,"a",(function(){return i}));var r=n(2);let a;const s=()=>(a||(a=r.i18n.translate("xpack.spaces.featureDescription",{defaultMessage:"Organize your dashboards and other saved objects into meaningful categories."})),a),i=r.i18n.translate("xpack.spaces.shareToSpace.objectNoun",{defaultMessage:"object"})},function(e,t,n){"use strict";n.d(t,"b",(function(){return r.b})),n.d(t,"a",(function(){return c}));var r=n(22),a=n(6),s=n.n(a),i=(n(1),n(0));const c=async e=>{const{SpacesContextWrapperInternal:t}=await n.e(11).then(n.bind(null,152));return({children:n,...r})=>Object(i.jsx)(t,s()({},e,r,{children:n}))}},function(e,t){e.exports=__kbnSharedDeps__.Lodash},function(e,t){e.exports=__kbnSharedDeps__.RxjsOperators},function(e,t,n){"use strict";n.r(t),n.d(t,"isReservedSpace",(function(){return a.a})),n.d(t,"MAX_SPACE_INITIALS",(function(){return s.d})),n.d(t,"SPACE_SEARCH_COUNT_THRESHOLD",(function(){return s.e})),n.d(t,"ENTER_SPACE_PATH",(function(){return s.c})),n.d(t,"DEFAULT_SPACE_ID",(function(){return s.b})),n.d(t,"addSpaceIdToPath",(function(){return o})),n.d(t,"getSpaceIdFromPath",(function(){return c})),n.d(t,"spaceV1",(function(){return r}));var r={};n.r(r);var a=n(21),s=n(7);const i=/^\/s\/([a-z0-9_\-]+)/;function c(e,t){null==e&&(e="/"),null==t&&(t="/");const n=function(e,t){return t&&"/"!==t&&e.startsWith(t)?e.substr(t.length):e}(e,t),r=n.match(i);if(!r||0===r.length)return{spaceId:s.b,pathHasExplicitSpaceIdentifier:!1};const[,a]=r;if(!a)throw new Error(`Unable to determine Space ID from request path: ${e}`);return{spaceId:a,pathHasExplicitSpaceIdentifier:!0}}function o(e="/",t="",n=""){if(n&&!n.startsWith("/"))throw new Error("path must start with a /");const r=e.endsWith("/")?e.slice(0,-1):e;return t&&t!==s.b?`${r}/s/${t}${n}`:`${r}${n}`||"/"}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(12),a=n(1),s=r.__importDefault(n(28));t.default=function(e,t){void 0===t&&(t=[]);var n=s.default(e,t,{loading:!0}),r=n[0],i=n[1];return a.useEffect((function(){i()}),[i]),r}},function(e,t){e.exports=__kbnSharedDeps_npm__},function(e,t,n){"use strict";n.d(t,"a",(function(){return i})),n.d(t,"c",(function(){return c})),n.d(t,"b",(function(){return o}));var r=n(5),a=n(17);const s=97;function i(e={}){const{color:t,name:n=""}=e;if(t)return t;const a=n.codePointAt(0)||s;return r.VISUALIZATION_COLORS[a%r.VISUALIZATION_COLORS.length]}function c(e={}){const{initials:t,name:n=""}=e;if(t)return t;const r=n.split(" "),s=Math.min(a.MAX_SPACE_INITIALS,r.length);return r.splice(s,r.length),r.map((e=>e.substring(0,1))).join("")}function o(e={}){const{imageUrl:t}=e;return t||""}},function(e,t,n){"use strict";n.d(t,"a",(function(){return a}));var r=n(15);function a(e){return Object(r.get)(e,"_reserved",!1)}},function(e,t,n){"use strict";n.d(t,"b",(function(){return o})),n.d(t,"a",(function(){return u}));var r=n(1);const{useContext:a,createElement:s,createContext:i}=r,c=i({}),o=()=>a(c),u=(e,t,n)=>{const r={spacesManager:t,spacesDataPromise:n,services:e};return{value:r,Provider:({children:e})=>s(c.Provider,{value:r,children:e}),Consumer:c.Consumer}}},function(e,t,n){"use strict";n.d(t,"b",(function(){return f})),n.d(t,"a",(function(){return h})),n.d(t,"c",(function(){return p})),n.d(t,"d",(function(){return u}));var r=n(1),a=n.n(r),s=n(25),i=n.n(s),c=n(0);const o=a.a.createContext(null),u=({children:e,...t})=>{const{navigateToUrl:n,currentAppId:r}=t;return Object(c.jsx)(o.Provider,{value:{navigateToUrl:n,currentAppId:r}},e)},p=({children:e,coreStart:t})=>{const{navigateToUrl:n,currentAppId$:r}=t.application,a=i()(r,void 0);return Object(c.jsx)(o.Provider,{value:{navigateToUrl:n,currentAppId:a}},e)};n(5),n(6);const l={name:"36bnqj",styles:"display:flex;flex:1"},d=({children:e,navigateToUrl:t,currentAppId:n})=>{const a=Object(r.useRef)(null),s=Object(r.useCallback)((e=>(({event:e,container:t,navigateToUrl:n,currentAppId:r})=>{if(!t||!r)return;const a=((e,t)=>{let n=e;do{var r,a;if("a"===(null===(r=n)||void 0===r?void 0:r.tagName.toLowerCase()))return n;const e=null===(a=n)||void 0===a?void 0:a.parentElement;if(!e||e===document.body||e===t)break;n=e}while(parent||parent!==document.body||parent!==t)})(e.target,t);if(!a)return;const s=a.href,i=""===a.target||"_self"===a.target,c=0===e.button;s&&i&&c&&!e.defaultPrevented&&!(e=>e.metaKey||e.altKey||e.ctrlKey||e.shiftKey)(e)&&(e.preventDefault(),n(a.href))})({event:e,currentAppId:n,navigateToUrl:t,container:a.current})),[n,t]);return Object(c.jsx)("div",{onClick:s,ref:a,css:l},e)},f=({children:e})=>Object(c.jsx)(d,function(){const e=Object(r.useContext)(o);if(!e)throw new Error("RedirectAppLinksContext is missing. Ensure your component or React root is wrapped with RedirectAppLinksProvider.");return e}(),e),h=({children:e,...t})=>{const n=Object(c.jsx)(f,null,e);if(void 0!==t.coreStart){const{coreStart:e}=t;return Object(c.jsx)(p,{coreStart:e},n)}const{navigateToUrl:r,currentAppId:a}=t;return Object(c.jsx)(u,{currentAppId:a,navigateToUrl:r},n)}},function(e,t,n){"use strict";n.d(t,"a",(function(){return a})),n(1);var r=n(0);const a=async()=>{const{CopyToSpaceFlyoutInternal:e}=await n.e(2).then(n.bind(null,155));return t=>Object(r.jsx)(e,t)}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(12),a=n(1),s=r.__importDefault(n(31));t.default=function(e,t){var n=a.useState(t),r=n[0],i=n[1];return s.default((function(){var t=e.subscribe(i);return function(){return t.unsubscribe()}}),[e]),r}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(12),a=n(32),s=r.__importDefault(n(34));t.default=function(e,t){s.default(e,t,a.isDeepEqual)}},function(e,t){e.exports=__kbnSharedDeps__.Rxjs},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(12),a=n(1),s=r.__importDefault(n(35));t.default=function(e,t,n){void 0===t&&(t=[]),void 0===n&&(n={loading:!1});var i=a.useRef(0),c=s.default(),o=a.useState(n),u=o[0],p=o[1],l=a.useCallback((function(){for(var t=[],n=0;n{const a=Object(c.useMemo)((()=>{if(t)return e=>Object(_.jsx)(o.a.Fragment,null,Object(_.jsx)(y,null),Object(_.jsx)(t,e))}),[t]);if(a)return Object(_.jsx)(l.Route,g()({},r,{component:a}));if(n||"function"==typeof e){const t="function"==typeof e?e:n;return Object(_.jsx)(l.Route,g()({},r,{render:e=>Object(_.jsx)(o.a.Fragment,null,Object(_.jsx)(y,null),t(e))}))}return Object(_.jsx)(l.Route,r,Object(_.jsx)(y,null),e)},y=()=>{const{executionContext:e}=Object(c.useContext)(v).services,t=Object(l.useRouteMatch)();return function(e,t){j()((()=>(null==e||e.set(t),()=>{null==e||e.clear()})),[t])}(e,{type:"application",page:t.path,id:Object.keys(t.params).length>0?JSON.stringify(t.params):void 0}),null};var O=n(8);const x=({children:e,...t})=>Object(_.jsx)(l.Router,t,Object(_.jsx)(O.CompatRouter,null,e));var w=n(15);const A=({legacySwitch:e=!0,children:t})=>{const n=Object(l.useRouteMatch)();return e?Object(_.jsx)(l.Switch,null,t):Object(_.jsx)(O.Routes,null,c.Children.map(t,(e=>{if(o.a.isValidElement(e)&&e.type===m){var r;const a=Object(w.replace)(null==e?void 0:e.props.path,n.url+"/",""),s="function"==typeof(null==e?void 0:e.props.children)?null==e?void 0:e.props.children:null==e?void 0:e.props.render;return Object(_.jsx)(O.Route,{path:a,element:Object(_.jsx)(o.a.Fragment,null,Object(_.jsx)(y,null),(null==e||null===(r=e.props)||void 0===r?void 0:r.component)&&Object(_.jsx)(e.props.component,null)||s&&s()||t)})}return e})))},P=Object.freeze({id:"spaces",create({getStartServices:e,spacesManager:t,config:r}){const a=s.i18n.translate("xpack.spaces.displayName",{defaultMessage:"Spaces"});return{id:this.id,order:2,title:a,async mount({element:i,theme$:c,setBreadcrumbs:o,history:p}){const[[h,{features:g}],{SpacesGridPage:b},{ManageSpacePage:v}]=await Promise.all([e(),n.e(6).then(n.bind(null,158)),n.e(5).then(n.bind(null,154))]),S={text:a,href:"/"},{notifications:j,i18n:y,application:O,chrome:w}=h;return w.docTitle.change(a),Object(u.render)(Object(_.jsx)(d.KibanaContextProvider,{services:h},Object(_.jsx)(y.Context,null,Object(_.jsx)(d.KibanaThemeProvider,{theme$:c},Object(_.jsx)(f.a,{coreStart:h},Object(_.jsx)(x,{history:p},Object(_.jsx)(A,null,Object(_.jsx)(m,{path:["","/"],exact:!0},Object(_.jsx)((()=>(o([{...S,href:void 0}]),Object(_.jsx)(b,{capabilities:O.capabilities,getFeatures:g.getFeatures,notifications:j,spacesManager:t,history:p,getUrlForApp:O.getUrlForApp,maxSpaces:r.maxSpaces}))),null)),Object(_.jsx)(m,{path:"/create"},Object(_.jsx)((()=>(o([S,{text:s.i18n.translate("xpack.spaces.management.createSpaceBreadcrumb",{defaultMessage:"Create"})}]),Object(_.jsx)(v,{capabilities:O.capabilities,getFeatures:g.getFeatures,notifications:j,spacesManager:t,history:p,allowFeatureVisibility:r.allowFeatureVisibility}))),null)),Object(_.jsx)(m,{path:"/edit/:spaceId"},Object(_.jsx)((()=>{const{spaceId:e}=Object(l.useParams)();return Object(_.jsx)(v,{capabilities:O.capabilities,getFeatures:g.getFeatures,notifications:j,spacesManager:t,spaceId:e,onLoadSpace:e=>{o([S,{text:e.name}])},history:p,allowFeatureVisibility:r.allowFeatureVisibility})}),null)))))))),i),()=>{w.docTitle.reset(),Object(u.unmountComponentAtNode)(i)}}}}});class management_service_ManagementService{constructor(){a()(this,"registeredSpacesManagementApp",void 0)}setup({getStartServices:e,management:t,spacesManager:n,config:r}){this.registeredSpacesManagementApp=t.sections.section.kibana.registerApp(P.create({getStartServices:e,spacesManager:n,config:r}))}stop(){this.disableSpacesApp()}disableSpacesApp(){this.registeredSpacesManagementApp&&this.registeredSpacesManagementApp.disable()}}var C=n(5);const M=Object.freeze({id:"space_selector",create({application:e,getStartServices:t,spacesManager:r}){e.register({id:this.id,title:s.i18n.translate("xpack.spaces.spaceSelector.appTitle",{defaultMessage:"Select a space"}),chromeless:!0,appRoute:"/spaces/space_selector",mount:async({element:e,theme$:a})=>{const[[s],{renderSpaceSelectorApp:i}]=await Promise.all([t(),n.e(1).then(n.bind(null,153))]);return i(s.i18n,{element:e,theme$:a},{spacesManager:r,serverBasePath:s.http.basePath.serverBasePath,customBranding$:s.customBranding.customBranding$})}})}});var k=n(27),T=n(16);class spaces_manager_SpacesManager{constructor(e){a()(this,"activeSpace$",new k.BehaviorSubject(null)),a()(this,"serverBasePath",void 0),a()(this,"_onActiveSpaceChange$",void 0),this.http=e,this.serverBasePath=e.basePath.serverBasePath,this._onActiveSpaceChange$=this.activeSpace$.asObservable().pipe(Object(T.skipWhile)((e=>null==e)))}get onActiveSpaceChange$(){return this.activeSpace$.value||this.refreshActiveSpace(),this._onActiveSpaceChange$}async getSpaces(e={}){const{purpose:t,includeAuthorizedPurposes:n}=e,r={purpose:t,include_authorized_purposes:n};return await this.http.get("/api/spaces/space",{query:r})}async getSpace(e){return await this.http.get(`/api/spaces/space/${encodeURIComponent(e)}`)}async getActiveSpace({forceRefresh:e=!1}={}){if(this.isAnonymousPath())throw new Error("Cannot retrieve the active space for anonymous paths");return!e&&this.activeSpace$.value||await this.refreshActiveSpace(),this.activeSpace$.value}async createSpace(e){await this.http.post("/api/spaces/space",{body:JSON.stringify(e)})}async updateSpace(e){await this.http.put(`/api/spaces/space/${encodeURIComponent(e.id)}`,{query:{overwrite:!0},body:JSON.stringify(e)});const t=(await this.getActiveSpace()).id;e.id===t&&this.refreshActiveSpace()}async deleteSpace(e){await this.http.delete(`/api/spaces/space/${encodeURIComponent(e.id)}`)}async disableLegacyUrlAliases(e){await this.http.post("/api/spaces/_disable_legacy_url_aliases",{body:JSON.stringify({aliases:e})})}async copySavedObjects(e,t,n,r,a){return this.http.post("/api/spaces/_copy_saved_objects",{body:JSON.stringify({objects:e,spaces:t,includeReferences:n,createNewCopies:r,...r?{overwrite:!1}:{overwrite:a}})})}async resolveCopySavedObjectsErrors(e,t,n,r){return this.http.post("/api/spaces/_resolve_copy_saved_objects_errors",{body:JSON.stringify({objects:e,includeReferences:n,createNewCopies:r,retries:t})})}async getShareSavedObjectPermissions(e){return this.http.get("/internal/security/_share_saved_object_permissions",{query:{type:e}}).catch((e=>{var t;if(404===(null==e||null===(t=e.body)||void 0===t?void 0:t.statusCode))return{shareToAllSpaces:!0};throw e}))}async getShareableReferences(e){const t=await this.http.post("/api/spaces/_get_shareable_references",{body:JSON.stringify({objects:e})}),n=e.reduce(((e,{type:t,id:n})=>e.add(`${t}:${n}`)),new Set);return{objects:t.objects.filter((({type:e,id:t})=>"tag"!==e||n.has(`${e}:${t}`)))}}async updateSavedObjectsSpaces(e,t,n){return this.http.post("/api/spaces/_update_objects_spaces",{body:JSON.stringify({objects:e,spacesToAdd:t,spacesToRemove:n})})}redirectToSpaceSelector(){window.location.href=`${this.serverBasePath}/spaces/space_selector`}async refreshActiveSpace(){if(this.isAnonymousPath())return;const e=await this.http.get("/internal/spaces/_active_space");this.activeSpace$.next(e)}isAnonymousPath(){return this.http.anonymousPaths.isAnonymous(window.location.pathname)}}var I=n(18),E=n.n(I);class suspense_error_boundary_SuspenseErrorBoundary extends c.Component{constructor(...e){super(...e),a()(this,"state",{error:null})}static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e){const{notifications:t}=this.props;if(t){const n=s.i18n.translate("xpack.spaces.uiApi.errorBoundaryToastTitle",{defaultMessage:"Failed to load Kibana asset"}),r=s.i18n.translate("xpack.spaces.uiApi.errorBoundaryToastMessage",{defaultMessage:"Reload page to continue."});t.toasts.addError(e,{title:n,toastMessage:r})}}render(){const{children:e,notifications:t,showLoadingSpinner:n=!0}=this.props,{error:r}=this.state;if(!t||r)return null;const a=n?Object(_.jsx)(C.EuiLoadingSpinner,null):null;return Object(_.jsx)(c.Suspense,{fallback:a},e)}}const R=({fn:e,getStartServices:t,showLoadingSpinner:n,props:r})=>{const{value:a=[{notifications:void 0}]}=E()(t),[{notifications:s}]=a,i=Object(c.useMemo)((()=>Object(c.lazy)((()=>e().then((e=>({default:e})))))),[e]);return s?Object(_.jsx)(suspense_error_boundary_SuspenseErrorBoundary,{notifications:s,showLoadingSpinner:n},Object(_.jsx)(i,r)):null};var L=n(24);function D(e){return async function({path:t,aliasPurpose:n,objectNoun:r=i.a}){const[{notifications:a,application:c}]=await e(),{currentAppId$:o,navigateToApp:u}=c,p=await o.pipe(Object(T.first)()).toPromise();if("savedObjectConversion"===n){const e=s.i18n.translate("xpack.spaces.redirectLegacyUrlToast.title",{defaultMessage:"We redirected you to a new URL"}),t=s.i18n.translate("xpack.spaces.redirectLegacyUrlToast.text",{defaultMessage:"The {objectNoun} you're looking for has a new location. Use this URL from now on.",values:{objectNoun:r}});a.toasts.addInfo({title:e,text:t})}await u(p,{replace:!0,path:t})}}const $=async()=>{const{ShareToSpaceFlyoutInternal:e}=await n.e(3).then(n.bind(null,156));return t=>Object(_.jsx)(e,t)};var U=n(9);const N=async()=>{const{SpaceListInternal:e}=await n.e(10).then(n.bind(null,151));return t=>Object(_.jsx)(e,t)};var F=n(14);const B=({spacesManager:e,getStartServices:t})=>{function r(e,n={}){const{showLoadingSpinner:r}=n;return n=>Object(_.jsx)(R,{fn:e,getStartServices:t,props:n,showLoadingSpinner:r})}return{getSpacesContextProvider:r((()=>Object(F.a)({spacesManager:e,getStartServices:t}))),getShareToSpaceFlyout:r($,{showLoadingSpinner:!1}),getCopyToSpaceFlyout:r(L.a,{showLoadingSpinner:!1}),getSpaceList:r(N),getEmbeddableLegacyUrlConflict:r((()=>(async e=>{const{EmbeddableLegacyUrlConflictInternal:t}=await n.e(7).then(n.bind(null,148));return n=>Object(_.jsx)(t,g()({},e,n))})({spacesManager:e,getStartServices:t}))),getLegacyUrlConflict:r((()=>(async e=>{const{LegacyUrlConflictInternal:t}=await n.e(8).then(n.bind(null,149));return n=>Object(_.jsx)(t,g()({},e,n))})({getStartServices:t}))),getSpaceAvatar:r(U.a)}},z=({spacesManager:e,getStartServices:t})=>({components:B({spacesManager:e,getStartServices:t}),redirectLegacyUrl:D(t),useSpaces:F.b});class plugin_SpacesPlugin{constructor(e){a()(this,"spacesManager",void 0),a()(this,"spacesApi",void 0),a()(this,"managementService",void 0),a()(this,"config",void 0),this.initializerContext=e,this.config=this.initializerContext.config.get()}setup(e,t){return this.spacesManager=new spaces_manager_SpacesManager(e.http),this.spacesApi={ui:z({spacesManager:this.spacesManager,getStartServices:e.getStartServices}),getActiveSpace$:()=>this.spacesManager.onActiveSpaceChange$,getActiveSpace:()=>this.spacesManager.getActiveSpace()},t.home&&t.home.featureCatalogue.register({id:"spaces",title:s.i18n.translate("xpack.spaces.spacesTitle",{defaultMessage:"Spaces"}),description:Object(i.b)(),icon:"spacesApp",path:"/app/management/kibana/spaces",showOnHomePage:!1,category:"admin"}),t.management&&(this.managementService=new management_service_ManagementService,this.managementService.setup({management:t.management,getStartServices:e.getStartServices,spacesManager:this.spacesManager,config:this.config})),M.create({getStartServices:e.getStartServices,application:e.application,spacesManager:this.spacesManager}),{}}start(e){return function(e,t){const r=t.i18n.Context,{theme$:a}=t.theme;t.chrome.navControls.registerLeft({order:1e3,mount(s){if(t.http.anonymousPaths.isAnonymous(window.location.pathname))return()=>null;const i=Object(c.lazy)((()=>n.e(4).then(n.bind(null,157)).then((({NavControlPopover:e})=>({default:e})))));return p.a.render(Object(_.jsx)(r,null,Object(_.jsx)(d.KibanaThemeProvider,{theme$:a},Object(_.jsx)(c.Suspense,{fallback:Object(_.jsx)(C.EuiLoadingSpinner,null)},Object(_.jsx)(i,{spacesManager:e,serverBasePath:t.http.basePath.serverBasePath,anchorPosition:"downLeft",capabilities:t.application.capabilities,navigateToApp:t.application.navigateToApp,navigateToUrl:t.application.navigateToUrl})))),s),()=>{p.a.unmountComponentAtNode(s)}}})}(this.spacesManager,e),this.spacesApi}stop(){this.managementService&&(this.managementService.stop(),this.managementService=void 0)}}const K=e=>new plugin_SpacesPlugin(e)},function(e,t){e.exports=__kbnSharedDeps__.KbnI18nReact},function(e,t){e.exports=__kbnSharedDeps__.Classnames},function(e,t){e.exports=__kbnSharedDeps__.EmotionCache},function(e,t,n){n.r(t);var r=__kbnBundles__.get("plugin/esUiShared/public");Object.defineProperties(t,Object.getOwnPropertyDescriptors(r))},function(e,t){e.exports=__kbnSharedDeps__.Moment}]);