/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import a from"./OOHXOPMN.js";import{a as h}from"./3JWEYJQ3.js";import"./HKOW6E75.js";import"./OUVF5KOE.js";import"./ZNBKMZP7.js";import{O as d,R as m,U as p,a as r,b as l}from"./E4G2DFST.js";import"./ALDX5YZO.js";export default $arcgis.t(([{watch:T},{a:u,b:g,c:v,d:f,f:n}])=>{var y=r`:host{overflow-y:hidden;display:flex;flex:1 0}.template-select-flow-item-container{display:flex;flex-direction:column;justify-content:space-between;overflow-y:hidden;flex-grow:1}.template-select-flow-item-container .template-select-flow-item-content{display:flex;flex-direction:column;overflow-y:auto;flex:1 0}.template-select-flow-item-container .template-select-flow-item-content .template-select-flow-item-list-heading{display:flex;gap:var(--calcite-spacing-xs);align-items:center;padding:var(--calcite-spacing-md) var(--calcite-spacing-lg);background-color:var(--calcite-color-foreground-2);border-bottom:1px solid var(--calcite-color-border-3);font-weight:var(--calcite-font-weight-semibold)}.template-button-container{padding:var(--calcite-spacing-md)}.template-done-button{width:100%}`,c=class extends d{constructor(){super(...arguments),this._handles=h("disconnect")}static{this.properties={_selectedTemplate:16,excludeOrganizationTemplates:5,viewModel:0,messages:0,hideTemplateSelector:0}}static{this.styles=y}loaded(){this.manager.onLifecycle(()=>[T(()=>this.viewModel.templateOptions.id,e=>{this._handles.removeHandles("template-handle"),this._selectedTemplate=e?this.viewModel.getLayoutTemplateById(e)??void 0:void 0,this._handles.addHandles(T(()=>this._selectedTemplate?.state,()=>this.requestUpdate(),{initial:!0}),"template-handle")},{initial:!0})])}_getPortalTemplates(){return this.viewModel.includeDefaultTemplates&&!this.excludeOrganizationTemplates?this.viewModel.defaultTemplates.toArray().filter(({layout:e,layoutItem:a})=>!n(e)&&!!a?.id):[]}_getDefaultTemplates(){return this.viewModel.includeDefaultTemplates?this.viewModel.defaultTemplates.toArray().filter(({layout:e,layoutItem:a})=>!n(e)&&!a?.id):[]}_getPrintServiceTemplates(){return!this.viewModel.includeDefaultTemplates||!this._getDefaultTemplates().length?this.viewModel.printServiceTemplates.toArray().filter(({layout:e})=>!n(e)):[]}render(){let{messages:e}=this,a=u.test(this.viewModel.portal?.url),t=this.viewModel.browseTemplates.toArray(),i=this._getPortalTemplates(),s=this._getDefaultTemplates(),o=this._getPrintServiceTemplates(),w=t.length+i.length+s.length+o.length>15;return l`<div class="template-select-flow-item-container"><div class="template-select-flow-item-content"><slot></slot><calcite-list .filterEnabled=${w} .filterProps=${["label"]} .label=${e.templateList} selection-mode=single-persist @calciteListChange=${({currentTarget:$})=>this.viewModel.applyTemplate($.selectedItems[0]?.value)}>${t.length?l`<div><div class="template-select-flow-item-list-heading">${e.myTemplates}${a?l`<calcite-chip appearance=outline kind=neutral .label=${e.beta} scale=s>${e.beta}</calcite-chip>`:null}</div>${this._renderLayoutTemplates(t,!0)}</div>`:null}${i.length?l`<div><div class="template-select-flow-item-list-heading">${e.organizationTemplates}${a?l`<calcite-chip appearance=outline kind=neutral .label=${e.beta} scale=s>${e.beta}</calcite-chip>`:null}</div>${this._renderLayoutTemplates(i)}</div>`:null}${t.length||i.length?s.length?l`<div><div class="template-select-flow-item-list-heading">${e.defaultTemplates}</div>${this._renderLayoutTemplates(s)}</div>`:null:this._renderLayoutTemplates(s)}${t.length||i.length?o.length?l`<div><div class="template-select-flow-item-list-heading">${e.defaultTemplates}</div>${this._renderLayoutTemplates(o)}</div>`:null:this._renderLayoutTemplates(o)}</calcite-list></div><div class="template-button-container"><calcite-button class="template-done-button" @click=${this.hideTemplateSelector}>Done</calcite-button></div></div>`}_renderLayoutTemplates(e,a=!1){return e.map(t=>l`<calcite-list-item .description=${g(t)} .label=${v(t,this.messages)} .selected=${t.id===this.viewModel.templateOptions.id} title=${t.description??""??m} .value=${t}><calcite-icon .icon=${(t.layout?f(t.layout):null)||"custom-print"} slot=content-start></calcite-icon>${t.state==="loading"?l`<calcite-loader inline label=loading scale=s slot=content-end></calcite-loader>`:null}${t?.state==="error"?l`<calcite-icon class="template-select-error" icon=exclamation-mark-circle scale=s slot=content-end></calcite-icon>`:null}${a?l`<calcite-action icon=trash @click=${()=>this.viewModel.removePortalTemplate(t)} slot=actions-end text=delete></calcite-action>`:null}</calcite-list-item>`)}};p("arcgis-print-template-selector",c);return c},"core/reactiveUtils",a)