/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import{__decorate as e}from"tslib";import{isSome as r}from"../../../../core/arrayUtils.js";import{destroyMaybe as t}from"../../../../core/maybe.js";import{property as a,subclass as o}from"../../../../core/accessorSupport/decorators.js";import s from"../../../Widget.js";import i from"./MeasuredContentGroup.js";import l from"./OverflowGroup.js";import n from"./ResponsiveToolbarManager.js";import{SplitButton as d}from"./SplitButton.js";import{loadCalciteComponents as c}from"../../../support/componentsUtils.js";import{tsx as p}from"../../../support/widget.js";const u="esri-responsive-toolbar",m={rulerBase:`${u}__ruler`,rulerBarHorizontal:`${u}__ruler--bar`,rulerBarVertical:`${u}__ruler--bar--vertical`,rulerPadVertical:`${u}__ruler--pad--vertical`,rulerPadHorizontal:`${u}__ruler--pad--horizontal`,bar:`${u}__bar`,barHorizontal:`${u}__bar--horizontal`,barVertical:`${u}__bar--vertical`,pad:`${u}__pad`,padVertical:`${u}__pad--vertical`,padHorizontal:`${u}__pad--horizontal`};let h=class extends s{constructor(e){super(e),this.scale="m",this.barStyle="floating",this._measurementManager=new n,this._managedWidgets=new Map}loadDependencies(){return c({"action-bar":()=>import("@esri/calcite-components/dist/components/calcite-action-bar")})}destroy(){this._measurementManager=t(this._measurementManager),this._managedWidgets.forEach(e=>e.destroy()),this._managedWidgets.clear()}set layout(e){const r=this._get("layout");this._set("layout",e),this._measurementManager&&(this._measurementManager.layout=e),r!==e&&this.scheduleRender()}get _barClasses(){const e="docked"===this.barStyle,r="vertical"===this.layout;return{[m.barHorizontal]:e&&!r,[m.barVertical]:e&&r,[m.bar]:e,[m.padHorizontal]:!e&&!r,[m.padVertical]:!e&&r,[m.pad]:!e}}render(){const{layout:e,scale:r,barStyle:t}=this,a={layout:e,scale:r,expandDisabled:!0,key:"measured-toolbar"},o="docked"===t?"vertical"===e?m.rulerBarVertical:m.rulerBarHorizontal:"horizontal"===e?m.rulerPadHorizontal:m.rulerPadVertical,s=this._renderChildren();return s.length?p("div",{key:"toolbar-wrapper"},p("div",{afterCreate:e=>{this._measurementManager?.connect(e)},class:this.classes(m.rulerBase,o),key:"ruler-element"}),p("calcite-action-bar",{...a,classes:this._barClasses,floating:"docked"!==t,overflowActionsDisabled:!0},s)):null}_renderChildren(){if(!this.children)return[];const e=new Set,t=[];for(const r of this.children){if(!r.properties?.key||!("group-kind"in r.properties)||!r.children?.length)continue;const a=r.properties,o=a.key;e.add(o);const s="docked"===this.barStyle?a.slot??void 0:void 0,n=a.priority??0,c=a["group-kind"]??"overflow-group",p=a["allow-collapse"]??!0,u=this._managedWidgets.get(o);if(u)u.children=r.children,u.priority=n,"allowCollapse"in u&&(u.allowCollapse=p),u.slot=s,u.layout=this.layout,u.scale=this.scale,u.measurementManager=this._measurementManager,t.push(u);else{const e={scale:this.scale,priority:n,measurementManager:this._measurementManager,children:r.children,slot:s,layout:this.layout};switch(c){case"split-button":{const r=new d({...e,allowCollapse:p});this._managedWidgets.set(o,r),t.push(r);break}case"overflow-group":{const r=new l({...e,allowCollapse:p});this._managedWidgets.set(o,r),t.push(r);break}case"measured-content":{const r=new i({...e});this._managedWidgets.set(o,r),t.push(r);break}}}}for(const[r]of this._managedWidgets.entries())e.has(r)||(this._managedWidgets.get(r)?.destroy(),this._managedWidgets.delete(r));return this._measurementManager?.allocate(),t.map(e=>e.render()).filter(r)}};e([a()],h.prototype,"scale",void 0),e([a({value:"horizontal"})],h.prototype,"layout",null),e([a()],h.prototype,"barStyle",void 0),e([a()],h.prototype,"_measurementManager",void 0),e([a()],h.prototype,"_managedWidgets",void 0),e([a()],h.prototype,"_barClasses",null),h=e([o("esri.widgets.Sketch.support.ResponsiveToolbar.ResponsiveToolbar")],h);export{h as default};
