@use 'sass:map';
@use 'sass:list';

$icon-mapping: (
    filter: '\ea41',
    asc: '\e900',
    desc: '\e901',
    excel: '\ea11',
    last: '\e952',
    none: '\ea62',
    right: '\e903',
    small-right: '\ea31',
    tree-indeterminate: '\e954',
    arrows: '\ec11',
    cross: '\e913',
    first: '\e951',
    left: '\e902',
    menu: '\e928',
    save: '\e917',
    eye-slash: '\ea52',
    tick: '\e911',
    copy: '\ea35',
    eye: '\ea54',
    small-left: '\ea28',
    small-down: '\e90a',
);

// ICONS where we already want to use the allianz icon font
// we override this for each icon separately until we have the full set
.ag-theme-allianz-icons .ag-icon {
    @each $icon-name, $character in $icon-mapping {
        --ag-icon-font-code-#{$icon-name}: '#{$character}';
    }

    $icon-selectors: ();
    @each $icon-name, $character in $icon-mapping {
        $icon-selectors: map.set($icon-selectors, unquote('&.ag-icon-#{$icon-name}'), $character);
    }
    $joined: list.join(map.keys($icon-selectors), (), comma);
    #{$joined} {
        --ag-icon-font-family: Allianz-Icons;
    }
}

