/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import{__decorate as t}from"tslib";import{property as o,subclass as e}from"../../../../core/accessorSupport/decorators.js";import i from"../../../Widget.js";import{WellKnownSizes as n,Icons as r}from"./responsiveToolbarUtils.js";import{ToolbarGroupBase as s}from"./ToolbarGroupBase.js";import{loadCalciteComponents as l}from"../../../support/componentsUtils.js";import{tsx as a,tsxFragment as c,messageBundle as p}from"../../../support/widget.js";const m={splitButtonBase:`${"esri-split-button"}--split-part`};let u=class extends(s(i)){constructor(t){super(t),this.allowCollapse=!0,this.messagesCommon=null}loadDependencies(){return l({action:()=>import("@esri/calcite-components/dist/components/calcite-action"),"action-group":()=>import("@esri/calcite-components/dist/components/calcite-action-group"),"action-menu":()=>import("@esri/calcite-components/dist/components/calcite-action-menu")})}static{this.vnodeSelector="calcite-action-group"}get minimumLength(){const t=this.actionChildren;return t.length?1===t.length?n.action[this.scale]+n.groupSeparator:this.allowCollapse?n.action[this.scale]+n.splitButtonPart[this.layout][this.scale]+n.groupSeparator:n.action[this.scale]*t.length+n.groupSeparator:0}get lengthOptions(){const{actionChildren:t,minimumLength:o,layout:e,scale:i,priority:r,allowCollapse:s}=this;if(t.length<2||r<0||!s)return[o];const l=n.groupSeparator+n.action[i]*t.length;return[n.groupSeparator+n.action[i]+n.splitButtonPart[e][i],l]}render(){if(!this.actionChildren.length)return a(c,null,void 0);const{actionChildren:t,minimumLength:o,budgetedLength:e,layout:i,slot:n,allowCollapse:r}=this,s=!r||t.length<2||e>o;return a("calcite-action-group",{key:"split-button-group",layout:i,onclick:t=>this._handleClick(t.target),slot:n},s?this._renderUnSplit():this._renderSplit())}_renderSplit(){const{activeChildElement:t,layout:o,actionChildren:e,scale:i,messagesCommon:n}=this,s=t??e.at(0);if(!s)return;const l=e.filter(t=>t!==s);return[this._renderManagedAction(s),a("calcite-action-menu",{key:"split-button-dropdown",label:n.more,overlayPositioning:"fixed",placement:"horizontal"===o?"bottom-end":"right-end"},a("calcite-action",{class:`${m.splitButtonBase}--${o}--${this.scale}`,compact:"horizontal"===o,icon:r.splitButton[o],key:"split-button-dropdown-trigger",scale:i,slot:"trigger",text:n.more}),l?.map(t=>this._renderManagedAction(t)))]}_renderUnSplit(){return this.actionChildren.map(t=>this._renderManagedAction(t))}_renderManagedAction(t){return a("calcite-action",{...t?.properties,"data-action-key":t?.properties?.key,text:t?.properties?.text??""})}};t([o()],u.prototype,"minimumLength",null),t([o()],u.prototype,"allowCollapse",void 0),t([o()],u.prototype,"lengthOptions",null),t([o(),p("esri/t9n/common")],u.prototype,"messagesCommon",void 0),u=t([e("esri.widgets.Sketch.support.ResponsiveToolbar.SplitButton")],u);export{u as SplitButton};
