"use strict";const o=require("vue"),f=require("./useButtonGroupKeyboardNav.js"),p=require("./Icon.js"),B=require("./CdxToggleButton.cjs"),y=require("./_plugin-vue_export-helper.js"),V=o.defineComponent({name:"CdxToggleButtonGroup",components:{CdxIcon:p.CdxIcon,CdxToggleButton:B},props:{buttons:{type:Array,required:!0,validator:e=>Array.isArray(e)&&e.length>=1},modelValue:{type:[String,Number,null,Array],required:!0},disabled:{type:Boolean,default:!1}},emits:["update:modelValue"],setup(e,{emit:r}){const{rootElement:d,assignTemplateRef:s,onFocus:i,onBlur:c,onKeydown:t}=f.useButtonGroupKeyboardNav(o.toRef(e,"buttons"));function u(n){return Array.isArray(e.modelValue)?e.modelValue.indexOf(n.value)!==-1:e.modelValue!==null?e.modelValue===n.value:!1}function l(n,a){if(Array.isArray(e.modelValue)){const m=e.modelValue.indexOf(n.value)!==-1;a&&!m?r("update:modelValue",e.modelValue.concat(n.value)):!a&&m&&r("update:modelValue",e.modelValue.filter(g=>g!==n.value))}else a&&e.modelValue!==n.value&&r("update:modelValue",n.value)}return{rootElement:d,assignTemplateRef:s,onFocus:i,onBlur:c,onKeydown:t,getButtonLabel:f.getButtonLabel,isSelected:u,onUpdate:l}}}),v={ref:"rootElement",class:"cdx-toggle-button-group"};function k(e,r,d,s,i,c){const t=o.resolveComponent("cdx-icon"),u=o.resolveComponent("cdx-toggle-button");return o.openBlock(),o.createElementBlock("div",v,[(o.openBlock(!0),o.createElementBlock(o.Fragment,null,o.renderList(e.buttons,(l,n)=>(o.openBlock(),o.createBlock(u,{key:l.value,ref_for:!0,ref:a=>e.assignTemplateRef(a,n),"model-value":e.isSelected(l),disabled:l.disabled||e.disabled,"aria-label":l.ariaLabel,"onUpdate:modelValue":a=>e.onUpdate(l,a),onFocus:a=>e.onFocus(n),onBlur:e.onBlur,onKeydown:e.onKeydown},{default:o.withCtx(()=>[o.renderSlot(e.$slots,"default",{button:l,selected:e.isSelected(l)},()=>[l.icon?(o.openBlock(),o.createBlock(t,{key:0,icon:l.icon},null,8,["icon"])):o.createCommentVNode("v-if",!0),o.createTextVNode(" "+o.toDisplayString(e.getButtonLabel(l)),1)])]),_:2},1032,["model-value","disabled","aria-label","onUpdate:modelValue","onFocus","onBlur","onKeydown"]))),128))],512)}const C=y._export_sfc(V,[["render",k]]);module.exports=C;
