import{r as p,v as f,d as h,a as c,h as l,e as b,s as m,a6 as g,a0 as _,a1 as v,ac as y,g as k,w,m as T}from"./index-DscFWUNz.js";import{v as x}from"./align-CyK0wp7d-DT9btF96.js";import{v as C}from"./label-CdtNxOKu-DuSxxbJz.js";import{t as P}from"./i18n-CdSCDnmA-Bln0Fy0B.js";import{K as r}from"./keyboard-D6PoWr38-Bn_Qh8Bq.js";import{c as S}from"./clsx-eK3rPvPS-BT_IL7Fz.js";/*!
 * KoliBri - The accessible HTML-Standard
 */const u=["select-automatic","select-manual"],A=(e,t)=>{w(e,"_behavior",n=>typeof n=="string"&&u.includes(n),new Set([`KoliBriTabBehavior {${u.join(", ")}`]),t)},B=(e,t)=>{T(e,"_hasCreateButton",t)},z=`/* forward the rem function */
/*
* This file defines the layer order for all CSS layers used in KoliBri.
* The order is important as it determines the cascade priority.
*
* Layer order (lowest to highest priority):
* 1. kol-a11y - Accessibility defaults and requirements
* 2. kol-global - Global component styles and resets
* 3. kol-component - Component-specific styles
* 4. kol-theme-global - Theme-specific global styles
* 5. kol-theme-component - Theme-specific component styles
*/
@layer kol-a11y, kol-global, kol-component, kol-theme-global, kol-theme-component;
/*
 * This file contains all rules for accessibility.
 */
@layer kol-a11y {
  :host {
    /*
     * Minimum size of interactive elements.
     */
    --a11y-min-size: calc(44 * 1rem / var(--kolibri-root-font-size, 16));
    /*
     * No element should be used without verifying the contrast ratio of its background and font colors.
     * By initially setting the background color to white and the font color to black,
     * the contrast ratio is ensured and explicit adjustment is forced.
     */
    color: black;
    background-color: white;
    /*
     * Verdana is an accessible font that can be used without requiring additional loading time.
     */
    font-family: Verdana;
    /*
     * Letter spacing is required for all texts.
     */
    letter-spacing: inherit;
    /*
     * Word spacing is required for all texts.
     */
    word-spacing: inherit;
  }
  * {
    /*
     * This rule enables the word dividing for all texts. That is important for high zoom levels.
     */
    hyphens: auto;
    /*
     * This rule enables the word dividing for all texts. That is important for high zoom levels.
     */
    word-break: break-word;
  }
  /*
   * All interactive elements should have a minimum size of to-rem(44).
   */
  /* input:not([type='checkbox'], [type='radio'], [type='range']), */
  /* option, */
  /* select, */
  /* textarea, */
  button,
  .kol-input .input {
    min-width: var(--a11y-min-size);
    min-height: var(--a11y-min-size);
  }
  /*
   * Some interactive elements should not inherit the font-family and font-size.
   */
  a,
  button,
  h1,
  h2,
  h3,
  h4,
  h5,
  h6,
  input,
  option,
  select,
  textarea {
    /*
     * All elements should inherit the font family from his parent element.
     */
    font-family: inherit;
    /*
     * All elements should inherit the font size from his parent element.
     */
    font-size: inherit;
    /*
     * Letter spacing is required for all texts.
     */
    letter-spacing: inherit;
    /*
     * Word spacing is required for all texts.
     */
    word-spacing: inherit;
  }
  /**
  * Sometimes we need the semantic element for accessibility reasons,
  * but we don't want to show it.
  *
  * - https://www.a11yproject.com/posts/how-to-hide-content/
  */
  .visually-hidden {
    position: fixed;
    top: 0;
    left: 0;
    width: 1px;
    height: 1px;
    overflow: hidden;
    white-space: nowrap;
    clip-path: inset(50%);
  }
}
@layer kol-global {
  /*
   * Dieses CSS stellt sicher, dass der Standard-Style
   * von A und Button resettet werden.
   */
  :is(a, button) {
    background-color: transparent;
    width: 100%;
    margin: 0;
    padding: 0;
    border: none;
    /* 100% needed for custom width from outside */
  }
  /*
   * Ensure elements with hidden attribute to be actually not visible
   * @see https://meowni.ca/hidden.is.a.lie.html
   */
  [hidden] {
    display: none !important;
  }
  .badge-text-hint {
    color: black;
    background-color: lightgray;
  }
}
@layer kol-global {
  :host {
    /*
     * The max-width is needed to prevent the table from overflowing the
     * parent node, if the table is wider than the parent node.
     */
    max-width: 100%;
    font-size: calc(16 * 1rem / var(--kolibri-root-font-size, 16));
  }
  * {
    /*
     * We prefer to box-sizing: border-box for all elements.
     */
    box-sizing: border-box;
  }
  .kol-span {
    /* KolSpan is a layout component with icons in all directions and a label text in the middle. */
    display: grid;
    place-items: center;
    /* The sub span in KolSpan is the horizontal span with icon left and right and the label text in the middle. */
  }
  .kol-span__container {
    display: flex;
    place-items: center;
  }
  a,
  button {
    cursor: pointer;
  }
  .kol-span .kol-span__label--hide-label .kol-span__label {
    display: none;
  }
  /* Reset browser agent style. */
  button:disabled {
    color: unset;
  }
  .disabled label,
  .disabled:focus-within label,
  [aria-disabled=true],
  [aria-disabled=true]:focus,
  [disabled],
  [disabled]:focus {
    opacity: 0.5;
    outline: none;
    cursor: not-allowed;
  }
  [aria-disabled=true]:focus .kol-span,
  [disabled]:focus .kol-span {
    outline: none !important;
  }
}
@layer kol-component {
  :host {
    display: block;
  }
}
@layer kol-component {
  @keyframes fadeInOpacity {
    0% {
      opacity: 0;
    }
    100% {
      opacity: 1;
    }
  }
  .kol-tooltip {
    display: contents;
  }
  .kol-tooltip__floating {
    display: none;
    position: fixed;
    /* Avoid layout interference - see https://floating-ui.com/docs/computePosition */
    top: 0;
    left: 0;
    /* Can be used to specify the tooltip-width from the outside. Unset by default.  */
    width: var(--kol-tooltip-width);
    max-width: 90vw;
    max-height: 90vh;
    visibility: hidden;
    animation-duration: 0.25s;
    animation-iteration-count: 1;
    animation-name: fadeInOpacity;
    animation-timing-function: ease-in;
  }
  .kol-tooltip__arrow {
    transform: rotate(45deg);
    color: #000;
    background-color: #fff;
    position: absolute;
    z-index: 999;
    width: calc(10 * 1rem / var(--kolibri-root-font-size, 16));
    height: calc(10 * 1rem / var(--kolibri-root-font-size, 16));
  }
  .kol-tooltip__content {
    color: #000;
    background-color: #fff;
    position: relative;
    z-index: 1000;
  }
}
@layer kol-component {
  .kol-tabs {
    display: var(--display);
    grid-template-columns: var(--grid-template-columns);
    grid-template-rows: var(--grid-template-rows);
  }
  .kol-tabs--align-right {
    --display: grid;
    --grid-template-columns: 1fr auto;
    --button-group-flex-direction: column;
    --button-group-order: 2;
  }
  .kol-tabs--align-left {
    --display: grid;
    --grid-template-columns: auto 1fr;
    --button-group-flex-direction: column;
    --button-group-order: 0;
  }
  .kol-tabs--align-bottom {
    --display: grid;
    --grid-template-rows: 1fr auto;
    --button-group-order: 2;
  }
  .kol-tabs__tabs-align-top {
    --display: grid;
    --grid-template-rows: auto 1fr;
    --button-group-order: 0;
  }
  .kol-tabs__button-group {
    display: flex;
    order: var(--button-group-order);
    flex-direction: var(--button-group-flex-direction);
    flex-wrap: wrap;
  }
  .kol-tabs__button-group .kol-button {
    border-bottom-color: transparent;
    display: block;
    border-bottom-style: solid;
  }
  .kol-tabs__panel {
    height: 100%;
  }
}`,I=class{constructor(e){p(this,e),this.onCreateLabel=`${P("kol-new")} …`,this.nextPossibleTabIndex=(t,n,i=1)=>{const a=n+i;return a<t.length?t[a]._disabled?this.nextPossibleTabIndex(t,n,i+1):a:n},this.prevPossibleTabIndex=(t,n,i=1)=>{const a=n-i;return a>=0?t[a]._disabled?this.prevPossibleTabIndex(t,n,i+1):a:n},this.onKeyDown=t=>{switch(t.key){case r.ArrowRight:this.goToNextTab(t);break;case r.ArrowLeft:this.goToPreviousTab(t);break;case r.Space:case r.Enter:this.activateFocusedTab(t);break}},this.onClickSelect=(t,n)=>{this.selectNextTabEvent(t,n)},this.onMouseDown=t=>{t.preventDefault()},this.callbacks={onClick:this.onClickSelect,onMouseDown:this.onMouseDown},this.catchTabPanelHost=t=>{this.tabPanelHost=t},this._align="top",this._hasCreateButton=!1,this._selected=0,this.state={_align:"top",_label:"",_selected:0,_tabs:[]},this.selectNextNotDisabledTab=(t,n,i=!0,a)=>{if(t>n.length-1&&(t=n.length-1),t<0&&(t=0),Array.isArray(n)&&n[t]&&n[t]._disabled){if(i===!0){if(t<n.length-1)return this.selectNextNotDisabledTab(t+1,n,!0,a||t);t=a||t,i=!1}if(i===!1){if(t>0)return this.selectNextNotDisabledTab(t-1,n,!1,a||t);f("[KolTabs] All tabs are disabled, and therefore no tab can be displayed.")}}return t},this.syncSelectedAndTabs=(t,n,i,a)=>{let o;a==="_selected"?o=t:o=this.state._selected;let s;a==="_tabs"?s=t:s=this.state._tabs,s.length>0&&n.set("_selected",this.selectNextNotDisabledTab(o,s))},this.refreshTabPanels=()=>{var t,n,i,a;if(this.tabPanelHost){for(;this.tabPanelHost.firstChild;)this.tabPanelHost.removeChild(this.tabPanelHost.firstChild);for(let o=0;o<((t=this.state._tabs)===null||t===void 0?void 0:t.length);o++){const s=document.createElement("div");s.setAttribute("aria-labelledby",`${this.state._label.replace(/\s/g,"-")}-tab-${o}`),s.setAttribute("id",`tabpanel-${o}`),s.setAttribute("role","tabpanel"),s.setAttribute("hidden","");const d=document.createElement("slot");d.setAttribute("name",`tabpanel-slot-${o}`),s.appendChild(d),(n=this.tabPanelHost)===null||n===void 0||n.appendChild(s),typeof HTMLCollection<"u"&&((i=this.host)===null||i===void 0?void 0:i.children)instanceof HTMLCollection&&(!((a=this.host)===null||a===void 0)&&a.children[o])&&this.host.children[o].setAttribute("slot",`tabpanel-slot-${o}`)}this.updateVisiblePanel()}},this.updateVisiblePanel=()=>{this.tabPanelHost&&Array.from(this.tabPanelHost.children).forEach((t,n)=>{n===this.state._selected?t.removeAttribute("hidden"):t.setAttribute("hidden","")})},this.onCreate=t=>{var n,i;t.preventDefault(),(i=(n=this.state._on)===null||n===void 0?void 0:n.onCreate)===null||i===void 0||i.call(n,t),this.host&&h(this.host,c.create)},this.onBlur=()=>{this.currentFocusIndex=void 0}}getCurrentFocusIndex(){return typeof this.currentFocusIndex=="number"?this.currentFocusIndex:this.state._selected}getKeyboardTabChangeMode(){return this._behavior==="select-manual"?"selectFocusOnly":"activateCompletely"}goToNextTab(e){const t=this.nextPossibleTabIndex(this.state._tabs,this.getCurrentFocusIndex());this.selectNextTabEvent(e,t,this.getKeyboardTabChangeMode())}goToPreviousTab(e){const t=this.prevPossibleTabIndex(this.state._tabs,this.getCurrentFocusIndex());this.selectNextTabEvent(e,t,this.getKeyboardTabChangeMode())}activateFocusedTab(e){typeof this.currentFocusIndex=="number"&&this.onSelect(e,this.currentFocusIndex)}selectNextTabEvent(e,t,n="activateCompletely"){var i,a;this.currentFocusIndex=t,this.focusTabById(t),n==="activateCompletely"&&(this._selected=t,(a=(i=this.state._tabs[t]._on)===null||i===void 0?void 0:i.onSelect)===null||a===void 0||a.call(i,e,t),this.onSelect(e,t))}renderButtonGroup(){return l("div",{"aria-label":this.state._label,class:"kol-tabs__button-group",role:"tablist",onKeyDown:this.onKeyDown,onBlur:this.onBlur},this.state._tabs.map((e,t)=>l(b,{_disabled:e._disabled,_icons:e._icons,_hideLabel:e._hideLabel,_label:e._label,_on:this.callbacks,_tabIndex:this.state._selected===t?0:-1,_tooltipAlign:e._tooltipAlign,_buttonVariant:this.state._selected===t?"custom":void 0,_customClass:this.state._selected===t?"selected":void 0,_ariaControls:`tabpanel-${t}`,_ariaSelected:this.state._selected===t,_id:`${this.state._label.replace(/\s/g,"-")}-tab-${t}`,_role:"tab",_value:t})),this.state._hasCreateButton&&l(b,{class:"kol-tabs__button-create",_label:this.onCreateLabel,_on:{onClick:this.onCreate},_icons:"codicon codicon-plus","data-testid":"tabs-create-button"}))}render(){return l("div",{key:"c90d53464702512863a3483602ed15645a6c0484",ref:e=>{this.tabPanelsElement=e},class:S("kol-tabs",`kol-tabs--align-${this.state._align}`)},this.renderButtonGroup(),l("div",{key:"3e172f4835867233726b1ae2081e3a6729eb3b83",class:"kol-tabs__content",ref:this.catchTabPanelHost}))}validateAlign(e){x(this,e)}validateBehavior(e){A(this,e)}validateHasCreateButton(e){B(this,e)}validateLabel(e){C(this,e,{required:!0})}validateOn(e){if(typeof e=="object"&&e!==null){const t={};typeof e.onCreate=="function"&&(t.onCreate=e.onCreate),typeof e.onSelect=="function"&&(t.onSelect=e.onSelect),m(this,"_on",t)}}validateSelected(e){g(this,"_selected",e,{hooks:{beforePatch:this.syncSelectedAndTabs}})}validateTabs(e){_(this,"_tabs",t=>typeof t=="object"&&t!==null&&typeof t._label=="string"&&t._label.length>0,e,void 0,{hooks:{beforePatch:this.syncSelectedAndTabs,afterPatch:this.refreshTabPanels}}),v("KolTabs",this.state._tabs.length)}componentWillLoad(){this.validateAlign(this._align),this.validateLabel(this._label),this.validateOn(this._on),this.validateSelected(this._selected),this.validateTabs(this._tabs),this.validateBehavior(this._behavior),this.validateHasCreateButton(this._hasCreateButton)}componentDidRender(){this.refreshTabPanels()}focusTabById(e){if(this.tabPanelsElement){const t=y(`button#${this.state._label.replace(/\s/g,"-")}-tab-${e}`,this.tabPanelsElement);t?.focus()}}onSelect(e,t){var n,i;(i=(n=this._on)===null||n===void 0?void 0:n.onSelect)===null||i===void 0||i.call(n,e,t),this.host&&h(this.host,c.select,t),this.focusTabById(t)}get host(){return k(this)}static get watchers(){return{_align:["validateAlign"],_behavior:["validateBehavior"],_hasCreateButton:["validateHasCreateButton"],_label:["validateLabel"],_on:["validateOn"],_selected:["validateSelected"],_tabs:["validateTabs"]}}};I.style={default:z};export{I as kol_tabs};
//# sourceMappingURL=kol-tabs.entry-9kE1VpQ8.js.map
