Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}}),require(`../../chunk-Bmb41Sf3.cjs`);const e=require(`../../_plugin-vue_export-helper-D8jCH6HB.cjs`),t=require(`./tabs-constants.cjs`);let n=require(`vue`);var r={compatConfig:{MODE:3},name:`DtTabGroup`,provide(){return{groupContext:this.provideObj,setFocus:this.setFocus}},props:{label:{type:String,default:``},selected:{type:String,default:``},disabled:{type:Boolean,default:!1},inverted:{type:Boolean,default:!1},borderless:{type:Boolean,default:!1},size:{type:String,default:`default`,validate(e){return t.TAB_LIST_SIZES.includes(e)}},tabListClass:{type:[String,Array,Object],default:``},tabListChildProps:{type:Object,default:()=>({})}},emits:[`change`,`before-change`],data(){return{provideObj:{selected:``,disabled:!1},focusId:null,tabs:[],TAB_LIST_SIZE_MODIFIERS:t.TAB_LIST_SIZE_MODIFIERS,TAB_LIST_KIND_MODIFIERS:t.TAB_LIST_KIND_MODIFIERS,TAB_LIST_IMPORTANCE_MODIFIERS:t.TAB_LIST_IMPORTANCE_MODIFIERS}},watch:{disabled:{immediate:!0,handler(){this.provideObj.disabled=this.disabled}},selected:{immediate:!0,handler(){this.provideObj.selected=this.selected}}},mounted(){this.updateSelected()},updated(){this.updateSelected()},methods:{updateSelected(){this.provideObj.selected||(this.provideObj.selected=this.selected),this.tabs=this.getTabChildren()},setFocus(e){this.focusId=e},getTabChildren(){return Array.from(this.$refs.tabs.querySelectorAll(`.d-tab`)).map(e=>({context:e,panelId:e.getAttribute(`aria-controls`)?.replace(`dt-panel-`,``),tabId:e.getAttribute(`id`)?.replace(`dt-tab-`,``),isSelected:e.getAttribute(`aria-selected`)===`true`}))},onChange(){this.$emit(`change`,{...this.provideObj})},tabLeft(){let e=this.getFocusedTabIndex();if(e===-1)return;let t=e-1<0?this.tabs.length-1:e-1;this.selectFocusOnTab(t)},tabRight(){let e=this.getFocusedTabIndex();if(e===-1)return;let t=e+1>this.tabs.length-1?0:e+1;this.selectFocusOnTab(t)},selectFocusOnTab(e){let{context:t}=this.tabs[e];t.focus()},selectTab(e){if(this.isSameTabClicked()||(this.$emit(`before-change`,e),e.defaultPrevented))return;let t=this.getFocusedTabIndex();this.selectTabByIndex(t),this.onChange()},selectTabByIndex(e){let{context:t,panelId:n}=this.tabs[e];this.provideObj.selected=n,t.focus()},getFocusedTabIndex(){let e=this.tabs.findIndex(e=>this.focusId?e.tabId===`${this.focusId}`:e.isSelected);return e===-1?0:e},onHomeButton(){this.tabs.length!==0&&this.tabs[0]?.context?.focus()},onEndButton(){this.tabs.length!==0&&this.tabs[this.tabs.length-1]?.context?.focus()},isSameTabClicked(){let e=this.tabs[this.getFocusedTabIndex()];return this.provideObj.selected===e.panelId}}},i={"data-qa":`dt-tab-group`},a=[`aria-label`];function o(e,t,r,o,s,c){return(0,n.openBlock)(),(0,n.createElementBlock)(`div`,i,[(0,n.createElementVNode)(`div`,(0,n.mergeProps)({ref:`tabs`,class:[`d-tablist`,s.TAB_LIST_SIZE_MODIFIERS[r.size],{[s.TAB_LIST_KIND_MODIFIERS.inverted]:r.inverted,[s.TAB_LIST_IMPORTANCE_MODIFIERS.borderless]:r.borderless},r.tabListClass]},r.tabListChildProps,{role:`tablist`,"aria-label":r.label,onKeyup:[t[0]||(t[0]=(0,n.withKeys)((...e)=>c.tabLeft&&c.tabLeft(...e),[`left`])),t[1]||(t[1]=(0,n.withKeys)((...e)=>c.tabRight&&c.tabRight(...e),[`right`])),t[2]||(t[2]=(0,n.withKeys)((...e)=>c.selectTab&&c.selectTab(...e),[`enter`])),t[3]||(t[3]=(0,n.withKeys)((...e)=>c.selectTab&&c.selectTab(...e),[`space`]))],onClick:t[4]||(t[4]=(...e)=>c.selectTab&&c.selectTab(...e)),onKeydown:[t[5]||(t[5]=(0,n.withKeys)((...e)=>c.onHomeButton&&c.onHomeButton(...e),[`home`])),t[6]||(t[6]=(0,n.withKeys)((...e)=>c.onEndButton&&c.onEndButton(...e),[`end`]))]}),[(0,n.renderSlot)(e.$slots,`tabs`)],16,a),(0,n.renderSlot)(e.$slots,`default`)])}var s=e.t(r,[[`render`,o]]);exports.default=s;
//# sourceMappingURL=tab-group.cjs.map