import{r as S,s as c,w as g,aa as w,t as k,p as m,h as p,ab as D,ac as x,H as P,m as C,o as z,C as T}from"./index-BeCeuELg.js";import{t as f}from"./i18n-43b7aa72-DSS4ELtF.js";import{t as O}from"./events-29e84d75-CETYymUM.js";import{E as _}from"./keyboard-77e19a81-BWwnOSNt.js";import{v as F,a as j,b as E,c as A}from"./table-selection-990198ae-BDYQcGYp.js";import{v as H}from"./label-3757689e-D7ErDa5R.js";const y=["top","bottom","both"],W=(t,n)=>{g(t,"_paginationPosition",i=>typeof i=="string"&&y.includes(i),new Set([`PaginationPositionPropType {${y.join(", ")}`]),n,{defaultValue:"bottom"})},M=`/*
 * This file contains all rules for accessibility.
 */
@layer kol-a11y {
  :host {
    /*
     * Minimum size of interactive elements.
     */
    --a11y-min-size: calc(44rem / var(--kolibri-root-font-size, 16));
    color: black;
    /*
     * No element should be used without a background and font color whose contrast ratio has
     * not been checked. By initially setting the background color to white and the font color
     * to black, the contrast ratio is ensured and explicit adjustment is forced.
     */
    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 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%; /* 100% needed for custom width from outside */
    margin: 0;
    padding: 0;
    border: none;
  }
  /*
   * Ensure elements with hidden attribute to be actually not visible
   * @see https://meowni.ca/hidden.is.a.lie.html
   */
  [hidden] {
    display: none !important;
  }
}
@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(16rem / var(--kolibri-root-font-size, 16));
  }
  * {
    /*
     * We prefer to box-sizing: border-box for all elements.
     */
    box-sizing: border-box;
  }
  /* KolSpan is a layout component with icons in all directions and a label text in the middle. */
  .kol-span-wc {
    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-wc > span {
    display: flex;
    place-items: center;
  }
  a,
  button {
    cursor: pointer;
  }
  /* This is the text label. */
  .hide-label > .kol-span-wc > span > span {
    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-wc,
  [disabled]:focus .kol-span-wc {
    outline: none !important;
  }
  .badge-text-hint {
    color: black;
    background-color: lightgray;
  }
}
@layer kol-component {
  :host {
    display: block;
  }
}
@layer kol-component {
  .kol-tooltip-wc {
    display: contents;
  }
  .kol-tooltip-wc .tooltip-floating {
    opacity: 0;
    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, unset);
    max-width: 90vw;
    max-height: 90vh;
    animation-direction: normal;
    /* Can be used to specify the animation duration from the outside. 250ms by default. */
    animation-duration: var(--kolibri-tooltip-animation-duration, 250ms);
    animation-fill-mode: forwards;
    animation-iteration-count: 1;
    animation-timing-function: ease-in;
  }
  .kol-tooltip-wc .tooltip-floating.hide {
    animation-name: hideTooltip;
  }
  .kol-tooltip-wc .tooltip-floating.show {
    animation-name: showTooltip;
  }
  /* Shared between content and arrow */
  .kol-tooltip-wc .tooltip-area {
    color: #000;
    background-color: #fff;
  }
  .kol-tooltip-wc .tooltip-arrow {
    transform: rotate(45deg);
    position: absolute;
    z-index: 999;
    width: calc(10rem / var(--kolibri-root-font-size, 16));
    height: calc(10rem / var(--kolibri-root-font-size, 16));
  }
  .kol-tooltip-wc .tooltip-content {
    position: relative;
    z-index: 1000;
  }
  @keyframes hideTooltip {
    0% {
      opacity: 1;
    }
    100% {
      opacity: 0;
      display: none;
    }
  }
  @keyframes showTooltip {
    0% {
      opacity: 0;
    }
    100% {
      opacity: 1;
    }
  }
}
@layer kol-component {
  div.pagination {
    display: grid;
    place-items: center;
  }
  div.pagination .kol-pagination {
    display: flex;
    flex-wrap: wrap;
  }
  div.pagination > div:last-child {
    display: grid;
    place-items: center;
  }
  @media (max-width: 1024px) {
    div.pagination .kol-pagination {
      flex-direction: column;
    }
  }
  @media (min-width: 1024px) {
    div.pagination,
    div.pagination > div:last-child {
      grid-auto-flow: column;
    }
  }
}
@layer kol-component {
  :host,
  .kol-table-stateless-wc {
    display: block;
  }
  .table {
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
  }
  table {
    width: 100%;
  }
  caption {
    text-align: start;
  }
  .focus-element:focus {
    outline: 0 !important;
  }
  .table:has(.focus-element:focus) {
    /* @see https://remysharp.com/til/css/focus-ring-default-styles */
    outline: 5px auto Highlight;
    outline: 5px auto -webkit-focus-ring-color;
    outline-offset: 2px;
  }
  .table-sort-button .button {
    color: inherit;
  }
  tbody th,
  .table__header-cell--align-left {
    text-align: left;
  }
  tbody th .table-sort-button .button-inner,
  .table__header-cell--align-left .table-sort-button .button-inner {
    justify-items: start;
  }
  .table__header-cell--align-center {
    text-align: center;
  }
  .table__header-cell--align-center .table-sort-button .button-inner {
    justify-items: center;
  }
  .table__header-cell--align-right {
    text-align: right;
  }
  .table__header-cell--align-right .table-sort-button .button-inner {
    justify-items: end;
  }
  tr.foot-spacer,
  tr.head-spacer {
    display: none;
  }
  .selection-header-cell {
    width: 0;
  }
  .selection-cell {
    width: var(--a11y-min-size);
    height: var(--a11y-min-size);
    white-space: nowrap;
  }
  .input label {
    display: flex;
    position: relative;
    width: var(--a11y-min-size);
    height: var(--a11y-min-size);
    align-items: center;
    justify-content: center;
    cursor: pointer;
  }
  .input .icon {
    display: block;
    position: absolute;
    inset: auto;
    z-index: 1;
  }
  .input input {
    border-style: solid;
    margin: 0;
    appearance: none;
    cursor: pointer;
  }
  .input input:before {
    content: "";
  }
  .input input[type=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;
    transition: all 0.5s ease 0s;
  }
  .input input[type=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;
  }
  .input input[type=radio]:before {
    border-radius: 100%;
    width: 0.75em;
    height: 0.75em;
    margin: auto;
  }
  .input input[type=radio]:checked:before {
    background-color: #000;
  }
  @media (forced-colors: active) {
    .input input[type=radio]:checked:before {
      /* Give it a visible background in forced colors mode */
      background-color: selectedItem !important;
    }
  }
}`,K=M,N=[10,20,50,100],v=t=>t===!0||t===""||typeof t=="object"&&t!==null,L=class{constructor(t){S(this,t),this.catchRef=n=>{this.tableWcRef=n},this.sortDirections=new Map,this.sortData=[],this.showPagination=!1,this.pageStartSlice=0,this.pageEndSlice=10,this.disableSort=!1,this.sortedColumnHead={label:"",key:"",sortDirection:"NOS"},this.setSortDirection=(n,i)=>{this.sortDirections.clear(),this.sortDirections.set(n,i),this.sortFunction=n},this.handlePagination={onClick:(n,i)=>{var e;typeof((e=this.state._pagination._on)===null||e===void 0?void 0:e.onClick)=="function"&&this.state._pagination._on.onClick(n,i),c(this,"_pagination",Object.assign(Object.assign({},this.state._pagination),{_page:i}))},onChangePage:(n,i)=>{var e;typeof((e=this.state._pagination._on)===null||e===void 0?void 0:e.onChangePage)=="function"&&this.state._pagination._on.onChangePage(n,i),c(this,"_pagination",Object.assign(Object.assign({},this.state._pagination),{_page:i}))},onChangePageSize:(n,i)=>{var e;typeof((e=this.state._pagination._on)===null||e===void 0?void 0:e.onChangePageSize)=="function"&&this.state._pagination._on.onChangePageSize(n,i),c(this,"_pagination",Object.assign(Object.assign({},this.state._pagination),{_pageSize:i})),c(this,"_pageSize",i)}},this.onSelectionChange=n=>{n.stopPropagation()},this.updateSortedData=(n=this.sortedColumnHead)=>{if(this.disableSort){c(this,"_sortedData",this.state._data);return}let i=[...this.state._data];if(this.sortData.length>0)i.sort((e,a)=>{for(let l=0;l<this.sortData.length;l++){const h=this.sortData[l],o=h.compareFn(e,a);if(o!==0)return h.direction==="ASC"?o:-o}return 0});else if(typeof this.sortFunction=="function")switch(this.sortDirections.get(this.sortFunction)){case"ASC":i=this.sortFunction([...this.state._data]),this.sortedColumnHead={label:n.label,key:n.key,sortDirection:"ASC"};break;case"DESC":i=this.sortFunction([...this.state._data]).reverse(),this.sortedColumnHead={label:n.label,key:n.key,sortDirection:"DESC"};break;default:this.sortedColumnHead={label:"",key:"",sortDirection:"NOS"}}c(this,"_sortedData",i)},this._allowMultiSort=void 0,this._data=void 0,this._dataFoot=void 0,this._headers=void 0,this._label=void 0,this._minWidth=void 0,this._pagination=void 0,this._paginationPosition="bottom",this._selection=void 0,this._on=void 0,this.state={_allowMultiSort:!1,_data:[],_dataFoot:[],_headers:{horizontal:[],vertical:[]},_label:"",_pagination:{_page:1,_pageSize:10,_max:0},_sortedData:[],_paginationPosition:"bottom"}}validateAllowMultiSort(t){g(this,"_allowMultiSort",()=>!0,new Set(["boolean"]),t,{defaultValue:!1})}validateData(t){F(this,t,{afterPatch:()=>{setTimeout(this.updateSortedData)}})}validateDataFoot(t){j(this,t,{afterPatch:()=>{setTimeout(this.updateSortedData)}})}validatePaginationPosition(t){W(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 i=this.sortData.findIndex(e=>e.key===t.key);if(i>=0){const e=this.sortData[i];switch(e.direction){case"ASC":e.direction="DESC";break;case"DESC":this.sortData.splice(i,1);break;default:e.direction="ASC";break}}else t.key&&this.sortData.push({label:t.label,key:t.key,compareFn:t.compareFn,direction:"ASC"});this.updateSortedData(t)}else if(typeof t.sort=="function"){switch(this.sortFunction=t.sort,this.sortDirections.get(this.sortFunction)){case"ASC":this.setSortDirection(this.sortFunction,"DESC");break;case"DESC":this.setSortDirection(this.sortFunction,"NOS");break;default:this.setSortDirection(this.sortFunction,"ASC")}this.updateSortedData(t)}}validateHeaders(t){w(t,()=>{z(t,()=>{try{t=m(t)}catch{}g(this,"_headers",n=>typeof n=="object"&&n!==null,new Set(["KoliBriTableHeaders"]),t,{hooks:{beforePatch:n=>{var i,e,a,l;const h=r=>{let s=!1;r.forEach(d=>{const b=d.key;if(!b)return;const u=d.sortDirection;(u==="ASC"||u==="DESC")&&(typeof d.compareFn=="function"?((this.state._allowMultiSort||this.sortData.length===0)&&this.sortData.push({label:d.label,key:b,compareFn:d.compareFn,direction:u}),s=!0):typeof d.sort=="function"&&(this.setSortDirection(d.sort,u),setTimeout(()=>this.updateSortedData({key:b,label:d.label,sortDirection:u}))))}),s&&setTimeout(()=>this.updateSortedData())},o=n;(i=o.horizontal)===null||i===void 0||i.forEach(h),(e=o.vertical)===null||e===void 0||e.forEach(h),o.horizontal&&o.vertical&&((a=o.horizontal)===null||a===void 0?void 0:a.length)>0&&((l=o.vertical)===null||l===void 0?void 0:l.length)>0&&(this.disableSort=!0,T("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){H(this,t,{required:!0})}validateMinWidth(t){k(this,"_minWidth",t,{defaultValue:void 0})}validateSelection(t){E(this,t)}validateOn(t){A(this,t)}validatePagination(t){try{t=m(t)}catch{}this.showPagination=v(t),g(this,"_pagination",v,new Set(["boolean","KoliBriTablePagination"]),t,{defaultValue:{_page:1,_pageSize:10,_max:0}})}componentDidLoad(){var t;(t=this.tableWcRef)===null||t===void 0||t.addEventListener("kol-selection-change",this.onSelectionChange)}disconnectedCallback(){var t;(t=this.tableWcRef)===null||t===void 0||t.removeEventListener("kol-selection-change",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.validatePagination(this._pagination),this.validatePaginationPosition(this._paginationPosition),this.validateSelection(this._selection),this.validateOn(this._on)}selectDisplayedData(t,n,i){return typeof n=="number"&&n>0&&typeof i=="number"&&i>0?(this.pageStartSlice=n*(i-1),this.pageEndSlice=n*i>t.length?t.length:n*i,t.slice(this.pageStartSlice,this.pageEndSlice)):(this.pageStartSlice=0,this.pageEndSlice=t.length,t)}renderPagination(t){const n=f("kol-table-pagination-label",{placeholders:{label:`${this.state._label} (${f(`kol-pagination-position-${t}`)})`}});return p("div",{class:"pagination"},p("span",{role:"status","aria-live":"polite"},f("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"}})),p("div",null,p(D,{_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||N,_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"||typeof t.sort=="function")){if(t.key===this.sortedColumnHead.key)return this.sortedColumnHead.sortDirection;if(t.key){const n=this.sortData.find(i=>i.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(i=>i.key===t);n&&this.changeCellSort(n)}getSelectedData(t){var n;const i=this.state._selection;if(i){const e=(n=i.keyPropertyName)!==null&&n!==void 0?n:"id",a=this.state._sortedData.filter(l=>t.includes(l[e]));if(i?.multiple===!1)return a[0];if(e)return a}return null}handleSelectionChange(t,n){var i;const e=this.state._selection;e&&(this.state=Object.assign(Object.assign({},this.state),{_selection:Object.assign(Object.assign({},e),{selectedKeys:typeof n=="object"?n:[n]})}));const a=this.getSelectedData(n);O("selection-change",this.host,a),typeof((i=this.state._on)===null||i===void 0?void 0:i[_.onSelectionChange])=="function"&&this.state._on[_.onSelectionChange](t,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,i,e;const a=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),l=this._paginationPosition==="top"||this._paginationPosition==="both"?this.renderPagination("top"):null,h=this._paginationPosition==="bottom"||this._paginationPosition==="both"?this.renderPagination("bottom"):null,o={horizontal:(i=this.state._headers.horizontal)===null||i===void 0?void 0:i.map(r=>r.map(s=>Object.assign(Object.assign({},s),{sortDirection:this.getHeaderCellSortState(s)}))),vertical:(e=this.state._headers.vertical)===null||e===void 0?void 0:e.map(r=>r.map(s=>Object.assign(Object.assign({},s),{sortDirection:this.getHeaderCellSortState(s)})))};return p(P,{key:"08f169e0520e974e018e987202a9af0ced93a19e",class:"kol-table-stateful"},this.pageEndSlice>0&&this.showPagination&&l,p(x,{key:"86b50cb5b9d07ea8c137c54a51b92ec03b656dce",ref:this.catchRef,_data:a,_headerCells:o,_label:this.state._label,_dataFoot:this.state._dataFoot,_minWidth:this.state._minWidth,_on:{onSort:(r,s)=>{this.handleSort(s)},onSelectionChange:(r,s)=>{this.handleSelectionChange(r,s)}},_selection:this.state._selection}),this.pageEndSlice>0&&this.showPagination&&h)}get host(){return C(this)}static get watchers(){return{_allowMultiSort:["validateAllowMultiSort"],_data:["validateData"],_dataFoot:["validateDataFoot"],_paginationPosition:["validatePaginationPosition"],_headers:["validateHeaders"],_label:["validateLabel"],_minWidth:["validateMinWidth"],_selection:["validateSelection"],_on:["validateOn"],_pagination:["validatePagination"]}}};L.style={default:K};export{L as kol_table_stateful};
//# sourceMappingURL=kol-table-stateful.entry-jnkPdCRj.js.map
