import{r as S,s as c,w as g,ac as w,n as x,p as m,a as u,h,I as z,d as P,ad as D,H as C,g as T,o as j,v as O}from"./index-yJ8X--q8.js";import{t as f}from"./i18n-H9CUbi---DysS2qV6.js";import{v as E}from"./label-D3d1qqIG-BD7RiEyC.js";import{v as A,a as F,b as W,c as H,d as M}from"./table-settings-BtONOLMh-BaYXvIu9.js";import{C as k}from"./keyboard-D6PoWr38-Bn_Qh8Bq.js";/*!
 * KoliBri - The accessible HTML-Standard
 */const v=["top","bottom","both"],K=(t,n)=>{g(t,"_paginationPosition",e=>typeof e=="string"&&v.includes(e),new Set([`PaginationPositionPropType {${v.join(", ")}`]),n,{defaultValue:"bottom"})},I=`@charset "UTF-8";
/* forward the rem function */
/*
 * This file contains all rules for accessibility.
 */
@layer kol-global {
  :host {
    /*
     * Minimum size of interactive elements.
     */
    --a11y-min-size: calc(44rem / var(--kolibri-root-font-size, 16));
    /*
     * 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;
    color: black;
  }
  * {
    /*
     * This rule enables the word dividing for all texts. That is important for high zoom levels.
     */
    hyphens: auto;
    /*
     * 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;
    /*
     * This rule enables the word dividing for all texts. That is important for high zoom levels.
     */
    word-break: break-word;
    /*
     * Word spacing is required for all texts.
     */
    word-spacing: inherit;
  }
  /*
   * All interactive elements should have a minimum size of to-rem(44).
   */
  /* input:not([type='checkbox'], [type='radio'], [type='range']), */
  /* option, */
  /* select, */
  /* textarea, */
  [role=button],
  button:not([role=link]),
  .kol-input .input {
    min-height: var(--a11y-min-size);
    min-width: 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;
  }
}
/**
 * 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 {
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  height: 1px;
  overflow: hidden;
  position: absolute;
  white-space: nowrap;
  width: 1px;
}

@layer kol-global {
  /*
   * Dieses CSS stellt sicher, dass der Standard-Style
   * von A und Button resettet werden.
   */
  :is(a, button) {
    background-color: transparent;
    border: none;
    margin: 0;
    padding: 0;
    width: 100%;
    /* 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 {
    background-color: lightgray;
    color: black;
  }
}
@layer kol-global {
  :host {
    font-size: calc(16rem / var(--kolibri-root-font-size, 16));
    /*
     * 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%;
  }
  * {
    /*
     * 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 {
    cursor: not-allowed;
    opacity: 0.5;
    outline: none;
  }
  [aria-disabled=true]:focus .kol-span,
  [disabled]:focus .kol-span {
    outline: none !important;
  }
}
@layer kol-component {
  :host {
    display: block;
  }
}
@layer kol-component {
  .kol-tooltip {
    contain: layout;
    display: contents;
  }
  .kol-tooltip__floating {
    animation-duration: 0.25s;
    animation-iteration-count: 1;
    animation-name: fadeInOpacity;
    animation-timing-function: ease-in;
    display: none;
    position: fixed;
    visibility: hidden;
    /* Avoid layout interference - see https://floating-ui.com/docs/computePosition */
    top: 0;
    left: 0;
    max-width: 90vw;
    max-height: 90vh;
    /* Can be used to specify the tooltip-width from the outside. Unset by default.  */
    width: var(--kol-tooltip-width);
  }
  .kol-tooltip__arrow {
    background-color: #fff;
    color: #000;
    height: calc(10rem / var(--kolibri-root-font-size, 16));
    position: absolute;
    transform: rotate(45deg);
    width: calc(10rem / var(--kolibri-root-font-size, 16));
    z-index: 999;
  }
  .kol-tooltip__content {
    background-color: #fff;
    color: #000;
    position: relative;
    z-index: 1000;
  }
  @keyframes fadeInOpacity {
    0% {
      opacity: 0;
    }
    100% {
      opacity: 1;
    }
  }
}
@layer kol-component {
  .kol-alert {
    display: grid;
  }
  .kol-alert__container {
    place-items: center;
    display: flex;
  }
  .kol-alert__container-content {
    flex-grow: 1;
  }
  .kol-alert__closer {
    /* Visible with forced colors */
    outline: transparent solid calc(1rem / var(--kolibri-root-font-size, 16));
  }
}
@layer kol-component {
  :host {
    display: inline-block;
  }
  .kol-button {
    font-style: calc(16rem / var(--kolibri-root-font-size, 16));
    display: inline-flex;
    place-items: center;
    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 {
    margin: auto;
    width: 100%;
  }
}
@layer kol-component {
  .kol-popover-button__button {
    display: inline-block;
  }
  .kol-popover-button__popover {
    border: 0;
    margin: 0;
    padding: 0;
  }
}
@layer kol-component {
  .kol-table-settings {
    background: #fff;
    position: absolute;
    right: 0;
    top: 0;
    z-index: 1;
  }
  .kol-table-settings__columns-container {
    margin-top: calc(16rem / var(--kolibri-root-font-size, 16));
    max-height: calc(200rem / var(--kolibri-root-font-size, 16));
    overflow: auto;
  }
  .kol-table-settings__columns {
    align-items: center;
    display: grid;
    gap: calc(8rem / var(--kolibri-root-font-size, 16));
    grid-auto-rows: min-content;
    grid-template-columns: min-content 1fr calc(100rem / var(--kolibri-root-font-size, 16)) auto auto;
    overflow: hidden;
  }
  .kol-table-settings__column {
    display: contents;
  }
}
@layer kol-component {
  .kol-table {
    display: block;
    max-width: 100%;
    position: relative;
  }
  .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 {
    text-align: start;
    min-height: var(--a11y-min-size);
    padding-right: var(--a11y-min-size);
  }
  .kol-table__focus-element {
    font-size: 0;
  }
  .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 {
    align-items: center;
    cursor: pointer;
    display: flex;
    height: var(--a11y-min-size);
    justify-content: center;
    position: relative;
    width: var(--a11y-min-size);
  }
  .kol-table__selection-label--disabled {
    cursor: not-allowed;
  }
  .kol-table__selection-icon {
    display: block;
    inset: auto;
    position: absolute;
    z-index: 1;
  }
  .kol-table__selection-input {
    appearance: none;
    border-style: solid;
    cursor: pointer;
    margin: 0;
  }
  .kol-table__selection-input:disabled {
    cursor: not-allowed;
  }
  .kol-table__selection-input:before {
    content: "";
  }
  .kol-table__selection-input--checkbox {
    position: relative;
    display: flex;
    height: calc(var(--a11y-min-size) / 2);
    width: calc(var(--a11y-min-size) / 2);
    align-items: center;
    justify-content: center;
    background-color: rgb(255, 255, 255);
    border-width: 2px;
    line-height: 1.5;
    transition: all 0.5s ease 0s;
  }
  .kol-table__selection-input--radio {
    display: flex;
    border-width: 2px;
    border-radius: 100%;
    height: 1.5em;
    min-height: 1.5em;
    min-width: 1.5em;
    padding: 0;
    width: 1.5em;
  }
  .kol-table__selection-input--radio:before {
    border-radius: 100%;
    margin: auto;
    height: 0.75em;
    width: 0.75em;
  }
  .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;
    }
  }
}
@layer kol-component {
  .kol-pagination {
    align-items: center;
    display: grid;
    gap: calc(16rem / var(--kolibri-root-font-size, 16));
    grid-template-columns: 1fr auto;
  }
  .kol-pagination__navigation-list {
    align-items: center;
    display: inline-flex;
    flex-wrap: wrap;
    gap: 0.5em;
    list-style: none;
    margin: 0;
    padding: 0;
  }
  .kol-pagination__separator:before {
    content: "•••";
  }
}
@layer kol-component {
  .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;
    }
  }
}`,L=[10,20,50,100],y=t=>t===!0||t===""||typeof t=="object"&&t!==null,V=class{constructor(t){S(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"},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 o=this.sortData[a],r=o.compareFn(e,i);if(r!==0)return o.direction==="ASC"?r:-r}return 0}),c(this,"_sortedData",n)}}validateAllowMultiSort(t){g(this,"_allowMultiSort",()=>!0,new Set(["boolean"]),t,{defaultValue:!1})}validateData(t){A(this,t,{afterPatch:()=>{setTimeout(this.updateSortedData)}})}validateDataFoot(t){F(this,t,{afterPatch:()=>{setTimeout(this.updateSortedData)}})}validatePaginationPosition(t){K(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){w(t,()=>{j(t,()=>{try{t=m(t)}catch{}g(this,"_headers",n=>typeof n=="object"&&n!==null,new Set(["KoliBriTableHeaders"]),t,{hooks:{beforePatch:n=>{var e,i,a,o;const r=_=>{let p=!1;_.forEach(l=>{const s=l.key;if(!s)return;const b=l.sortDirection;(b==="ASC"||b==="DESC")&&typeof l.compareFn=="function"&&((this.state._allowMultiSort||this.sortData.length===0)&&this.sortData.push({label:l.label,key:s,compareFn:l.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&&((o=d.vertical)===null||o===void 0?void 0:o.length)>0&&(this.disableSort=!0,O("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){E(this,t,{required:!0})}validateMinWidth(t){x(this,"_minWidth",t,{defaultValue:void 0})}validateSelection(t){W(this,t)}validateOn(t){H(this,t)}validateTableSettings(t){M(this,t)}validatePagination(t){try{t=m(t)}catch{}this.showPagination=y(t),g(this,"_pagination",y,new Set(["boolean","KoliBriTablePagination"]),t,{defaultValue:{_page:1,_pageSize:10,_max:0}})}componentDidLoad(){var t;(t=this.tableWcRef)===null||t===void 0||t.addEventListener(u.selectionChange,this.onSelectionChange)}disconnectedCallback(){var t;(t=this.tableWcRef)===null||t===void 0||t.removeEventListener(u.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)}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=f("kol-table-pagination-label",{placeholders:{label:`${this.state._label} (${f(`kol-pagination-position-${t}`)})`}});return h("div",{class:`kol-table-stateful__pagination kol-table-stateful__pagination--${this.state._paginationPosition}`},h("span",null,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"}})),h("div",{class:"kol-table-stateful__pagination-wrapper"},h(z,{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||L,_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!=null&&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(o=>t.includes(o[i]));if((e==null?void 0: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[k.onSelectionChange])=="function"&&this.state._on[k.onSelectionChange](t,a),this.host&&P(this.host,u.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,o;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,_=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(l=>l.map(s=>Object.assign(Object.assign({},s),{sortDirection:this.getHeaderCellSortState(s)}))))!==null&&i!==void 0?i:[],vertical:(o=(a=this.state._headers.vertical)===null||a===void 0?void 0:a.map(l=>l.map(s=>Object.assign(Object.assign({},s),{sortDirection:this.getHeaderCellSortState(s)}))))!==null&&o!==void 0?o:[]};return h(C,{key:"ae9fe552c93f1ef8273be72a54865e524abc550d",class:"kol-table-stateful"},this.pageEndSlice>0&&this.showPagination&&d,h(D,{key:"4409842d643b60aa5a19e31394e7ec40823d10e8",ref:this.catchRef,_data:r,_headerCells:p,_label:this.state._label,_dataFoot:this.state._dataFoot,_minWidth:this.state._minWidth,_on:{onSort:(l,s)=>{this.handleSort(s)},onSelectionChange:(l,s)=>{this.handleSelectionChange(l,s)}},_selection:this.state._selection,_tableSettings:this.state._tableSettings}),this.pageEndSlice>0&&this.showPagination&&_)}get host(){return T(this)}static get watchers(){return{_allowMultiSort:["validateAllowMultiSort"],_data:["validateData"],_dataFoot:["validateDataFoot"],_paginationPosition:["validatePaginationPosition"],_headers:["validateHeaders"],_label:["validateLabel"],_minWidth:["validateMinWidth"],_selection:["validateSelection"],_on:["validateOn"],_tableSettings:["validateTableSettings"],_pagination:["validatePagination"]}}};V.style={default:I};export{V as kol_table_stateful};
//# sourceMappingURL=kol-table-stateful.entry-wa4IDr7g.js.map
