import{__decorate as e}from"tslib";import{InvalidOperationError as i}from"../../InvalidOperationError.js";import{isLayerExtension as t,isSublayerExtension as d}from"../../ItemType.js";import{serializable as n,SerializableBase as s}from"../../support/Serializable.js";import{notifyChange as l,observable as r,watch as a}from"../../support/observableUtils.js";import{checkArg as u}from"../../utilities/checkArg.js";export class LayerListSettingsProperties{expanded;included;childrenIncluded}let h=class extends(r(s)){get expanded(){return this._expanded}set expanded(e){this._expanded=e}get included(){return this._included}set included(e){this._included=e}get effectivelyIncluded(){return this.included}get initialExpanded(){return this._initialExpanded}get initialChildrenIncluded(){return this._initialChildrenIncluded}get initialIncluded(){return this._initialIncluded}get childrenIncluded(){return this._childrenIncluded}set childrenIncluded(e){this._childrenIncluded=e}_initialExpanded;_initialIncluded;_initialChildrenIncluded;_childrenIncluded;_expanded;_included;_getSerializableProperties(){return{expanded:{serializeModes:["initial"],default:!1},included:{serializeModes:["initial"],default:!0},childrenIncluded:{serializeModes:["initial"],default:!0}}}};h=e([n],h);export{h as LayerListSettings};export class ExtensionBaseLayerListSettings extends h{_extension;_defaultChildrenIncluded;_initialEsriLayerListMode;constructor(e,i,d){u("extension",i).isNotMissing().isDefined(),super(e),this._extension=i,this._defaultChildrenIncluded=d;const n=t(i)?i.layer:i.sublayer,s=e=>{t(i)?a(i,"layer",e,{once:!0}):a(i,"sublayer",e,{once:!0})};"included"in e?(this._initialIncluded=e.included,l(this,"initialIncluded")):(n?this._initialIncluded=this.included:s((()=>{this._initialIncluded=this.included,l(this,"initialIncluded")})),void 0===this._initialIncluded&&(this._initialIncluded=!0,l(this,"initialIncluded"))),"childrenIncluded"in e?(this._initialChildrenIncluded=e.childrenIncluded,l(this,"initialChildrenIncluded")):(n?this._initialChildrenIncluded=this.childrenIncluded:s((()=>{this._initialChildrenIncluded=this.childrenIncluded,l(this,"initialChildrenIncluded")})),void 0===this._initialChildrenIncluded&&(this._initialChildrenIncluded=!0,l(this,"initialChildrenIncluded"))),n?this._initialEsriLayerListMode=n.listMode:s((()=>{void 0===this._initialEsriLayerListMode&&(this._initialEsriLayerListMode=this._esriLayer.listMode)})),this._initialExpanded=e.expanded??!1}get included(){return void 0!==super.included?super.included:!this._esriLayer||"hide"!==this._esriLayer.listMode}set included(e){u("value",e).satisfies((e=>"boolean"==typeof e),"LayerListSettings must be set to boolean values"),super.included=e,this._setListMode()}get effectivelyIncluded(){const e=i=>{if(t(i)){const t=i.parentLayerExtension;return t?t.layerListSettings.childrenIncluded&&e(t):i.layerListSettings.included}if(d(i)){const t=i.parentSublayerExtension??i.layerExtension;return t.layerListSettings.childrenIncluded&&e(t)}return!1};return e(this._extension)}get childrenIncluded(){return void 0!==super.childrenIncluded?super.childrenIncluded:this._esriLayer?this._supportsChildren&&"show"===this._esriLayer.listMode:this._defaultChildrenIncluded??this._supportsChildren}set childrenIncluded(e){if(u("value",e).satisfies((e=>"boolean"==typeof e),"LayerListSettings must be set to boolean values"),!this._supportsChildren&&e)throw new i("Cannot set 'childrenIncluded' to true on a layer that does not support sublayers.");super.childrenIncluded=e,this._setListMode()}get expanded(){return super.expanded}set expanded(e){if(u("value",e).satisfies((e=>"boolean"==typeof e),"LayerListSettings must be set to boolean values"),!this._supportsChildren&&e)throw new i("Cannot set 'expanded' to true on a layer that does not support sublayers.");super.expanded=e}onLayerExtensionInitialized(){this._setListMode(),a(this._extension,this._listModePath,(()=>{super.childrenIncluded=void 0,super.included=void 0}),{sync:!0})}_getSerializableProperties(){return{...super._getSerializableProperties(),included:{serializeModes:["initial"],isDefault:e=>!!e},childrenIncluded:{serializeModes:["initial"],isDefault:e=>e===this._childrenIncludedSerializationDefault()}}}_childrenIncludedSerializationDefault(){return this._esriLayer?"show"===this._initialEsriLayerListMode:this._defaultChildrenIncluded??this._supportsChildren}_setListMode(){const e=this._esriLayer;e&&(void 0===this._initialEsriLayerListMode&&(this._initialEsriLayerListMode=e.listMode),!this.childrenIncluded&&this._extension._layerSupportsHideChildren&&this.included?e.listMode="hide-children":this.childrenIncluded||this.included?e.listMode="show":e.listMode="hide")}}export function fromLayerListMode(e){const i={};return"hide"===e?i.included=!1:"show"===e?i.included=!0:"hide-children"===e&&(i.childrenIncluded=!1),i}