text: import{r as t,e,h as i,H as s,g as a}from"./p-8dbe4215.js";import{h as r,c as n,d as o}from"./p-ce719b56.js";import{p as l,d as h,a as d}from"./p-8e9cb243.js";import{h as c}from"./p-09b2e663.js";const p=(t,e)=>{if(1===t.nodeType)return(t.tagName===e.toUpperCase()?[t]:Array.from(t.querySelectorAll(e))).find((e=>e.value===t.value))},b=class{constructor(i){t(this,i),this.bkkrChange=e(this,"bkkrChange",7),this.bkkrCancel=e(this,"bkkrCancel",7),this.bkkrFocus=e(this,"bkkrFocus",7),this.bkkrBlur=e(this,"bkkrBlur",7),this.bkkrStyle=e(this,"bkkrStyle",7),this.didInit=!1,this.inputId="bkkr-sel-"+y++,this.hasFocus=!1,this.isExpanded=!1,this.cancelText="Cancel",this.okText="OK",this.multiple=!1,this.name=this.inputId,this.disabled=!1,this.interface="drawer",this.search=!0,this.interfaceOptions={},this.onClick=t=>{this.setFocus(),this.open(t)},this.onFocus=()=>{this.bkkrFocus.emit()},this.onBlur=()=>{this.bkkrBlur.emit()}}disabledChanged(){this.emitStyle()}valueChanged(){this.emitStyle(),this.didInit&&this.bkkrChange.emit({value:this.value})}componentDidLoad(){this.didInit=!0}connectedCallback(){this.updateOverlayOptions(),this.emitStyle(),this.mutationO=((t,e,i)=>{if("undefined"==typeof MutationObserver)return;const s=new MutationObserver((t=>{i(((t,e)=>{let i;t.forEach((t=>{for(let s=0;s<t.addedNodes.length;s++)i=p(t.addedNodes[s],e)||i}))})(t,"ion-select-option"))}));return s.observe(t,{childList:!0,subtree:!0}),s})(this.el,0,(async()=>{this.updateOverlayOptions()}))}disconnectedCallback(){this.mutationO&&(this.mutationO.disconnect(),this.mutationO=void 0)}async open(t){if(this.disabled||this.isExpanded)return;const e=this.overlay=await this.createOverlay(t);return this.isExpanded=!0,this.hasFocus=!0,this.emitStyle(),e.onDidDismiss().then((()=>{this.overlay=void 0,this.isExpanded=!1,this.hasFocus=!1,this.emitStyle(),this.setFocus()})),await e.present(),e}updateOverlayOptions(){const t=this.overlay;if(!t)return;const e=this.childOpts,i=this.value;switch(this.interface){case"popover":const s=t.querySelector("bkkr-select-popover");s&&(s.options=this.createChoicesOptions(e,i));break;case"drawer":const a=t.querySelector("bkkr-select-drawer");a&&(a.options=this.createChoicesOptions(e,i));break;case"alert":t.inputs=this.createAlertInputs(e,this.multiple?"checkbox":"radio",i)}}createOverlay(t){let e=this.interface;return"popover"!==e||t||(console.warn('Select interface cannot be a "popover" without passing an event. Using the "alert" interface instead.'),e="alert"),"drawer"!==e||t||(console.warn('Select interface cannot be a "drawer" without passing an event. Using the "alert" interface instead.'),e="alert"),"alert"!==e&&this.multiple&&(console.warn('Multiple option is only supported in "drawer".'),e="alert"),"popover"===e?this.openPopover(t):"alert"===e?this.openAlert():this.openDrawer(t)}async openPopover(t){const e=this.interfaceOptions,i=this.value,s=Object.assign(Object.assign({},e),{component:"bkkr-select-choices",cssClass:["select-popover",e.cssClass],event:t,componentProps:{header:e.header,subHeader:e.subHeader,search:this.search,value:i,options:this.createChoicesOptions(this.childOpts,i)}});return l.create(s)}async openDrawer(t){const e=this.interfaceOptions,i=this.value,s=Object.assign(Object.assign({},e),{component:"bkkr-select-choices",cssClass:["select-drawer",e.cssClass],event:t,componentProps:{header:e.header,subHeader:e.subHeader,search:this.search,multiple:this.multiple,interfaceOptions:this.interfaceOptions,value:i,options:this.createChoicesOptions(this.childOpts,i)}});return h.create(s)}createChoicesOptions(t,e){return t.map((t=>{const i=g(t),s=Array.from(t.classList).filter((t=>"hydrated"!==t)).join(" ");return{label:t.textContent||"",cssClass:`${x} ${s}`,value:i,selected:u(i,e,this.compareWith),disabled:t.disabled,handler:()=>{this.value=i,this.multiple||this.close()}}}))}async openAlert(){const t=this.getLabel(),e=t?t.textContent:null,i=this.interfaceOptions,s=this.multiple?"checkbox":"radio",a=Object.assign(Object.assign({},i),{header:i.header?i.header:e,inputs:this.createAlertInputs(this.childOpts,s,this.value),buttons:[{text:this.cancelText,role:"cancel",handler:()=>{this.bkkrCancel.emit()}},{text:this.okText,handler:t=>{this.value=t}}],cssClass:["select-alert",i.cssClass,this.multiple?"multiple-select-alert":"single-select-alert"]});return d.create(a)}createAlertInputs(t,e,i){return t.map((t=>{const s=g(t),a=Array.from(t.classList).filter((t=>"hydrated"!==t)).join(" ");return{type:e,cssClass:`${x} ${a}`,label:t.textContent||"",value:s,checked:u(s,i,this.compareWith),disabled:t.disabled}}))}close(){return this.overlay?(this.hasFocus=!1,this.emitStyle(),this.overlay.dismiss()):Promise.resolve(!1)}getLabel(){return r(this.el)}hasValue(){return""!==this.getText()}get childOpts(){return Array.from(this.el.querySelectorAll("bkkr-select-option"))}getText(){const t=this.selectedText;return null!=t&&""!==t?t:m(this.childOpts,this.value,this.compareWith)}setFocus(){this.focusEl&&this.focusEl.focus()}emitStyle(){this.bkkrStyle.emit({interactive:!0,select:!0,"has-placeholder":null!=this.placeholder,"has-value":this.hasValue(),"has-focus":this.hasFocus,"interactive-disabled":this.disabled,"select-disabled":this.disabled})}render(){const{disabled:t,el:e,inputId:a,isExpanded:r,name:l,placeholder:h,value:d}=this,{labelText:p,labelId:b}=n(e,a);o(!0,e,l,v(d),t);let u=!1,g=this.getText();""===g&&null!=h&&(g=h,u=!0);const f={"select-text":!0,"select-placeholder":u},m=u?"placeholder":"text",k=void 0!==p?""!==g?`${g}, ${p}`:p:g;return i(s,{onClick:this.onClick,role:"button","aria-haspopup":"listbox","aria-disabled":t?"true":null,"aria-label":k,class:{"in-item":c("bkkr-item",e),"select-disabled":t,"has-value":this.hasValue(),"has-focus":this.hasFocus}},i("div",{"aria-hidden":"true",class:f,part:m},g),i("div",{class:"select-icon",role:"presentation",part:"icon"},i("div",{class:"select-icon-inner"})),i("label",{id:b},k),i("button",{type:"button",disabled:t,id:a,"aria-labelledby":b,"aria-haspopup":"listbox","aria-expanded":""+r,onFocus:this.onFocus,onBlur:this.onBlur,ref:t=>this.focusEl=t}))}get el(){return a(this)}static get watchers(){return{disabled:["disabledChanged"],placeholder:["disabledChanged"],value:["valueChanged"]}}},u=(t,e,i)=>void 0!==t&&(Array.isArray(t)?t.some((t=>f(t,e,i))):f(t,e,i)),g=t=>{const e=t.value;return void 0===e?t.textContent||"":e},v=t=>{if(null!=t)return Array.isArray(t)?t.join(","):t.toString()},f=(t,e,i)=>"function"==typeof i?i(t,e):"string"==typeof i?t[i]===e[i]:Array.isArray(e)?e.includes(t):t===e,m=(t,e,i)=>void 0===e?"":Array.isArray(e)?e.map((e=>k(t,e,i))).filter((t=>null!==t)).join(", "):k(t,e,i)||"",k=(t,e,i)=>{const s=t.find((t=>f(g(t),e,i)));return s?s.textContent:null};let y=0;const x="select-interface-option";b.style=":host{--placeholder-color:initial;--padding-top:10px;--padding-end:var(--bkkr-spacer, 16px)/2;--padding-bottom:10px;--padding-start:var(--bkkr-spacer, 16px);padding-left:var(--padding-start);padding-right:var(--padding-end);padding-top:var(--padding-top);padding-bottom:var(--padding-bottom);display:-ms-flexbox;display:flex;position:relative;-ms-flex-align:center;align-items:center;font-family:var(--default-font-sans-serif);overflow:hidden;z-index:2}@supports ((-webkit-margin-start: 0) or (margin-inline-start: 0)) or (-webkit-margin-start: 0){:host{padding-left:unset;padding-right:unset;-webkit-padding-start:var(--padding-start);padding-inline-start:var(--padding-start);-webkit-padding-end:var(--padding-end);padding-inline-end:var(--padding-end)}}:host(.in-item){position:static;max-width:45%}:host(.select-disabled){opacity:0.4;pointer-events:none}:host(.state-focused) button{border:2px solid #5e9ed6}.select-placeholder{-webkit-transition:var(--placeholder-transition, none);transition:var(--placeholder-transition, none);-webkit-transition-delay:var(--placeholder-transition-delay, none);transition-delay:var(--placeholder-transition-delay, none);color:var(--placeholder-color);opacity:var(--placeholder-opacity, 0.5)}label{top:0;left:0;margin-left:0;margin-right:0;margin-top:0;margin-bottom:0;position:absolute;width:100%;height:100%;border:0;outline:none;background:transparent;cursor:pointer;-webkit-appearance:none;-moz-appearance:none;appearance:none;display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center;opacity:0}label::-moz-focus-inner{border:0}button{position:absolute;top:0;right:0;bottom:0;left:0;width:100%;height:100%;margin:0;padding:0;border:0;outline:0;opacity:0;overflow:hidden;clip:rect(0 0 0 0);-webkit-appearance:none;-moz-appearance:none;appearance:none}.select-icon{position:relative;width:12px;height:18px;opacity:0.33}.select-text{-ms-flex:1;flex:1;min-width:16px;font-size:inherit;text-overflow:ellipsis;white-space:nowrap;overflow:hidden}.select-icon-inner{top:50%;left:0;margin-top:-2px;position:absolute;width:0;height:0;border-top:5px solid;border-right:5px solid transparent;border-left:5px solid transparent;color:currentColor;pointer-events:none}";export{b as bkkr_select}