"use strict";var DesignSystem;(globalThis.webpackChunkDesignSystem=globalThis.webpackChunkDesignSystem||[]).push([[709],{6492:(e,a,t)=>{var r=t(7142),s=t(2485),n=t.n(s),l=t(5901);const d=e=>{const a=n()("ds-c-tabs__panel",e.className);return(0,l.Y)("div",{"aria-labelledby":e.tabId,"aria-hidden":!e.selected,className:a,id:e.id,role:"tabpanel",children:e.children})};d.displayName="TabPanel",d.defaultProps={selected:!1};const i=d;var c=t(7402);const o=(0,c.forwardRef)(((e,a)=>{const t=e.href||`#${e.panelId}`,r={role:"tab",className:n()("ds-c-tabs__item",e.className),id:e.id,ref:a};return e.disabled?(0,l.Y)("span",{"aria-disabled":"true",...r,children:e.children}):(0,l.Y)("a",{"aria-selected":e.selected||!1,"aria-controls":e.panelId,href:t,onClick:a=>{const{onClick:r,panelId:s,id:n}=e;r&&r(a,s,n,t)},onKeyDown:a=>{const{onKeyDown:r,panelId:s,id:n}=e;r&&r(a,s,n,t)},...r,children:e.children})}));o.displayName="Tab";const p=o;var b=t(8156),h=t.n(b);const u=e=>{const a=h()(e,"type.displayName")||h()(e,"type.name");return e&&(e.type===i||"TabPanel"===a)},f=e=>e.props.tabId??`${e.props.id}__tab`,m=e=>{const a=e.defaultSelectedId||(e=>{let a;return c.Children.forEach(e.children,(function(e){u(e)&&!a&&(a=e.props.id)})),a})(e),[t,r]=(0,c.useState)(a),s=void 0!==e.selectedId?e.selectedId:t,d=e.ariaLabel?{"aria-label":e.ariaLabel}:{},i=n()("ds-c-tabs",e.tablistClassName),o=(0,c.useRef)({}),b=()=>c.Children.toArray(e.children).filter(u),h=a=>{const{onChange:t}=e;var n;t&&t(a,s),o.current[a].focus(),n=o.current[a].href,window.history&&window.history.replaceState({},document.title,n),r(a)},m=(e,a)=>{e.preventDefault(),h(a)},v=(e,a)=>{const t=b().filter((e=>c.default.isValidElement(e))),r=t.findIndex((e=>e.props.id===a));let s;const n=e=>e.props.disabled;switch(e.key){case"ArrowLeft":{e.preventDefault();let a=0===r?t.length-1:r-1;for(;n(t[a]);)a=0===a?t.length-1:a-1;s=t[a].props.id,h(s);break}case"ArrowRight":{e.preventDefault();let a=r===t.length-1?0:r+1;for(;n(t[a]);)a=a===t.length-1?0:a+1;s=t[a].props.id,h(s);break}}};return(0,l.FD)("div",{children:[(0,l.Y)("div",{className:i,role:"tablist",...d,children:b().map((e=>(0,l.Y)(p,{className:e.props.tabClassName,href:e.props.tabHref,disabled:e.props.disabled,id:f(e),onClick:m,onKeyDown:v,panelId:e.props.id,ref:a=>{o.current[e.props.id]=a},selected:s===e.props.id,children:e.props.tab},e.key)))}),c.Children.map(e.children,(e=>u(e)&&(0,c.isValidElement)(e)?(0,c.cloneElement)(e,{selected:s===e.props.id,tab:void 0,tabHref:void 0,tabId:f(e)}):e))]})};var v=t(5590);const y=e=>{let{tabsAriaLabel:a,...t}=e;return(0,l.Y)(m,{...t,ariaLabel:a,children:(r=t.children,r.map((e=>{const a=e.props;if(!a.id||!a.children||!a.tab)return console.warn("Each child passed to `ds-tabs` must include `id` and `children` attributes for `TabPanel` functionality."),null;const{id:t,children:r,"class-name":s,selected:n,disabled:l,tab:d,"tab-class-name":o,"tab-href":p,"tab-id":b,...h}=a,u={id:t,className:s,selected:(0,v.$Q)(n),disabled:(0,v.$Q)(l),tab:(0,v.Rk)(d),tabClassName:o,tabHref:p,tabId:b};return(0,c.createElement)(i,{...u,...h},r)})))});var r};(0,r.E)("ds-tabs",(()=>y),{attributes:["default-selected-id","selected-id","tablist-class-name","tabs-aria-label"],events:[["onChange",(e,a)=>({detail:{selectedId:e,prevSelectedId:a}})]]})},5590:(e,a,t)=>{function r(e){return void 0!==e&&"false"!==e}function s(e){return e?new Date(e):void 0}function n(e){if(void 0!==e)return parseInt(e)}function l(e){return(e=>{try{JSON.parse(e)}catch(e){return!1}return!0})(e)?JSON.parse(e):e}t.d(a,{$Q:()=>r,Rk:()=>l,Tt:()=>n,tv:()=>s})},5901:(e,a,t)=>{t.d(a,{FD:()=>r.FD,FK:()=>r.FK,Y:()=>r.Y}),t(7402);var r=t(201)}},e=>{var a=e(e.s=6492);DesignSystem=a}]);
//# sourceMappingURL=ds-tabs.js.map