/*!
 * KoliBri - The accessible HTML-Standard
 */
'use strict';

var index = require('./index-DBbl8tEq.js');
var componentNames = require('./component-names-5KS_pYRF.js');
var i18n = require('./i18n-DL7vJXNn.js');
var common = require('./common-DAAt5YQ7.js');
var ariaLabelledby = require('./aria-labelledby-BhnM3OnL.js');
var tableSelection = require('./table-selection-BzjiHUz6.js');
var label = require('./label-VzToxIES.js');
var keyboard = require('./keyboard-BfFtSnNy.js');
var events = require('./events-DN9qldnr.js');
require('./i18n-CgUN6lev.js');

const validateAllowMultiSort = (component, value, options = {}) => {
    common.watchBoolean(component, '_allowMultiSort', value, Object.assign({ defaultValue: false }, options));
};

const paginationPositionPropTypeOptions = ['top', 'bottom', 'both'];
const validatePaginationPosition = (component, value) => {
    common.watchValidator(component, `_paginationPosition`, (value) => typeof value === 'string' && paginationPositionPropTypeOptions.includes(value), new Set([`PaginationPositionPropType {${paginationPositionPropTypeOptions.join(', ')}`]), value, {
        defaultValue: 'bottom',
    });
};

const defaultStyleCss = "@charset \"UTF-8\";\n/*\n* This file defines the layer order for all CSS layers used in KoliBri.\n* The order is important as it determines the cascade priority.\n*\n* Layer order (lowest to highest priority):\n* 1. kol-a11y - Accessibility defaults and requirements\n* 2. kol-global - Global component styles and resets\n* 3. kol-component - Component-specific styles\n* 4. kol-theme-global - Theme-specific global styles\n* 5. kol-theme-component - Theme-specific component styles\n*/\n@layer kol-a11y, kol-global, kol-component, kol-theme-global, kol-theme-component;\n/* forward the rem function */\n/*\n * This file contains all rules for accessibility.\n */\n@layer kol-a11y {\n  :host {\n    /*\n                   * Minimum size of interactive elements.\n                   */\n    --a11y-min-size: calc(44 * 1rem / var(--kolibri-root-font-size, 16));\n    /*\n     * No element should be used without verifying the contrast ratio of its background and font colors.\n     * By initially setting the background color to white and the font color to black,\n     * the contrast ratio is ensured and explicit adjustment is forced.\n     */\n    color: black;\n    background-color: white;\n    /*\n     * Verdana is an accessible font that can be used without requiring additional loading time.\n     */\n    font-family: Verdana;\n    /*\n     * Letter spacing is required for all texts.\n     */\n    letter-spacing: inherit;\n    /*\n     * Word spacing is required for all texts.\n     */\n    word-spacing: inherit;\n    /*\n     * Text should be aligned left by default to provide a predictable starting point.\n     */\n    text-align: left;\n  }\n  * {\n    /*\n     * This rule enables the word dividing for all texts. That is important for high zoom levels.\n     */\n    hyphens: auto;\n    /*\n     * This rule enables the word dividing for all texts. That is important for high zoom levels.\n     */\n    word-break: break-word;\n  }\n  /*\n   * All interactive elements should have a minimum size of to-rem(44).\n   */\n  /* input:not([type='checkbox'], [type='radio'], [type='range']), */\n  /* option, */\n  /* select, */\n  /* textarea, */\n  button,\n  .kol-input .input {\n    min-width: var(--a11y-min-size);\n    min-height: var(--a11y-min-size);\n  }\n  /*\n   * Some interactive elements should not inherit the font-family and font-size.\n   */\n  a,\n  button,\n  h1,\n  h2,\n  h3,\n  h4,\n  h5,\n  h6,\n  input,\n  option,\n  select,\n  textarea {\n    /*\n     * All elements should inherit the text color from his parent element.\n     */\n    color: inherit;\n    /*\n     * All elements should inherit the font family from his parent element.\n     */\n    font-family: inherit;\n    /*\n     * All elements should inherit the font size from his parent element.\n     */\n    font-size: inherit;\n    /*\n     * Letter spacing is required for all texts.\n     */\n    letter-spacing: inherit;\n    /*\n     * Word spacing is required for all texts.\n     */\n    word-spacing: inherit;\n  }\n  /**\n  * Sometimes we need the semantic element for accessibility reasons,\n  * but we don't want to show it.\n  *\n  * - https://www.a11yproject.com/posts/how-to-hide-content/\n  */\n  .visually-hidden {\n    position: fixed;\n    top: 0;\n    left: 0;\n    width: 1px;\n    height: 1px;\n    overflow: hidden;\n    white-space: nowrap;\n    clip-path: inset(50%);\n  }\n}\n@layer kol-global {\n  /*\n   * Dieses CSS stellt sicher, dass der Standard-Style\n   * von A und Button resettet werden.\n   */\n  :is(a, button) {\n    background-color: transparent;\n    width: 100%;\n    margin: 0;\n    padding: 0;\n    border: none;\n    /* 100% needed for custom width from outside */\n  }\n  /*\n   * Ensure elements with hidden attribute to be actually not visible\n   * @see https://meowni.ca/hidden.is.a.lie.html\n   */\n  [hidden] {\n    display: none !important;\n  }\n  .badge-text-hint {\n    color: black;\n    background-color: white;\n  }\n}\n@layer kol-global {\n  :host {\n    /*\n     * The max-width is needed to prevent the table from overflowing the\n     * parent node, if the table is wider than the parent node.\n     */\n    max-width: 100%;\n    font-size: calc(16 * 1rem / var(--kolibri-root-font-size, 16));\n  }\n  * {\n    /*\n     * We prefer to box-sizing: border-box for all elements.\n     */\n    box-sizing: border-box;\n  }\n  .kol-span {\n    /* KolSpan is a layout component with icons in all directions and a label text in the middle. */\n    display: flex;\n    flex-flow: column;\n    align-items: center;\n    justify-content: center;\n    /* The sub span in KolSpan is the horizontal span with icon left and right and the label text in the middle. */\n  }\n  .kol-span__container {\n    display: flex;\n    align-items: center;\n  }\n  a,\n  button {\n    cursor: pointer;\n  }\n  .kol-span .kol-span__label--hide-label .kol-span__label {\n    display: none;\n  }\n  /* Reset browser agent style. */\n  button:disabled {\n    color: unset;\n  }\n  .disabled label,\n  .disabled:focus-within label,\n  [aria-disabled=true],\n  [aria-disabled=true]:focus,\n  [disabled],\n  [disabled]:focus {\n    outline: none;\n    cursor: not-allowed;\n  }\n  [aria-disabled=true]:focus .kol-span,\n  [disabled]:focus .kol-span {\n    outline: none !important;\n  }\n  .hastooltip {\n    z-index: 900 !important;\n  }\n}\n@layer kol-component {\n  :host {\n    display: block;\n  }\n}\n@font-face {\n  font-family: \"kolicons\";\n  src: url(\"kolicons.eot?t=1780914078349\"); /* IE9*/\n  src: url(\"kolicons.eot?t=1780914078349#iefix\") format(\"embedded-opentype\"), url(\"kolicons.woff2?t=1780914078349\") format(\"woff2\"), url(\"kolicons.woff?t=1780914078349\") format(\"woff\"), url(\"kolicons.ttf?t=1780914078349\") format(\"truetype\"), url(\"kolicons.svg?t=1780914078349#kolicons\") format(\"svg\"); /* iOS 4.1- */\n}\n@layer kol-component {\n  [class^=kolicon-], [class*=\" kolicon-\"] {\n    font-family: \"kolicons\";\n    font-style: normal;\n    font-weight: 400;\n    line-height: 1em;\n    -webkit-font-smoothing: antialiased;\n    -moz-osx-font-smoothing: grayscale;\n  }\n  .kolicon-alert-error::before {\n    content: \"\\ea01\";\n  }\n  .kolicon-alert-info::before {\n    content: \"\\ea02\";\n  }\n  .kolicon-alert-success::before {\n    content: \"\\ea03\";\n  }\n  .kolicon-alert-warning::before {\n    content: \"\\ea04\";\n  }\n  .kolicon-check::before {\n    content: \"\\ea05\";\n  }\n  .kolicon-chevron-double-left::before {\n    content: \"\\ea06\";\n  }\n  .kolicon-chevron-double-right::before {\n    content: \"\\ea07\";\n  }\n  .kolicon-chevron-down::before {\n    content: \"\\ea08\";\n  }\n  .kolicon-chevron-left::before {\n    content: \"\\ea09\";\n  }\n  .kolicon-chevron-right::before {\n    content: \"\\ea0a\";\n  }\n  .kolicon-chevron-up::before {\n    content: \"\\ea0b\";\n  }\n  .kolicon-cogwheel::before {\n    content: \"\\ea0c\";\n  }\n  .kolicon-cross::before {\n    content: \"\\ea0d\";\n  }\n  .kolicon-eye-closed::before {\n    content: \"\\ea0e\";\n  }\n  .kolicon-eye::before {\n    content: \"\\ea0f\";\n  }\n  .kolicon-house::before {\n    content: \"\\ea10\";\n  }\n  .kolicon-kolibri::before {\n    content: \"\\ea11\";\n  }\n  .kolicon-link-external::before {\n    content: \"\\ea12\";\n  }\n  .kolicon-link::before {\n    content: \"\\ea13\";\n  }\n  .kolicon-minus::before {\n    content: \"\\ea14\";\n  }\n  .kolicon-plus::before {\n    content: \"\\ea15\";\n  }\n  .kolicon-settings::before {\n    content: \"\\ea16\";\n  }\n  .kolicon-sort-asc::before {\n    content: \"\\ea17\";\n  }\n  .kolicon-sort-desc::before {\n    content: \"\\ea18\";\n  }\n  .kolicon-sort-neutral::before {\n    content: \"\\ea19\";\n  }\n  .kolicon-up::before {\n    content: \"\\ea1a\";\n  }\n  .kolicon-version::before {\n    content: \"\\ea1b\";\n  }\n}\n@layer kol-component {\n  .kol-icon {\n    color: inherit;\n    display: inline-block;\n    font-size: inherit;\n    font-weight: inherit;\n    line-height: inherit;\n  }\n  .kol-tooltip {\n    display: contents;\n  }\n  .kol-tooltip__floating {\n    opacity: 0;\n    display: none;\n    position: fixed;\n    /* Avoid layout interference - see https://floating-ui.com/docs/computePosition */\n    top: 0;\n    left: 0;\n    /* Can be used to specify the tooltip-width from the outside. Unset by default.  */\n    width: var(--kol-tooltip-width, max-content);\n    min-width: calc(8 * 1rem / var(--kolibri-root-font-size, 16));\n    max-width: 90vw;\n    max-height: 90vh;\n    animation-direction: normal;\n    /* Can be used to specify the animation duration from the outside. 250ms by default. */\n    animation-duration: var(--kolibri-tooltip-animation-duration, 250ms);\n    animation-fill-mode: forwards;\n    animation-iteration-count: 1;\n    animation-timing-function: ease-in;\n  }\n  .kol-tooltip__floating.hide {\n    animation-name: hideTooltip;\n  }\n  .kol-tooltip__floating.show {\n    animation-name: showTooltip;\n  }\n  .kol-tooltip__arrow {\n    transform: rotate(45deg);\n    color: black;\n    background-color: white;\n    position: absolute;\n    z-index: 999;\n    width: calc(10 * 1rem / var(--kolibri-root-font-size, 16));\n    height: calc(10 * 1rem / var(--kolibri-root-font-size, 16));\n  }\n  .kol-tooltip__content {\n    color: black;\n    background-color: white;\n    position: relative;\n    z-index: 1000;\n  }\n  @keyframes hideTooltip {\n    0% {\n      opacity: 1;\n    }\n    100% {\n      opacity: 0;\n      display: none;\n    }\n  }\n  @keyframes showTooltip {\n    0% {\n      opacity: 0;\n    }\n    100% {\n      opacity: 1;\n    }\n  }\n}\n@layer kol-component {\n  .kol-alert .kol-icon {\n    color: inherit;\n    display: inline-block;\n    font-size: inherit;\n    font-weight: inherit;\n    line-height: inherit;\n  }\n  .kol-alert :host {\n    display: inline-block;\n  }\n  .kol-alert .kol-button {\n    display: flex;\n    min-height: var(--a11y-min-size);\n    font-style: calc(16 * 1rem / var(--kolibri-root-font-size, 16));\n    text-decoration-line: none;\n  }\n  .kol-alert .kol-button::before {\n    /* Render zero-width character as first element to set the baseline correctly. */\n    content: \"​\";\n  }\n  .kol-alert .kol-button__text {\n    flex: 1 0 100%;\n  }\n  .kol-alert {\n    display: grid;\n  }\n  .kol-alert__container {\n    display: flex;\n    place-items: center;\n  }\n  .kol-alert__container-content {\n    flex-grow: 1;\n  }\n  .kol-alert__closer {\n    /* Visible with forced colors */\n    outline: transparent solid calc(1 * 1rem / var(--kolibri-root-font-size, 16));\n  }\n  .kol-icon {\n    color: inherit;\n    display: inline-block;\n    font-size: inherit;\n    font-weight: inherit;\n    line-height: inherit;\n  }\n  :host {\n    display: inline-block;\n  }\n  .kol-button {\n    display: flex;\n    min-height: var(--a11y-min-size);\n    font-style: calc(16 * 1rem / var(--kolibri-root-font-size, 16));\n    text-decoration-line: none;\n  }\n  .kol-button::before {\n    /* Render zero-width character as first element to set the baseline correctly. */\n    content: \"​\";\n  }\n  .kol-button__text {\n    flex: 1 0 100%;\n  }\n  .kol-popover-button__popover {\n    margin: 0;\n    padding: 0;\n    border: 0;\n  }\n  .kol-popover-button--inline .kol-popover-button__button {\n    display: inline;\n  }\n  .kol-popover {\n    opacity: 0;\n    transition: 0.2s ease-out opacity;\n  }\n  .kol-popover-button--open + .kol-popover {\n    opacity: 1;\n  }\n  .kol-table-settings {\n    position: absolute;\n    top: 0;\n    right: 0;\n    z-index: 1;\n  }\n  .kol-table-settings .kol-popover-button__popover {\n    background: white;\n    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);\n    border-radius: calc(8 * 1rem / var(--kolibri-root-font-size, 16));\n    border: 1px solid black;\n  }\n  .kol-table-settings__columns-container {\n    max-height: calc(200 * 1rem / var(--kolibri-root-font-size, 16));\n    overflow: auto;\n  }\n  .kol-table-settings__columns {\n    display: grid;\n    align-items: center;\n    grid-auto-rows: min-content;\n    grid-template-columns: min-content minmax(max-content, 1fr) calc(140 * 1rem / var(--kolibri-root-font-size, 16)) auto auto;\n  }\n  .kol-table-settings__column {\n    display: contents;\n  }\n  .kol-icon {\n    color: inherit;\n    display: inline-block;\n    font-size: inherit;\n    font-weight: inherit;\n    line-height: inherit;\n  }\n  .kol-table {\n    --kol-table-selection-col-width: var(--a11y-min-size);\n    display: block;\n    position: relative;\n    max-width: 100%;\n  }\n  .kol-table:has(.kol-table__focus-element:focus) .kol-table__scroll-container {\n    /* @see https://remysharp.com/til/css/focus-ring-default-styles */\n    outline: 5px auto Highlight;\n    outline: 5px auto -webkit-focus-ring-color;\n    outline-offset: 2px;\n  }\n  .kol-table__scroll-container {\n    overflow-x: auto;\n    overflow-y: hidden;\n  }\n  .kol-table__table {\n    table-layout: fixed;\n  }\n  .kol-table__caption {\n    min-height: var(--a11y-min-size);\n    text-align: start;\n  }\n  kol-table-settings-wc:not(:has(~ .kol-table__scroll-container .kol-table__caption)) {\n    display: block;\n    min-height: var(--a11y-min-size);\n  }\n  .kol-table__sort-button .kol-button {\n    color: inherit;\n  }\n  .kol-table__sort {\n    display: inline-flex;\n    align-items: center;\n  }\n  .kol-table__sort-order {\n    display: inline-flex;\n    align-items: center;\n    justify-content: center;\n  }\n  .kol-table__body {\n    text-align: left;\n  }\n  .kol-table__body .kol-button__text {\n    justify-items: start;\n  }\n  .kol-table__cell--align-left {\n    text-align: left;\n  }\n  .kol-table__cell--align-left .kol-button__text {\n    align-items: start;\n  }\n  .kol-table__cell--align-center {\n    text-align: center;\n  }\n  .kol-table__cell--align-center .kol-button__text {\n    align-items: center;\n  }\n  .kol-table__cell--align-right {\n    text-align: right;\n  }\n  .kol-table__cell--align-right .kol-button__text {\n    align-items: end;\n  }\n  .kol-table__cell--selection {\n    background-color: white;\n    position: sticky !important;\n    left: 0;\n    z-index: 2;\n    width: var(--kol-table-selection-col-width, auto);\n    min-width: var(--a11y-min-size);\n    min-height: var(--a11y-min-size);\n    white-space: nowrap;\n  }\n  .kol-table__cell--actions {\n    white-space: nowrap;\n  }\n  .kol-table__cell--actions .kol-icon {\n    color: inherit;\n    display: inline-block;\n    font-size: inherit;\n    font-weight: inherit;\n    line-height: inherit;\n  }\n  .kol-table__cell--actions :host {\n    display: inline-block;\n  }\n  .kol-table__cell--actions .kol-button {\n    display: flex;\n    min-height: var(--a11y-min-size);\n    font-style: calc(16 * 1rem / var(--kolibri-root-font-size, 16));\n    text-decoration-line: none;\n  }\n  .kol-table__cell--actions .kol-button::before {\n    /* Render zero-width character as first element to set the baseline correctly. */\n    content: \"​\";\n  }\n  .kol-table__cell--actions .kol-button__text {\n    flex: 1 0 100%;\n  }\n  .kol-table__cell--actions .kol-icon {\n    color: inherit;\n    display: inline-block;\n    font-size: inherit;\n    font-weight: inherit;\n    line-height: inherit;\n  }\n  .kol-table__cell--actions :host {\n    display: inline-block;\n  }\n  .kol-table__cell--actions .kol-link {\n    display: inline-flex;\n    max-width: fit-content;\n    align-items: baseline;\n    place-items: center;\n    text-align: left;\n    text-decoration-line: none;\n  }\n  .kol-table__cell--actions .kol-link--standalone {\n    min-width: var(--a11y-min-size);\n    min-height: var(--a11y-min-size);\n    align-items: stretch;\n  }\n  .kol-table__cell--actions .kol-link--standalone .kol-link__text {\n    display: inline-flex;\n    flex: 1 1 100%;\n    place-items: center;\n  }\n  .kol-table__cell--actions .kol-link .kol-span__label {\n    text-decoration-line: underline;\n  }\n  .kol-table__cell--actions .kol-link:focus:not([aria-disabled], [disabled]) .kol-span__label, .kol-table__cell--actions .kol-link:hover:not([aria-disabled], [disabled]) .kol-span__label {\n    text-decoration-thickness: 0.2em;\n  }\n  .kol-table__cell--actions .kol-link__icon {\n    display: inline-flex;\n  }\n  .kol-table__cell--sticky-left, .kol-table__cell--sticky-right {\n    background-color: white;\n    position: sticky !important;\n    z-index: 1;\n  }\n  .kol-table__cell--sticky-left:nth-last-child(1 of .kol-table__cell--sticky-left) {\n    border-right: 2px solid black;\n  }\n  .kol-table__cell--sticky-right:nth-child(1 of .kol-table__cell--sticky-left) {\n    border-left: 2px solid black;\n  }\n  .kol-table__cell-actions {\n    display: flex;\n    flex-wrap: wrap;\n    align-items: center;\n    justify-content: center;\n  }\n  .kol-table__spacer {\n    display: none;\n  }\n  .kol-table__selection {\n    position: relative;\n  }\n  .kol-table__selection-label {\n    display: flex;\n    position: relative;\n    min-width: var(--a11y-min-size);\n    min-height: var(--a11y-min-size);\n    align-items: center;\n    justify-content: center;\n    cursor: pointer;\n  }\n  .kol-table__selection--disabled {\n    cursor: not-allowed;\n  }\n  .kol-table__selection-icon {\n    display: block;\n    position: absolute;\n    inset: auto;\n    z-index: 1;\n  }\n  .kol-table__selection-input {\n    border-style: solid;\n    margin: 0;\n    appearance: none;\n    cursor: pointer;\n  }\n  .kol-table__selection-input:disabled {\n    cursor: not-allowed;\n  }\n  .kol-table__selection-input:before {\n    content: \"\";\n  }\n  .kol-table__selection-input--checkbox {\n    background-color: white;\n    display: flex;\n    position: relative;\n    min-width: calc(var(--a11y-min-size) / 2);\n    min-height: calc(var(--a11y-min-size) / 2);\n    border-width: 2px;\n    align-items: center;\n    justify-content: center;\n    line-height: 1.5;\n  }\n  .kol-table__selection-input--radio {\n    border-radius: 100%;\n    display: flex;\n    width: 1.5em;\n    min-width: 1.5em;\n    height: 1.5em;\n    min-height: 1.5em;\n    padding: 0;\n    border-width: 2px;\n  }\n  .kol-table__selection-input--radio:before {\n    border-radius: 100%;\n    width: 0.75em;\n    height: 0.75em;\n    margin: auto;\n  }\n  .kol-table__selection-input--radio:checked:before {\n    background-color: black;\n  }\n  @media (forced-colors: active) {\n    .kol-table__selection-input--radio:checked:before {\n      /* Give it a visible background in forced colors mode */\n      background-color: selectedItem !important;\n    }\n  }\n  .kol-alert .kol-icon {\n    color: inherit;\n    display: inline-block;\n    font-size: inherit;\n    font-weight: inherit;\n    line-height: inherit;\n  }\n  .kol-alert :host {\n    display: inline-block;\n  }\n  .kol-alert .kol-button {\n    display: flex;\n    min-height: var(--a11y-min-size);\n    font-style: calc(16 * 1rem / var(--kolibri-root-font-size, 16));\n    text-decoration-line: none;\n  }\n  .kol-alert .kol-button::before {\n    /* Render zero-width character as first element to set the baseline correctly. */\n    content: \"​\";\n  }\n  .kol-alert .kol-button__text {\n    flex: 1 0 100%;\n  }\n  .kol-alert {\n    display: grid;\n  }\n  .kol-alert__container {\n    display: flex;\n    place-items: center;\n  }\n  .kol-alert__container-content {\n    flex-grow: 1;\n  }\n  .kol-alert__closer {\n    /* Visible with forced colors */\n    outline: transparent solid calc(1 * 1rem / var(--kolibri-root-font-size, 16));\n  }\n  .kol-form-field {\n    display: grid;\n  }\n  .kol-form-field:not(.kol-form-field--disabled) .kol-form-field__label {\n    cursor: pointer;\n  }\n  .kol-form-field__label-text {\n    flex-flow: row;\n    align-items: flex-start;\n    justify-content: flex-start;\n  }\n  .kol-form-field--required .kol-form-field__label-text:has(.kol-span__slot[hidden])::after,\n  .kol-form-field--required .kol-tooltip__content .kol-span__label::after {\n    content: \"*\"/\"\";\n  }\n  .kol-input-container {\n    background-color: transparent;\n    display: grid;\n    position: relative;\n    width: 100%;\n    min-width: var(--a11y-min-size);\n    min-height: var(--a11y-min-size);\n    align-items: center;\n    grid-template-columns: 1fr;\n  }\n  .kol-input-container:has(> .kol-input-container__adornment--start) {\n    grid-template-columns: auto 1fr auto;\n  }\n  .kol-input-container__container {\n    position: relative;\n    z-index: 1;\n  }\n  .kol-input-container__adornment {\n    display: flex;\n    align-items: center;\n  }\n  .kol-input-container__adornment .kol-icon {\n    display: grid;\n    min-height: var(--a11y-min-size);\n    place-items: center;\n  }\n  .kol-select {\n    background-color: transparent;\n    width: 100%;\n    padding: 0;\n  }\n  .kol-select:not(:disabled) {\n    cursor: pointer;\n  }\n  .kol-select:not([multiple], [size]) {\n    height: 2.75em;\n  }\n  .kol-select:focus {\n    outline: none;\n  }\n  .kol-select__option:checked::before {\n    content: \"✓ \";\n  }\n  .kol-select[multiple] option {\n    display: flex;\n    min-height: var(--a11y-min-size);\n    align-items: center;\n  }\n  .kol-icon {\n    color: inherit;\n    display: inline-block;\n    font-size: inherit;\n    font-weight: inherit;\n    line-height: inherit;\n  }\n  .kol-pagination {\n    display: flex;\n    flex-wrap: wrap;\n    align-items: center;\n    justify-content: center;\n    container: paging/inline-size;\n  }\n  .kol-pagination__navigation-list {\n    display: inline-flex;\n    margin: 0;\n    padding: 0;\n    flex-wrap: wrap;\n    align-items: center;\n    list-style: none;\n  }\n  .kol-pagination__separator:before {\n    content: \"•••\";\n  }\n  .kol-pagination__page-size-select .kol-form-field-select {\n    align-items: center;\n    grid-template-columns: 1fr max-content;\n  }\n  @container paging (width < 600px) {\n    .kol-pagination:has(.kol-pagination__button--first) li:has(.kol-pagination__button--numbers),\n    .kol-pagination:has(.kol-pagination__button--first) li:has(.kol-pagination__separator) {\n      display: none;\n    }\n  }\n}";

