import { HttpParams } from '@angular/common/http';
import * as i0 from '@angular/core';
import { input, output, Component, NgModule } from '@angular/core';
import { elementSortUp, elementSortDown } from '@siemens/element-icons';
import { addIcons, SiIconComponent } from '@siemens/element-ng/icon';
import { t, SiTranslatePipe } from '@siemens/element-translate-ng/translate';

/**
 * Copyright (c) Siemens 2016 - 2026
 * SPDX-License-Identifier: MIT
 */
/**
 * @deprecated SiSortBarComponent originate from the older design system and do not align with current
 * design guidelines. No known use case exists for this component.
 * It will be removed in v50.
 */
class SiSortBarComponent {
    /**
     * Custom sort title.
     *
     * @defaultValue
     * ```
     * t(() => $localize`:@@SI_SORT_BAR.TITLE:Sort by`)
     * ```
     */
    sortTitle = input(t(() => $localize `:@@SI_SORT_BAR.TITLE:Sort by`), ...(ngDevMode ? [{ debugName: "sortTitle" }] : []));
    /**
     * List of sort criteria.
     */
    sortCriteria = input.required(...(ngDevMode ? [{ debugName: "sortCriteria" }] : []));
    /**
     * `key` which sortCriteria is active by default.
     */
    defaultSortCriteria = input.required(...(ngDevMode ? [{ debugName: "defaultSortCriteria" }] : []));
    /**
     * Output callback event will provide you with a HttpParams object if active
     * sortCriteria change.
     */
    sortChange = output();
    icons = addIcons({ elementSortDown, elementSortUp });
    activeSortCriteria = '';
    sortIsDescending = false;
    ngOnInit() {
        const defaultSortCriteria = this.defaultSortCriteria();
        if (defaultSortCriteria) {
            this.setActive(defaultSortCriteria);
        }
    }
    setActive(key) {
        if (this.activeSortCriteria === key) {
            this.sortIsDescending = !this.sortIsDescending;
        }
        this.activeSortCriteria = key;
        const searchParams = new HttpParams()
            .set('sort', this.activeSortCriteria)
            .set('order', this.sortIsDescending ? 'desc' : 'asc');
        this.sortChange.emit(searchParams);
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.8", ngImport: i0, type: SiSortBarComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
    static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.0.8", type: SiSortBarComponent, isStandalone: true, selector: "si-sort-bar", inputs: { sortTitle: { classPropertyName: "sortTitle", publicName: "sortTitle", isSignal: true, isRequired: false, transformFunction: null }, sortCriteria: { classPropertyName: "sortCriteria", publicName: "sortCriteria", isSignal: true, isRequired: true, transformFunction: null }, defaultSortCriteria: { classPropertyName: "defaultSortCriteria", publicName: "defaultSortCriteria", isSignal: true, isRequired: true, transformFunction: null } }, outputs: { sortChange: "sortChange" }, ngImport: i0, template: "<div class=\"list-header list-header-sorting\">\n  <div class=\"list-title\">{{ sortTitle() | translate }}:</div>\n  @for (item of sortCriteria(); track $index) {\n    <div\n      class=\"sort-item\"\n      tabindex=\"0\"\n      [attr.data-key]=\"item.key\"\n      (click)=\"setActive(item.key)\"\n      (keydown.enter)=\"setActive(item.key)\"\n    >\n      <span>{{ item.name | translate }}</span>\n      @if (item.key === activeSortCriteria) {\n        <si-icon\n          class=\"icon\"\n          [icon]=\"sortIsDescending ? icons.elementSortDown : icons.elementSortUp\"\n        />\n      }\n    </div>\n  }\n</div>\n", styles: [".list-title{font-weight:500;margin-inline-end:5px}.list-header-sorting{background:var(--element-ui-4);padding:6px 12px;display:flex;align-items:center}.sort-item{padding-block:0;padding-inline:5px;cursor:pointer;display:flex;align-items:center;gap:2px}\n"], dependencies: [{ kind: "component", type: SiIconComponent, selector: "si-icon", inputs: ["icon"] }, { kind: "pipe", type: SiTranslatePipe, name: "translate" }] });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.8", ngImport: i0, type: SiSortBarComponent, decorators: [{
            type: Component,
            args: [{ selector: 'si-sort-bar', imports: [SiIconComponent, SiTranslatePipe], template: "<div class=\"list-header list-header-sorting\">\n  <div class=\"list-title\">{{ sortTitle() | translate }}:</div>\n  @for (item of sortCriteria(); track $index) {\n    <div\n      class=\"sort-item\"\n      tabindex=\"0\"\n      [attr.data-key]=\"item.key\"\n      (click)=\"setActive(item.key)\"\n      (keydown.enter)=\"setActive(item.key)\"\n    >\n      <span>{{ item.name | translate }}</span>\n      @if (item.key === activeSortCriteria) {\n        <si-icon\n          class=\"icon\"\n          [icon]=\"sortIsDescending ? icons.elementSortDown : icons.elementSortUp\"\n        />\n      }\n    </div>\n  }\n</div>\n", styles: [".list-title{font-weight:500;margin-inline-end:5px}.list-header-sorting{background:var(--element-ui-4);padding:6px 12px;display:flex;align-items:center}.sort-item{padding-block:0;padding-inline:5px;cursor:pointer;display:flex;align-items:center;gap:2px}\n"] }]
        }], propDecorators: { sortTitle: [{ type: i0.Input, args: [{ isSignal: true, alias: "sortTitle", required: false }] }], sortCriteria: [{ type: i0.Input, args: [{ isSignal: true, alias: "sortCriteria", required: true }] }], defaultSortCriteria: [{ type: i0.Input, args: [{ isSignal: true, alias: "defaultSortCriteria", required: true }] }], sortChange: [{ type: i0.Output, args: ["sortChange"] }] } });

/**
 * Copyright (c) Siemens 2016 - 2026
 * SPDX-License-Identifier: MIT
 */
/**
 * @deprecated SiSortBarModule originate from the older design system and do not align with current
 * design guidelines. No known use case exists for this module and component.
 * It will be removed in v50.
 */
class SiSortBarModule {
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.8", ngImport: i0, type: SiSortBarModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
    static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "21.0.8", ngImport: i0, type: SiSortBarModule, imports: [SiSortBarComponent], exports: [SiSortBarComponent] });
    static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "21.0.8", ngImport: i0, type: SiSortBarModule, imports: [SiSortBarComponent] });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.8", ngImport: i0, type: SiSortBarModule, decorators: [{
            type: NgModule,
            args: [{
                    imports: [SiSortBarComponent],
                    exports: [SiSortBarComponent]
                }]
        }] });

/**
 * Copyright (c) Siemens 2016 - 2026
 * SPDX-License-Identifier: MIT
 */

/**
 * Generated bundle index. Do not edit.
 */

export { SiSortBarComponent, SiSortBarModule };
//# sourceMappingURL=siemens-element-ng-sort-bar.mjs.map
