import{Tooltip}from"./Tooltip.js";import{HBox}from"./Widget.js";export class SegmentedButton extends HBox{constructor(){super(!0),this._buttons=new Map,this._selected=null,this.registerRequiredCSS("ui/segmentedButton.css",{enableLegacyPatching:!0}),this.contentElement.classList.add("segmented-button")}addSegment(t,e,s){const n=this.contentElement.createChild("button","segmented-button-segment");n.textContent=t,s&&Tooltip.install(n,s),this._buttons.set(e,n),n.addEventListener("click",(()=>this.select(e)))}select(t){if(this._selected!==t){this._selected=t;for(const[t,e]of this._buttons)e.classList.toggle("segmented-button-segment-selected",t===this._selected)}}selected(){return this._selected}}