.ag-theme-aquila {
    --ag-card-radius: 4px;
    --ag-background-color: var(--ui-01);
    --ag-modal-overlay-background-color: var(--ui-01);
    --ag-control-panel-background-color: var(--ui-01);
    --ag-popup-shadow: var(--shadow-small);
    --ag-card-shadow: var(--shadow-large);
    --ag-font-family: var(--font-family);
    --ag-header-background-color: var(--table-header-cell-background-color);
    --ag-font-size: var(--table-header-cell-font-size);
    --ag-odd-row-background-color: var(--table-row-background-color);
    --ag-row-border-color: var(--table-cell-border-top-color);
    --ag-row-height: 56px;
    --ag-input-focus-box-shadow: var(--formfield-outline-focus-box-shadow);
    --ag-input-focus-border-color: var(--formfield-outline-active-border-color);
    --ag-checkbox-unchecked-color: var(--checkbox-border-color);
    --ag-checkbox-checked-color: var(--checkbox-selected-background-color);
    --ag-row-hover-color: var(--selectable-table-row-hover-background-color);
    --ag-selected-row-background-color: var(--zebra-table-row-selected-background-color);
    --ag-header-column-resize-handle-color: var(--table-resize-handle-color);
    --ag-header-column-separator-color: var(--table-resize-handle-color);
    --ag-header-column-resize-handle-height: 50%;
    --ag-border-radius: 4px;
    --ag-widget-vertical-spacing: 12px;
    --ag-cell-horizontal-padding: 16px;
    --ag-border-color: var(--ui-04);
    --ag-foreground-color: var(--text-01);
    --ag-disabled-foreground-color: var(--disabled-01);
    --ag-input-disabled-background-color: var(--formfield-background-color);
    --ag-input-disabled-border-color: var(--formfield-disabled-border-color);
    // that might need adjustment don't know where that is used
    --ag-chip-background-color: var(--ui-01);
    --ag-input-border-color: var(--formfield-outline-border-color);
    --ag-range-selection-border-color: var(--selectable-table-row-selected-border-color);

    // creates the spacing of the group header border to the resize handles
    // by hiding parts of the border with the properly positioned pseudo elements
    // a bit hacky but works :)
    .ag-header-group-cell {
        &:before,
        &:after {
            content: ' ';
            width: 8px;
            position: absolute;
            height: 100%;
            background-color: var(--ag-background-color);
            top: 50%;
            z-index: 2;
            display: block;
        }

        &:before {
            left: 0;
        }

        &::after {
            right: 2px;
        }
    }

    // safari fix that the before and after from above are placed on top of the border
    .ag-header-row-column-group {
        z-index: 1;
    }

    .ag-header-row:has(+ .ag-header-row-column-filter) {
        --ag-header-column-resize-handle-height: 67px;

        .ag-header-cell {
            overflow: visible !important;
        }

        .ag-header-cell-resize::after {
            top: 12px;
        }

        .ag-header-cell.ag-header-span-height {
            .ag-header-cell-resize::after {
                height: 112px;
            }
        }
    }

    .ag-header-row-column-group:has(+ .ag-header-row) {
        .ag-header-cell-resize::after {
            height: calc(200% - var(--ag-grid-size) * 4);
        }
    }

    .ag-cell-focus:not(.ag-cell-range-selected):focus-within {
        border-left-width: 2px;
        border-right-width: 2px;
    }

    .ag-floating-filter-button-button {
        color: var(--interactive-text);
    }

    .ag-floating-filter-input input {
        color: var(--formfield-input-color);
        font-weight: var(--formfield-outline-control-font-weight);
        border-top-right-radius: 0 !important;
        border-bottom-right-radius: 0 !important;
    }

    .ag-input-field-input {
        &:focus {
            color: var(--formfield-active-color);
        }
    }

    .ag-floating-filter-button {
        margin-left: 0;
        width: calc(var(--ag-icon-size) + 14px);
        height: 32px;
        display: flex;
        align-items: center;
        justify-content: center;
        border: var(--ag-borders-input) var(--ag-input-border-color);
        border-radius: var(--ag-border-radius);
        border-top-left-radius: 0;
        border-bottom-left-radius: 0;
    }

    .ag-floating-filter-input input {
        border-right: none;

        &:focus {
            border-right: var(--ag-borders-input) var(--ag-input-border-color);
        }
    }

    .ag-floating-filter-input .ag-disabled {
        input:disabled {
            border-right: none;
            color: var(--formfield-disabled-text-color);
        }
    }

    .ag-selection-checkbox {
        margin-right: 16px;
    }

    // move the popup slightly away from the icon
    .ag-popup-child {
        margin-top: 8px;
    }

    .ag-header-row {
        font-weight: 600;
    }

    .ag-header {
        border-bottom: 2px solid var(--table-header-border-bottom-color);
    }

    .ag-root-wrapper {
        border: none;
        border-bottom: 2px solid var(--table-border-bottom-color);
    }

    .ag-row {
        font-size: var(--ag-font-size);
    }
    .ag-cell {
        -webkit-font-smoothing: antialiased;
    }

    input[class^='ag-'][type='text'] {
        min-height: 32px;
    }

    .ag-select .ag-picker-field-wrapper {
        min-height: 32px;
        border: var(--ag-borders-input) var(--ag-input-border-color);
        border-radius: var(--ag-border-radius);

        & .ag-picker-field-icon {
            margin-right: 8px;
        }
    }

    .ag-floating-filter {
        border-top: none !important;
    }

    .ag-header-row {
        --ag-header-height: 44px;
    }

    .ag-row-hover.ag-row-selected::before {
        background-color: var(--selectable-table-row-selected-hover-background-color);
        background-image: none;
    }

    // pagination
    .ag-paging-button {
        color: var(--pagination-link-color);
        &.ag-disabled {
            color: var(--pagination-link-disabled-color);
            cursor: not-allowed;
        }
    }

    // hide the "1 to 100 of xxxxx" on mobile that the pagination doesn't line break
    @media (max-width: 475px) {
        .ag-paging-row-summary-panel {
            display: none;
        }
    }
}

.ag-theme-aquila-dense {
    --ag-row-height: 40px;
}

.ag-theme-aquila-zebra {
    --ag-odd-row-background-color: var(--zebra-table-even-row-background-color);
    --ag-row-border-style: none;
}

.ag-dnd-ghost {
    box-shadow: 0 0 24px 0 rgba(65, 65, 65, 0.35);
    border: 0;
}
