import e from"@arcgis/core/layers/support/SubtypeSublayer";import{isSubtypeSublayer as p}from"../utilities/_layers.js";import{checkArg as r}from"../utilities/checkArg.js";import{LayerDefinition as s}from"./LayerDefinition.js";import{PopupInfo as a}from"./PopupInfo.js";import{ERR_LAYER_TYPE_MISMATCH as i,applyLayerBaseToEsriApiLayer as o,fromEsriApiLayerToLayerBase as t}from"./_layerHelper.js";"layer"in e.prototype||Object.defineProperty(e.prototype,"layer",{get:function(){return this.parent},set:function(e){this.parent=e}});export var SubtypeSublayer;!function(e){async function l(e,t){r("sublayerJson",e).isNotMissing(),r("sublayerJson.layerType",e.layerType).satisfies((e=>!e||"ArcGISFeatureLayer"===e),i),r("sublayer",t).isNotMissing().satisfies((e=>p(e)),i),o(e,t),e.hasOwnProperty("popupInfo")&&null!=e.popupInfo&&(t.popupTemplate=a.toEsriApiPopupTemplate(e.popupInfo)),e.hasOwnProperty("disablePopup")&&(t.popupEnabled=!e.disablePopup),e.hasOwnProperty("showLabels")&&null!=e.showLabels&&(t.labelsVisible=e.showLabels),e.hasOwnProperty("subtypeCode")&&null!=e.subtypeCode&&(t.subtypeCode=+e.subtypeCode),e.hasOwnProperty("layerDefinition")&&null!=e.layerDefinition&&await s.applyToEsriApiLayer(e.layerDefinition,t)}e.esriSubtypeSublayerDefaults={labelsVisible:!0,legendEnabled:!0,popupEnabled:!0,visible:!0,minScale:0,maxScale:0},e.toEsriApiLayer=async function(e){r("sublayerJson",e).isNotMissing(),r("sublayerJson.layerType",e.layerType).satisfies((e=>!e||"ArcGISFeatureLayer"===e),i);const p=new((await import("@arcgis/core/layers/support/SubtypeSublayer")).default);return await l(e,p),p},e.applyToEsriApiLayer=l,e.fromEsriApiSubtypeSublayer=function(o){r("sublayer",o).isNotMissing().satisfies((e=>p(e)),i);const l={...t(o,e.esriSubtypeSublayerDefaults),layerType:"ArcGISFeatureLayer"};return o.popupEnabled!==e.esriSubtypeSublayerDefaults.popupEnabled&&(l.disablePopup=!o.popupEnabled),o.popupTemplate&&(l.popupInfo=a.fromEsriApiPopupTemplate(o.popupTemplate)),o.labelsVisible!==e.esriSubtypeSublayerDefaults.labelsVisible&&(l.showLabels=o.labelsVisible),o.hasOwnProperty("subtypeCode")&&(l.subtypeCode=o.subtypeCode),l.layerDefinition=s.fromEsriApiLayer(o),l}}(SubtypeSublayer||(SubtypeSublayer={}));