import{r as w,s as c,aa as x,n as z,p as m,w as f,a as _,h,G as P,d as D,ab as C,H as T,g as j,m as O,o as M,v as k}from"./index-DscFWUNz.js";import{t as u}from"./i18n-CdSCDnmA-Bln0Fy0B.js";import{v as A,a as E,b as F,c as W,d as H,e as K}from"./table-settings-DSZObo-2-Cp_zllcr.js";import{v as L}from"./label-CdtNxOKu-DuSxxbJz.js";import{C as v}from"./keyboard-D6PoWr38-Bn_Qh8Bq.js";/*!
 * KoliBri - The accessible HTML-Standard
 */const V=(t,n,e={})=>{O(t,"_allowMultiSort",n,Object.assign({defaultValue:!1},e))},y=["top","bottom","both"],q=(t,n)=>{f(t,"_paginationPosition",e=>typeof e=="string"&&y.includes(e),new Set([`PaginationPositionPropType {${y.join(", ")}`]),n,{defaultValue:"bottom"})},B=`@charset "UTF-8";
/*
* 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;
/* forward the rem function */
/*
 * 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-alert {
    display: grid;
  }
  .kol-alert__container {
    display: flex;
    place-items: center;
  }
  .kol-alert__container-content {
    flex-grow: 1;
  }
  .kol-alert__closer {
    /* Visible with forced colors */
    outline: transparent solid calc(1 * 1rem / var(--kolibri-root-font-size, 16));
  }
  :host {
    display: inline-block;
  }
  .kol-button {
    display: inline-flex;
    place-items: center;
    font-style: calc(16 * 1rem / var(--kolibri-root-font-size, 16));
    text-align: center;
    text-decoration-line: none;
  }
  .kol-button::before {
    /* Render zero-width character as first element to set the baseline correctly. */
    content: "​";
  }
  .kol-button__text {
    width: 100%;
    margin: auto;
  }
  .kol-popover-button__button {
    display: inline-block;
  }
  .kol-popover-button__popover {
    margin: 0;
    padding: 0;
    border: 0;
  }
  .kol-table-settings {
    background: #fff;
    position: absolute;
    top: 0;
    right: 0;
    z-index: 1;
  }
  .kol-table-settings .kol-popover-button__popover {
    background: #fff;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    border-radius: calc(8 * 1rem / var(--kolibri-root-font-size, 16));
    border: 1px solid #d1d5db;
  }
  .kol-table-settings__columns-container {
    max-height: calc(200 * 1rem / var(--kolibri-root-font-size, 16));
    margin-top: calc(16 * 1rem / var(--kolibri-root-font-size, 16));
    overflow: auto;
  }
  .kol-table-settings__columns {
    display: grid;
    overflow: hidden;
    gap: calc(8 * 1rem / var(--kolibri-root-font-size, 16));
    align-items: center;
    grid-auto-rows: min-content;
    grid-template-columns: min-content 1fr calc(100 * 1rem / var(--kolibri-root-font-size, 16)) auto auto;
  }
  .kol-table-settings__column {
    display: contents;
  }
  .kol-table {
    display: block;
    position: relative;
    max-width: 100%;
  }
  .kol-table__scroll-container {
    overflow-x: auto;
    overflow-y: hidden;
  }
  .kol-table:has(.kol-table__focus-element:focus) .kol-table__scroll-container {
    /* @see https://remysharp.com/til/css/focus-ring-default-styles */
    outline: 5px auto Highlight;
    outline: 5px auto -webkit-focus-ring-color;
    outline-offset: 2px;
  }
  .kol-table__table {
    width: 100%;
  }
  .kol-table__caption {
    min-height: var(--a11y-min-size);
    padding-right: var(--a11y-min-size);
    text-align: start;
  }
  .kol-table__sort-button .kol-button {
    color: inherit;
  }
  .kol-table__body {
    text-align: left;
  }
  .kol-table__body .kol-button__text {
    justify-items: start;
  }
  .kol-table__cell--align-left {
    text-align: left;
  }
  .kol-table__cell--align-left .kol-button__text {
    justify-items: start;
  }
  .kol-table__cell--align-center {
    text-align: center;
  }
  .kol-table__cell--align-center .kol-button__text {
    justify-items: center;
  }
  .kol-table__cell--align-right {
    text-align: right;
  }
  .kol-table__cell--align-right .kol-button__text {
    justify-items: end;
  }
  .kol-table__cell--selection {
    width: var(--a11y-min-size);
    height: var(--a11y-min-size);
    white-space: nowrap;
  }
  .kol-table__spacer {
    display: none;
  }
  .kol-table__selection-label {
    display: flex;
    position: relative;
    width: var(--a11y-min-size);
    height: var(--a11y-min-size);
    align-items: center;
    justify-content: center;
    cursor: pointer;
  }
  .kol-table__selection-label--disabled {
    cursor: not-allowed;
  }
  .kol-table__selection-icon {
    display: block;
    position: absolute;
    inset: auto;
    z-index: 1;
  }
  .kol-table__selection-input {
    border-style: solid;
    margin: 0;
    appearance: none;
    cursor: pointer;
  }
  .kol-table__selection-input:disabled {
    cursor: not-allowed;
  }
  .kol-table__selection-input:before {
    content: "";
  }
  .kol-table__selection-input--checkbox {
    background-color: rgb(255, 255, 255);
    display: flex;
    position: relative;
    width: calc(var(--a11y-min-size) / 2);
    height: calc(var(--a11y-min-size) / 2);
    border-width: 2px;
    align-items: center;
    justify-content: center;
    line-height: 1.5;
  }
  .kol-table__selection-input--radio {
    border-radius: 100%;
    display: flex;
    width: 1.5em;
    min-width: 1.5em;
    height: 1.5em;
    min-height: 1.5em;
    padding: 0;
    border-width: 2px;
  }
  .kol-table__selection-input--radio:before {
    border-radius: 100%;
    width: 0.75em;
    height: 0.75em;
    margin: auto;
  }
  .kol-table__selection-input--radio:checked:before {
    background-color: #000;
  }
  @media (forced-colors: active) {
    .kol-table__selection-input--radio:checked:before {
      /* Give it a visible background in forced colors mode */
      background-color: selectedItem !important;
    }
  }
  .kol-pagination {
    display: grid;
    gap: calc(16 * 1rem / var(--kolibri-root-font-size, 16));
    align-items: center;
    grid-template-columns: 1fr auto;
  }
  .kol-pagination__navigation-list {
    display: inline-flex;
    margin: 0;
    padding: 0;
    gap: 0.5em;
    flex-wrap: wrap;
    align-items: center;
    list-style: none;
  }
  .kol-pagination__separator:before {
    content: "•••";
  }
  .kol-table-stateful__pagination, .kol-table-stateful__pagination-wrapper {
    display: grid;
    place-items: center;
  }
  @media (min-width: 1024px) {
    .kol-table-stateful__pagination, .kol-table-stateful__pagination-wrapper {
      grid-auto-flow: column;
    }
  }
  .kol-pagination {
    display: flex;
    flex-wrap: wrap;
  }
  @media (min-width: 1024px) {
    .kol-pagination {
      display: flex;
    }
  }
  @media (max-width: 1024px) {
    .kol-pagination {
      flex-direction: column;
    }
  }
}`,I=[10,20,50,100],S=t=>t===!0||t===""||typeof t=="object"&&t!==null,N=class{constructor(t){w(this,t),this.catchRef=n=>{this.tableWcRef=n},this.sortData=[],this.showPagination=!1,this.pageStartSlice=0,this.pageEndSlice=10,this.disableSort=!1,this._paginationPosition="bottom",this.state={_allowMultiSort:!1,_data:[],_dataFoot:[],_headers:{horizontal:[],vertical:[]},_label:"",_minWidth:"auto",_pagination:{_page:1,_pageSize:10,_max:0},_sortedData:[],_paginationPosition:"bottom",_hasSettingsMenu:!1},this.handlePagination={onClick:(n,e)=>{var i;typeof((i=this.state._pagination._on)===null||i===void 0?void 0:i.onClick)=="function"&&this.state._pagination._on.onClick(n,e),c(this,"_pagination",Object.assign(Object.assign({},this.state._pagination),{_page:e}))},onChangePage:(n,e)=>{var i;typeof((i=this.state._pagination._on)===null||i===void 0?void 0:i.onChangePage)=="function"&&this.state._pagination._on.onChangePage(n,e),c(this,"_pagination",Object.assign(Object.assign({},this.state._pagination),{_page:e}))},onChangePageSize:(n,e)=>{var i;typeof((i=this.state._pagination._on)===null||i===void 0?void 0:i.onChangePageSize)=="function"&&this.state._pagination._on.onChangePageSize(n,e),c(this,"_pagination",Object.assign(Object.assign({},this.state._pagination),{_pageSize:e})),c(this,"_pageSize",e)}},this.onSelectionChange=n=>{n.stopPropagation()},this.updateSortedData=()=>{if(this.disableSort){c(this,"_sortedData",this.state._data);return}const n=[...this.state._data];this.sortData.length>0&&n.sort((e,i)=>{for(let a=0;a<this.sortData.length;a++){const l=this.sortData[a],r=l.compareFn(e,i);if(r!==0)return l.direction==="ASC"?r:-r}return 0}),c(this,"_sortedData",n)}}validateAllowMultiSort(t){V(this,t,{defaultValue:!1})}validateData(t){A(this,t,{afterPatch:()=>{setTimeout(this.updateSortedData)}})}validateDataFoot(t){E(this,t,{afterPatch:()=>{setTimeout(this.updateSortedData)}})}validatePaginationPosition(t){q(this,t)}validateHasSettingsMenu(t){F(this,t)}changeCellSort(t){var n;if(typeof t.compareFn=="function"){!this.state._allowMultiSort&&t.key!==((n=this.sortData[0])===null||n===void 0?void 0:n.key)&&(this.sortData=[]);const e=this.sortData.findIndex(i=>i.key===t.key);if(e>=0){const i=this.sortData[e];switch(i.direction){case"ASC":i.direction="DESC";break;case"DESC":this.sortData.splice(e,1);break;default:i.direction="ASC";break}}else t.key&&this.sortData.push({label:t.label,key:t.key,compareFn:t.compareFn,direction:"ASC"});this.updateSortedData()}}validateHeaders(t){x(t,()=>{M(t,()=>{try{t=m(t)}catch{}f(this,"_headers",n=>typeof n=="object"&&n!==null,new Set(["KoliBriTableHeaders"]),t,{hooks:{beforePatch:n=>{var e,i,a,l;const r=g=>{let p=!1;g.forEach(o=>{if(typeof o.compareFn=="function"&&!o.key){k("[KolTableStateful] A sortable column requires the 'key' property.");return}const s=o.key;if(!s)return;const b=o.sortDirection;(b==="ASC"||b==="DESC")&&typeof o.compareFn=="function"&&((this.state._allowMultiSort||this.sortData.length===0)&&this.sortData.push({label:o.label,key:s,compareFn:o.compareFn,direction:b}),p=!0)}),p&&setTimeout(()=>this.updateSortedData())},d=n;(e=d.horizontal)===null||e===void 0||e.forEach(r),(i=d.vertical)===null||i===void 0||i.forEach(r),d.horizontal&&d.vertical&&((a=d.horizontal)===null||a===void 0?void 0:a.length)>0&&((l=d.vertical)===null||l===void 0?void 0:l.length)>0&&(this.disableSort=!0,k("Table: You can not sort the table data, if horizontal and vertical headers are defined at the same time. (https://github.com/public-ui/kolibri/issues/2372)"))}}})})})}validateLabel(t){L(this,t,{required:!0})}validateMinWidth(t){z(this,"_minWidth",t,{defaultValue:void 0})}validateSelection(t){W(this,t)}validateOn(t){H(this,t)}validateTableSettings(t){K(this,t)}validatePagination(t){try{t=m(t)}catch{}this.showPagination=S(t),f(this,"_pagination",S,new Set(["boolean","KoliBriTablePagination"]),t,{defaultValue:{_page:1,_pageSize:10,_max:0}})}componentDidLoad(){var t;(t=this.tableWcRef)===null||t===void 0||t.addEventListener(_.selectionChange,this.onSelectionChange)}disconnectedCallback(){var t;(t=this.tableWcRef)===null||t===void 0||t.removeEventListener(_.selectionChange,this.onSelectionChange)}componentWillLoad(){this.validateAllowMultiSort(this._allowMultiSort),this.validateData(this._data),this.validateDataFoot(this._dataFoot),this.validateHeaders(this._headers),this.validateLabel(this._label),this.validateMinWidth(this._minWidth),this.validateOn(this._on),this.validatePagination(this._pagination),this.validatePaginationPosition(this._paginationPosition),this.validateSelection(this._selection),this.validateTableSettings(this._tableSettings),this.validateHasSettingsMenu(this._hasSettingsMenu)}selectDisplayedData(t,n,e){return typeof n=="number"&&n>0&&typeof e=="number"&&e>0?(this.pageStartSlice=n*(e-1),this.pageEndSlice=n*e>t.length?t.length:n*e,t.slice(this.pageStartSlice,this.pageEndSlice)):(this.pageStartSlice=0,this.pageEndSlice=t.length,t)}renderPagination(t){const n=u("kol-table-pagination-label",{placeholders:{label:`${this.state._label} (${u(`kol-pagination-position-${t}`)})`}});return h("div",{class:`kol-table-stateful__pagination kol-table-stateful__pagination--${this.state._paginationPosition}`},h("span",null,u("kol-table-visible-range",{placeholders:{start:this.pageEndSlice>0?(this.pageStartSlice+1).toString():"0",end:this.pageEndSlice.toString(),total:this.state._pagination&&this.state._pagination._max>0?this.state._pagination._max.toString():Array.isArray(this.state._data)?this.state._data.length.toString():"0"}})),h("div",{class:"kol-table-stateful__pagination-wrapper"},h(P,{class:"test",_boundaryCount:this.state._pagination._boundaryCount,_customClass:this.state._pagination._customClass,_on:this.handlePagination,_page:this.state._pagination._page,_pageSize:this.state._pagination._pageSize,_pageSizeOptions:this.state._pagination._pageSizeOptions||I,_siblingCount:this.state._pagination._siblingCount,_tooltipAlign:"bottom",_max:this.state._pagination._max||this.state._pagination._max||this.state._data.length,_label:n})))}getHeaderCellSortState(t){if(!this.disableSort&&typeof t.compareFn=="function"){if(t.key){const n=this.sortData.find(e=>e.key===t.key);if(n?.direction)return n.direction}return"NOS"}}handleSort({key:t}){const n=[...(this.state._headers.horizontal||[]).flat(),...(this.state._headers.vertical||[]).flat()].find(e=>e.key===t);n&&this.changeCellSort(n)}getSelectedData(t){var n;const e=this.state._selection;if(e){const i=(n=e.keyPropertyName)!==null&&n!==void 0?n:"id",a=this.state._sortedData.filter(l=>t.includes(l[i]));if(e?.multiple===!1)return a[0];if(i)return a}return null}handleSelectionChange(t,n){var e;const i=this.state._selection;i&&(this.state=Object.assign(Object.assign({},this.state),{_selection:Object.assign(Object.assign({},i),{selectedKeys:typeof n=="object"?n:[n]})}));const a=this.getSelectedData(n);typeof((e=this.state._on)===null||e===void 0?void 0:e[v.onSelectionChange])=="function"&&this.state._on[v.onSelectionChange](t,a),this.host&&D(this.host,_.selectionChange,a)}async getSelection(){var t;const n=((t=this.state._selection)===null||t===void 0?void 0:t.selectedKeys)||[];return this.getSelectedData(n)}render(){var t,n,e,i,a,l;const r=this.selectDisplayedData(this.state._sortedData,this.showPagination?(n=(t=this.state._pagination)===null||t===void 0?void 0:t._pageSize)!==null&&n!==void 0?n:10:this.state._sortedData.length,this.state._pagination._page||1),d=this._paginationPosition==="top"||this._paginationPosition==="both"?this.renderPagination("top"):null,g=this._paginationPosition==="bottom"||this._paginationPosition==="both"?this.renderPagination("bottom"):null,p={horizontal:(i=(e=this.state._headers.horizontal)===null||e===void 0?void 0:e.map(o=>o.map(s=>Object.assign(Object.assign({},s),{sortDirection:this.getHeaderCellSortState(s)}))))!==null&&i!==void 0?i:[],vertical:(l=(a=this.state._headers.vertical)===null||a===void 0?void 0:a.map(o=>o.map(s=>Object.assign(Object.assign({},s),{sortDirection:this.getHeaderCellSortState(s)}))))!==null&&l!==void 0?l:[]};return h(T,{key:"d2b36026a0c931eebdff9269a19c2e61b32ae9a2",class:"kol-table-stateful"},this.pageEndSlice>0&&this.showPagination&&d,h(C,{key:"9125f5790496178db69cfb865ce666dcf67acf27",ref:this.catchRef,_data:r,_headerCells:p,_label:this.state._label,_dataFoot:this.state._dataFoot,_minWidth:this.state._minWidth,_on:{onSort:(o,s)=>{this.handleSort(s)},onSelectionChange:(o,s)=>{this.handleSelectionChange(o,s)}},_selection:this.state._selection,_tableSettings:this.state._tableSettings,_hasSettingsMenu:this.state._hasSettingsMenu}),this.pageEndSlice>0&&this.showPagination&&g)}get host(){return j(this)}static get watchers(){return{_allowMultiSort:["validateAllowMultiSort"],_data:["validateData"],_dataFoot:["validateDataFoot"],_paginationPosition:["validatePaginationPosition"],_hasSettingsMenu:["validateHasSettingsMenu"],_headers:["validateHeaders"],_label:["validateLabel"],_minWidth:["validateMinWidth"],_selection:["validateSelection"],_on:["validateOn"],_tableSettings:["validateTableSettings"],_pagination:["validatePagination"]}}};N.style={default:B};export{N as kol_table_stateful};
//# sourceMappingURL=kol-table-stateful.entry-CI2YvXhI.js.map
