/* COPYRIGHT Esri - https://js.arcgis.com/1.2/LICENSE.txt */
import e from"./SK6MHFPK.js";import b from"./EZAL5KYF.js";import a from"./HBC3TKGZ.js";import{b as $}from"./W4YXXJAS.js";import{b as y}from"./S7VQX4XX.js";import{qb as T,ra as C,rb as v,sb as D}from"./4Q4PZB7R.js";import{a as I}from"./XN2LWKJE.js";import"./4BPRM7CL.js";import"./NIL6NWG5.js";import"./ED6SUP22.js";import"./E6P6PYNW.js";import"./IKKBLHLZ.js";import"./CUA2IUXX.js";import"./4UZDZNJD.js";import"./KOTG6W5Z.js";import"./6SC7YR5Y.js";import"./Z6NOHRUL.js";import"./GVM4XYEI.js";import"./NGDVSE4Z.js";import"./BTNJZZQQ.js";import"./ZYQ4P2ON.js";import"./5MKH4QDV.js";import"./3GWWHA4S.js";import"./3YYHZQJB.js";import"./JEJ23R3P.js";import"./TONS7KZJ.js";import"./Q62UEPOL.js";import"./44A5XEM4.js";import{b as g}from"./ODCCVHGI.js";import{F as c,G as f,H as x,J as o,h as _,i as l,r as d}from"./42WFQ3AX.js";import"./3QPJ2JCA.js";export default $arcgis.t(([{m:S,n:b},{e:p},{a:E}])=>{var R=_`/** @license
 * Copyright 2025 Esri
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

.display-flex {
  display: flex;
}

.display-none {
  display: none;
}

.flex-direction-column {
  flex-direction: column;
}

.flex-direction-row {
  flex-direction: row;
}

.font-weight-medium {
  font-weight: var(--calcite-font-weight-medium);
}

.font-style-1 {
  font-size: 1rem;
  color: var(--calcite-color-text-2);
}

.margin-top-0 {
  margin-top: 0;
}

.padding-bottom-2 {
  padding-bottom: 2rem;
}

.padding-left-2 {
  padding-left: 2rem;
}

.padding-right-2 {
  padding-right: 2rem;
}

.padding-end-1 {
  padding-inline-end: 1rem;
}

.padding-end-1-2 {
  padding-inline-end: .5rem;
}

.width-full {
  width: 100%;
}

.justify-content-space {
  justify-content: space-between;
}`,m=class extends x{constructor(){super(...arguments),this.open=!1,this.source="Card Dropdown",this.solutionData={},this.templateInfos=[],this._saveDisabled=!1,this._displayTemplateInfos=[],this._hasNameLengthError=!1,this._nonSolutionDependencyItems=[],this._solutionItemsTitlesUpdating=!1,this._translations=I({name:"solution-configure-titles",blocking:!0}),this._configContextConsumer=y({context:$,subscribe:!0}),this._defaultPrefix="",this._defaultSuffix="",this._loadingDefaultPrefix=!1,this._loadingDefaultSuffix=!1,this._prefixRef=c(),this._prefixValue="",this._suffixRef=c(),this._suffixValue="",this._templateInfos=[],this.solutionConfigureTitlesBeforeClose=d(),this.solutionItemsTitlesChanged=d()}static{this.properties={card:[0,{},{attribute:!1}],open:[5,{},{type:Boolean}],source:1,solutionData:1,templateInfos:[0,{},{attribute:!1}],_saveDisabled:[16,{},{state:!0}],_displayTemplateInfos:[16,{},{state:!0}],_hasNameLengthError:[16,{},{state:!0}],_nonSolutionDependencyItems:[16,{},{state:!0}],_solutionItemsTitlesUpdating:[16,{},{state:!0}],_translations:[16,{},{state:!0}]}}static{this.styles=R}async willUpdate(e){if(e.has("templateInfos")&&(this._templateInfos=this.templateInfos,this._updateTemplates()),e.has("open")){let t=e.get("open");if(this.open&&!t){let i=await E(this._configContextConsumer.value.userSession,this.card);this._nonSolutionDependencyItems=i._nonSolutionDependencyItems,await this._accordionRef?.expandFirstItem(),this._accordionRef?.expandItems(i.uniqueIitemIds)}}}get _telemetry(){return this._configContextConsumer.value?.telemetrySession}async load(){this._updateTemplates(),await this._updatePrefixSuffix()}async _updatePrefixSuffix(){this.solutionData=await C(this.card.id,this._configContextConsumer.value.userSession),this.solutionData.titles?.prefix&&(this._loadingDefaultPrefix=!0,this._defaultPrefix=this.solutionData.titles.prefix,this._prefixValue=this.solutionData.titles.prefix),this.solutionData.titles?.suffix&&(this._loadingDefaultSuffix=!0,this._defaultSuffix=this.solutionData.titles.suffix,this._suffixValue=this.solutionData.titles.suffix)}render(){return l`<calcite-dialog .heading=${this.card.title} modal @calciteDialogBeforeClose=${()=>{this.solutionConfigureTitlesBeforeClose.emit()}} .open=${this.open} outside-close-disabled width=l>${this._getPrefixSuffixControls()}${this._getAccordion()}${this._getDialogButtons()}</calcite-dialog>`}_getPrefixSuffixControls(){let e=p(this._prefixValue,"item"),t=this._hasNameLengthError&&this._prefixValue.length>0,i=!e,s=!t,n=i?"display-none":"",a=s?"display-none":"",r=i&&s?"valid":"invalid",w=p(this._suffixValue,"item"),V=this._hasNameLengthError&&this._suffixValue.length>0,u=!w,h=!V,L=u?"display-none":"",P=h?"display-none":"",N=u&&h?"valid":"invalid";return this._saveDisabled=!i||!s||!u||!h,l`<div class="display-flex flex-direction-column padding-left-2 padding-right-2"><calcite-label scale=l class="font-weight-medium">${this._translations.configureTitlesDialogHeader}</calcite-label><p class="font-style-1 margin-top-0">${this._translations.addPrefixOrSuffixToItems}</p><div class="display-flex flex-direction-row justify-content-space"><calcite-label class="width-full padding-end-1" scale=l>${this._translations.prefixToAddToItems}<calcite-input clearable @blur=${this._prefixInput} @input=${this._prefixInput} .placeholder=${this._translations.enterPrefixPlaceholder} .status=${r} .value=${this._prefixValue} ${f(this._prefixRef)}></calcite-input><calcite-input-message class=${o(n)} icon=exclamation-mark-triangle status=invalid>${this._translations.invalidPrefixOrSuffixCharsError}</calcite-input-message><calcite-input-message class=${o(a)} icon=exclamation-mark-triangle status=invalid>${this._translations.invalidPrefixOrSuffixLengthError}</calcite-input-message></calcite-label><calcite-label class="width-full" scale=l>${this._translations.suffixToAddToItems}<calcite-input clearable @blur=${this._suffixInput} @input=${this._suffixInput} .placeholder=${this._translations.enterSuffixPlaceholder} .status=${N} .value=${this._suffixValue} ${f(this._suffixRef)}></calcite-input><calcite-input-message class=${o(L)} icon=exclamation-mark-triangle status=invalid>${this._translations.invalidPrefixOrSuffixCharsError}</calcite-input-message><calcite-input-message class=${o(P)} icon=exclamation-mark-triangle status=invalid>${this._translations.invalidPrefixOrSuffixLengthError}</calcite-input-message></calcite-label></div></div>`}_getAccordion(){let e=[...new Set(this._nonSolutionDependencyItems.map(t=>t.controlItemId))];return l`<div class="display-flex flex-direction-column padding-left-2 padding-right-2 padding-bottom-2"><p class="font-style-1 margin-top-0">${this._translations.previewTheChanges}</p><solution-item-accordion .itemRelationshipDependencies=${e} list-selection-mode=multiple .reuseWarning=${this._translations.itemDependencyReuseWarning} .templateInfos=${this._displayTemplateInfos} .typeKeywords=${this.card?.typeKeywords} ${f(async t=>{t&&(this._accordionRef=t)})}></solution-item-accordion></div>`}_getDialogButtons(){return l`<div slot=footer-end><calcite-button appearance=outline class="padding-end-1-2" kind=brand @click=${this._closeDialog}>${this._translations.cancelTheDialog}</calcite-button><calcite-button .disabled=${this._saveDisabled} kind=brand .loading=${this._solutionItemsTitlesUpdating} @click=${this._commitNameChanges}>${this._translations.applyChangesAndCloseTheDialog}</calcite-button></div>`}_prefixInput(){clearTimeout(this._textInputTimeout),this._textInputTimeout=setTimeout(()=>{this._prefixValue=this._prefixRef.value?.value||"",this._updateTemplates()},500)}_suffixInput(){clearTimeout(this._textInputTimeout),this._textInputTimeout=setTimeout(()=>{this._suffixValue=this._suffixRef.value?.value||"",this._updateTemplates()},500)}_updateTemplates(){this._templateInfos=this._templateInfos.map(t=>(this._loadingDefaultPrefix&&t.title.startsWith(this._prefixValue)&&(t.title=this._replaceStart(t.title,this._prefixValue,"")),this._loadingDefaultSuffix&&t.title.endsWith(this._suffixValue)&&(t.title=this._replaceAtEnd(t.title,this._suffixValue,"")),t));let e=JSON.parse(JSON.stringify(this._templateInfos));this._hasNameLengthError=!1,this._displayTemplateInfos=e.map(t=>{let i=this._prefixValue!=="",s=this._suffixValue!=="";return t.title=i&&s?`${`${this._prefixValue}`}${t.title}${`${this._suffixValue}`}`:i?`${`${this._prefixValue}`}${t.title}`:s?`${t.title}${`${this._suffixValue}`}`:t.title,this._hasNameLengthError||(this._hasNameLengthError=t.title.length>S),t}),this._loadingDefaultPrefix=!1,this._loadingDefaultSuffix=!1}_replaceStart(e,t,i){return e.startsWith(t)?`${i}${e.slice(t.length)}`:e}_replaceAtEnd(e,t,i){return e.endsWith(t)?`${e.substring(0,e.length-t.length)}${i}`:e}_closeDialog(){this.open=!1}async _commitNameChanges(){let e=this._defaultPrefix!==this._prefixValue,t=this._defaultSuffix!==this._suffixValue;if(JSON.stringify(this._templateInfos)!==JSON.stringify(this._displayTemplateInfos)||e||t){this._telemetry?.logEvent({category:b.DEPLOYMENTS,action:"Rename Items",dimensions:[this.card?.title||"",this.card?.deployCommonId||"",this.card?.deployVersion||"",this.source]}),this._solutionItemsTitlesUpdating=!0;let s=this._displayTemplateInfos.reduce((n,a)=>{let r={id:a.id,title:a.title};return n.push(a.type==="Group"?v(r,this._configContextConsumer.value.userSession):T(r,this._configContextConsumer.value.userSession)),n},[]);if(this.solutionData?.templates){let n={id:this.card.id},a={...this.solutionData,titles:{prefix:this._prefixValue,suffix:this._suffixValue}};s.push(D(n,a,this._configContextConsumer.value.userSession))}await Promise.all(s),this._solutionItemsTitlesUpdating=!1,this.solutionItemsTitlesChanged.emit()}this._closeDialog()}};g("solution-configure-titles",m);return m},a,b,e)