const PAGINATION_OPTIONS = [10, 20, 50, 100];
const paginationValidator = (value) => value === true || value === '' || (typeof value === 'object' && value !== null);
const KolTableStateful = class {
    constructor(hostRef) {
        index.registerInstance(this, hostRef);
        this.resolvedElements = [];
        this.catchRef = (ref) => {
            this.tableWcRef = ref;
        };
        this.sortData = [];
        this.showPagination = false;
        this.pageStartSlice = 0;
        this.pageEndSlice = 10;
        this.disableSort = false;
        this._paginationPosition = 'bottom';
        this.state = {
            _allowMultiSort: false,
            _fixedCols: [0, 0],
            _data: [],
            _dataFoot: [],
            _headers: {
                horizontal: [],
                vertical: [],
            },
            _label: '',
            _pagination: {
                _page: 1,
                _pageSize: 10,
                _max: 0,
            },
            _sortedData: [],
            _paginationPosition: 'bottom',
            _hasSettingsMenu: false,
        };
        this.handlePagination = {
            onClick: (event, page) => {
                var _a;
                if (typeof ((_a = this.state._pagination._on) === null || _a === void 0 ? void 0 : _a.onClick) === 'function') {
                    this.state._pagination._on.onClick(event, page);
                }
                common.setState(this, '_pagination', Object.assign(Object.assign({}, this.state._pagination), { _page: page }));
            },
            onChangePage: (event, page) => {
                var _a;
                if (typeof ((_a = this.state._pagination._on) === null || _a === void 0 ? void 0 : _a.onChangePage) === 'function') {
                    this.state._pagination._on.onChangePage(event, page);
                }
                common.setState(this, '_pagination', Object.assign(Object.assign({}, this.state._pagination), { _page: page }));
            },
            onChangePageSize: (event, pageSize) => {
                var _a;
                if (typeof ((_a = this.state._pagination._on) === null || _a === void 0 ? void 0 : _a.onChangePageSize) === 'function') {
                    this.state._pagination._on.onChangePageSize(event, pageSize);
                }
                common.setState(this, '_pagination', Object.assign(Object.assign({}, this.state._pagination), { _pageSize: pageSize }));
                common.setState(this, '_pageSize', pageSize);
            },
        };
        this.onSelectionChange = (event) => {
            event.stopPropagation();
        };
        this.updateSortedData = () => {
            if (this.disableSort) {
                common.setState(this, '_sortedData', this.state._data);
                return;
            }
            const sortedData = [...this.state._data];
            if (this.sortData.length > 0) {
                sortedData.sort((a, b) => {
                    for (let index = 0; index < this.sortData.length; index++) {
                        const data = this.sortData[index];
                        const result = data.compareFn(a, b, data.direction);
                        if (result !== 0) {
                            return data.direction === 'ASC' ? result : -result;
                        }
                    }
                    return 0;
                });
            }
            common.setState(this, '_sortedData', sortedData);
        };
        this.handleChangeHeaderCells = (headerCells) => {
            this.adjustedHeaderCells = headerCells;
        };
    }
    validateAriaLabelledby(value) {
        this.syncExternalLabel(value);
    }
    syncExternalLabel(value) {
        this.resolvedElements = ariaLabelledby.validateAriaLabelledby(this, this.host, this.internals, value);
    }
    validateAllowMultiSort(value) {
        validateAllowMultiSort(this, value, { defaultValue: false });
    }
    validateData(value) {
        tableSelection.validateTableData(this, value, {
            afterPatch: () => {
                setTimeout(this.updateSortedData);
            },
        });
    }
    validateDataFoot(value) {
        tableSelection.validateTableDataFoot(this, value, {
            afterPatch: () => {
                setTimeout(this.updateSortedData);
            },
        });
    }
    validateFixedCols(value) {
        tableSelection.validateFixedCols(this, value);
    }
    validatePaginationPosition(value) {
        validatePaginationPosition(this, value);
    }
    validateHasSettingsMenu(value) {
        tableSelection.validateHasSettingsMenu(this, value);
    }
    changeCellSort(headerCell) {
        var _a;
        if (headerCell.type === undefined || headerCell.type === 'default') {
            if (typeof headerCell.compareFn !== 'function') {
                return;
            }
            if (!this.state._allowMultiSort && headerCell.key !== ((_a = this.sortData[0]) === null || _a === void 0 ? void 0 : _a.key)) {
                this.sortData = [];
            }
            const index = this.sortData.findIndex((value) => value.key === headerCell.key);
            if (index >= 0) {
                const settings = this.sortData[index];
                switch (settings.direction) {
                    case 'ASC':
                        settings.direction = 'DESC';
                        break;
                    case 'DESC':
                        this.sortData.splice(index, 1);
                        break;
                    default:
                        settings.direction = 'ASC';
                        break;
                }
            }
            else if (headerCell.key) {
                this.sortData.push({
                    label: headerCell.label,
                    key: headerCell.key,
                    compareFn: headerCell.compareFn,
                    direction: 'ASC',
                });
            }
            this.updateSortedData();
        }
    }
    initializeSortFromHeaders(headers) {
        var _a, _b;
        let hasSortedCells = false;
        const applySort = (cells) => {
            this.sortData = [];
            cells.forEach((cell) => {
                if (cell.type !== undefined && cell.type !== 'default') {
                    return;
                }
                if (typeof cell.compareFn === 'function' && !cell.key) {
                    common.devHint(`[KolTableStateful] A sortable column requires the 'key' property.`);
                    return;
                }
                const key = cell.key;
                if (!key) {
                    return;
                }
                const sortDirection = cell.sortDirection;
                if (sortDirection === 'ASC' || sortDirection === 'DESC') {
                    if (typeof cell.compareFn === 'function') {
                        if (this.state._allowMultiSort || this.sortData.length === 0) {
                            this.sortData.push({ label: cell.label, key, compareFn: cell.compareFn, direction: sortDirection });
                        }
                        hasSortedCells = true;
                    }
                }
            });
        };
        (_a = headers.horizontal) === null || _a === void 0 ? void 0 : _a.forEach(applySort);
        (_b = headers.vertical) === null || _b === void 0 ? void 0 : _b.forEach(applySort);
        return hasSortedCells;
    }
    validateHeaders(value) {
        common.emptyStringByArrayHandler(value, () => {
            common.objectObjectHandler(value, () => {
                try {
                    value = common.parseJson(value);
                }
                catch (_a) {
                }
                common.watchValidator(this, '_headers', (value) => typeof value === 'object' && value !== null, new Set(['KoliBriTableHeaders']), value, {
                    hooks: {
                        beforePatch: (nextValue) => {
                            var _a, _b;
                            const headers = nextValue;
                            if (this.headerKeysChanged(this.state._headers, headers)) {
                                this.adjustedHeaderCells = undefined;
                            }
                            const hasSortedCells = this.initializeSortFromHeaders(headers);
                            if (hasSortedCells) {
                                setTimeout(() => this.updateSortedData());
                            }
                            if (headers.horizontal && headers.vertical && ((_a = headers.horizontal) === null || _a === void 0 ? void 0 : _a.length) > 0 && ((_b = headers.vertical) === null || _b === void 0 ? void 0 : _b.length) > 0) {
                                this.disableSort = true;
                                common.devHint(`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(value) {
        label.validateLabel(this, value, {
            required: true,
        });
    }
    validateSelection(value) {
        tableSelection.validateTableSelection(this, value);
    }
    validateOn(value) {
        tableSelection.validateTableStatefulCallbacks(this, value);
    }
    validatePagination(value) {
        try {
            value = common.parseJson(value);
        }
        catch (_a) {
        }
        this.showPagination = paginationValidator(value);
        common.watchValidator(this, '_pagination', paginationValidator, new Set(['boolean', 'KoliBriTablePagination']), value, {
            defaultValue: {
                _page: 1,
                _pageSize: 10,
                _max: 0,
            },
        });
    }
    componentDidLoad() {
        var _a;
        (_a = this.tableWcRef) === null || _a === void 0 ? void 0 : _a.addEventListener(events.KolEvent.selectionChange, this.onSelectionChange);
        if (!this.resolvedElements.length) {
            this.syncExternalLabel(this._ariaLabelledby);
        }
    }
    disconnectedCallback() {
        var _a;
        (_a = this.tableWcRef) === null || _a === void 0 ? void 0 : _a.removeEventListener(events.KolEvent.selectionChange, this.onSelectionChange);
    }
    componentWillLoad() {
        this.internals = ariaLabelledby.attachInternals(this.host);
        this.syncExternalLabel(this._ariaLabelledby);
        this.validateAllowMultiSort(this._allowMultiSort);
        this.validateData(this._data);
        this.validateDataFoot(this._dataFoot);
        this.validateFixedCols(this._fixedCols);
        this.validateHeaders(this._headers);
        this.validateLabel(this._label);
        this.validateOn(this._on);
        this.validatePagination(this._pagination);
        this.validatePaginationPosition(this._paginationPosition);
        this.validateSelection(this._selection);
        this.validateHasSettingsMenu(this._hasSettingsMenu);
    }
    selectDisplayedData(data, pageSize, page) {
        if (typeof pageSize === 'number' && pageSize > 0 && typeof page === 'number' && page > 0) {
            this.pageStartSlice = pageSize * (page - 1);
            this.pageEndSlice = pageSize * page > data.length ? data.length : pageSize * page;
            return data.slice(this.pageStartSlice, this.pageEndSlice);
        }
        else {
            this.pageStartSlice = 0;
            this.pageEndSlice = data.length;
            return data;
        }
    }
    renderPagination(position) {
        const label = i18n.translate('kol-table-pagination-label', {
            placeholders: {
                label: `${this.state._label} (${i18n.translate(`kol-pagination-position-${position}`)})`,
            },
        });
        return (index.h("div", { class: `kol-table-stateful__pagination kol-table-stateful__pagination--${this.state._paginationPosition}` }, index.h("div", { class: "kol-table-stateful__pagination-wrapper" }, index.h(componentNames.KolPaginationWcTag, { _boundaryCount: this.state._pagination._boundaryCount, _customClass: this.state._pagination._customClass, _hasButtons: this.state._pagination._hasButtons, _on: this.handlePagination, _page: this.state._pagination._page, _pageSize: this.state._pagination._pageSize, _pageSizeOptions: this.state._pagination._pageSizeOptions || PAGINATION_OPTIONS, _siblingCount: this.state._pagination._siblingCount, _tooltipAlign: "bottom", _max: this.state._pagination._max || this.state._data.length, _label: label }))));
    }
    getHeaderCellSortState(headerCell) {
        if (headerCell.type !== undefined && headerCell.type !== 'default') {
            return;
        }
        if (!this.disableSort && typeof headerCell.compareFn === 'function') {
            if (headerCell.key) {
                const data = this.sortData.find((value) => value.key === headerCell.key);
                if (data === null || data === void 0 ? void 0 : data.direction) {
                    return data.direction;
                }
            }
            return 'NOS';
        }
    }
    getHeaderCellSortOrder(headerCell) {
        if (headerCell.type !== undefined && headerCell.type !== 'default') {
            return;
        }
        if (!this.disableSort && this.state._allowMultiSort && typeof headerCell.compareFn === 'function' && headerCell.key) {
            const index = this.sortData.findIndex((value) => value.key === headerCell.key);
            if (index >= 0) {
                return index + 1;
            }
        }
    }
    handleSort({ key }) {
        var _a, _b;
        const horizontalHeaders = (_a = this.state._headers.horizontal) !== null && _a !== void 0 ? _a : [];
        const verticalHeaders = (_b = this.state._headers.vertical) !== null && _b !== void 0 ? _b : [];
        const allHeaders = [];
        for (const row of horizontalHeaders) {
            if (Array.isArray(row)) {
                allHeaders.push(...row);
            }
        }
        for (const row of verticalHeaders) {
            if (Array.isArray(row)) {
                allHeaders.push(...row);
            }
        }
        const headerCell = allHeaders.find((cell) => cell.key === key);
        if (headerCell) {
            this.changeCellSort(headerCell);
        }
    }
    getSelectedData(selectedKeys) {
        var _a;
        const selection = this.state._selection;
        if (selection) {
            const keyPropertyName = (_a = selection.keyPropertyName) !== null && _a !== void 0 ? _a : 'id';
            const keySet = new Set(selectedKeys.map(String));
            const data = this.state._sortedData.filter((item) => keySet.has(String(item[keyPropertyName])));
            if (keyPropertyName)
                return data;
        }
        return null;
    }
    handleSelectionChange(event, selectedKeys) {
        var _a;
        const selection = this.state._selection;
        if (selection)
            this.state = Object.assign(Object.assign({}, this.state), { _selection: Object.assign(Object.assign({}, selection), { selectedKeys }) });
        const selectedData = this.getSelectedData(selectedKeys);
        if (typeof ((_a = this.state._on) === null || _a === void 0 ? void 0 : _a[keyboard.Callback.onSelectionChange]) === 'function') {
            this.state._on[keyboard.Callback.onSelectionChange](event, selectedData);
        }
        if (this.host) {
            events.dispatchDomEvent(this.host, events.KolEvent.selectionChange, selectedData);
        }
    }
    async getSelection() {
        var _a;
        const selectedKeys = ((_a = this.state._selection) === null || _a === void 0 ? void 0 : _a.selectedKeys) || [];
        return this.getSelectedData(selectedKeys);
    }
    async resetSort() {
        this.initializeSortFromHeaders(this.state._headers);
        this.updateSortedData();
    }
    headerKeysChanged(previous, next) {
        const getKeys = (headers) => {
            var _a, _b, _c, _d;
            return [
                ...((_b = (_a = headers.horizontal) === null || _a === void 0 ? void 0 : _a.flatMap((row) => row.map((cell) => cell === null || cell === void 0 ? void 0 : cell.key).filter((key) => Boolean(key)))) !== null && _b !== void 0 ? _b : []),
                ...((_d = (_c = headers.vertical) === null || _c === void 0 ? void 0 : _c.flatMap((column) => column.map((cell) => cell === null || cell === void 0 ? void 0 : cell.key).filter((key) => Boolean(key)))) !== null && _d !== void 0 ? _d : []),
            ];
        };
        const previousKeys = getKeys(previous);
        const nextKeys = getKeys(next);
        return previousKeys.length !== nextKeys.length || previousKeys.some((key, index) => key !== nextKeys[index]);
    }
    mergeAdjustedHeaderCells(adjusted) {
        var _a;
        const originalByKey = new Map();
        (_a = this.state._headers.horizontal) === null || _a === void 0 ? void 0 : _a.forEach((row) => row.forEach((cell) => {
            if (cell === null || cell === void 0 ? void 0 : cell.key) {
                originalByKey.set(cell.key, cell);
            }
        }));
        return adjusted.map((row) => row.map((cell) => {
            const original = (cell === null || cell === void 0 ? void 0 : cell.key) ? originalByKey.get(cell.key) : undefined;
            if (!original) {
                return cell;
            }
            const merged = Object.assign({}, original);
            if (cell.visible !== undefined)
                merged.visible = cell.visible;
            if (cell.width !== undefined)
                merged.width = cell.width;
            if (cell.hidable !== undefined)
                merged.hidable = cell.hidable;
            if (cell.sortable !== undefined)
                merged.sortable = cell.sortable;
            if (cell.resizable !== undefined)
                merged.resizable = cell.resizable;
            return merged;
        }));
    }
    buildHeaderCells() {
        var _a, _b, _c, _d;
        const overlaySortState = (cell) => cell
            ? Object.assign(Object.assign({}, cell), { sortDirection: this.getHeaderCellSortState(cell), sortOrder: this.getHeaderCellSortOrder(cell) }) : cell;
        const horizontalHeaders = ((_a = this.adjustedHeaderCells) === null || _a === void 0 ? void 0 : _a.horizontal)
            ? this.mergeAdjustedHeaderCells(this.adjustedHeaderCells.horizontal)
            : this.state._headers.horizontal;
        return {
            horizontal: (_b = horizontalHeaders === null || horizontalHeaders === void 0 ? void 0 : horizontalHeaders.map((row) => row.map(overlaySortState))) !== null && _b !== void 0 ? _b : [],
            vertical: (_d = (_c = this.state._headers.vertical) === null || _c === void 0 ? void 0 : _c.map((column) => column.map(overlaySortState))) !== null && _d !== void 0 ? _d : [],
        };
    }
    render() {
        var _a, _b;
        const displayedData = this.selectDisplayedData(this.state._sortedData, this.showPagination ? ((_b = (_a = this.state._pagination) === null || _a === void 0 ? void 0 : _a._pageSize) !== null && _b !== void 0 ? _b : 10) : this.state._sortedData.length, this.state._pagination._page || 1);
        const paginationTop = this._paginationPosition === 'top' || this._paginationPosition === 'both' ? this.renderPagination('top') : null;
        const paginationBottom = this._paginationPosition === 'bottom' || this._paginationPosition === 'both' ? this.renderPagination('bottom') : null;
        const headerCells = this.buildHeaderCells();
        return (index.h(index.Host, { key: '90a24351760bff3f69028dff8a3cde65a9648953', class: "kol-table-stateful" }, this.pageEndSlice > 0 && this.showPagination && paginationTop, index.h(componentNames.KolTableStatelessWcTag, { key: '4b3f6706a8c37ac9cbc741334d9d424e96c0d789', externalLabelElements: this.resolvedElements, ref: this.catchRef, _data: displayedData, _fixedCols: this._fixedCols, _headerCells: headerCells, _label: this.state._label, _dataFoot: this.state._dataFoot, _on: {
                onSort: (_, payload) => {
                    this.handleSort(payload);
                },
                onSelectionChange: (event, value) => {
                    this.handleSelectionChange(event, value);
                },
                onChangeHeaderCells: (_event, headerCells) => {
                    this.handleChangeHeaderCells(headerCells);
                },
            }, _selection: this.state._selection, _hasSettingsMenu: this.state._hasSettingsMenu, _variant: this._variant }), this.pageEndSlice > 0 && this.showPagination && paginationBottom));
    }
    get host() { return index.getElement(this); }
    static get watchers() { return {
        "_ariaLabelledby": ["validateAriaLabelledby"],
        "_allowMultiSort": ["validateAllowMultiSort"],
        "_data": ["validateData"],
        "_dataFoot": ["validateDataFoot"],
        "_fixedCols": ["validateFixedCols"],
        "_paginationPosition": ["validatePaginationPosition"],
        "_hasSettingsMenu": ["validateHasSettingsMenu"],
        "_headers": ["validateHeaders"],
        "_label": ["validateLabel"],
        "_selection": ["validateSelection"],
        "_on": ["validateOn"],
        "_pagination": ["validatePagination"]
    }; }
};
KolTableStateful.style = {
    default: defaultStyleCss
};

exports.kol_table_stateful = KolTableStateful;
//# sourceMappingURL=kol-table-stateful.entry.cjs.js.map
