// #region Imports
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import { DomServiceLocator } from '../../../../Dom/Dom';
import { Selectable } from '../../../Behaviors/Selectable';
import { Themeable } from '../../../Behaviors/Themeable';
import { Valueable } from '../../../Behaviors/Valueable';
import { addInheritanceConsumerController } from '../../../Controllers/InheritanceConsumerController';
import { Component } from '../../../Decorators/ComponentDecorator';
import { TableSelectionMode } from '../../../Types/TableSelectionMode';
import { TableSelectionType } from '../../../Types/TableSelectionType';
import { TableRowBaseElement } from './Abstracts2/TableRowBaseElement';
import { TableBodyElement } from './TableBodyElement';
import { tableBodyRowElementTemplate } from './TableBodyRowElementTemplate';
import { TABLE_INHERITANCE_CONTEXT } from './TableInheritanceContext';
import { tableBodyRowElementCosmopolitanStyle } from './Themes/TableBodyRowElement.Cosmopolitan';
import { tableBodyRowElementJoyStyle } from './Themes/TableBodyRowElement.Joy';
import { tableBodyRowElementMemphisStyle } from './Themes/TableBodyRowElement.Memphis';
// #endregion
/**
 * Table Body Row - A selectable horizontal grouping of body cells within a table body section.
 *
 * @element mosaik-table-body-row
 *
 * @slot - The default slot for body cells.
 *
 * @cssprop {String} --table-body-row-border-color - The row border color CSS custom property.
 * @cssprop {String} --table-body-row-border-radius - The row border radius CSS custom property.
 * @cssprop {String} --table-body-row-border-style - The row border style CSS custom property.
 * @cssprop {String} --table-body-row-border-width - The row border width CSS custom property.
 * @cssprop {String} --table-body-row-font-family - The row font family CSS custom property.
 * @cssprop {String} --table-body-row-font-letter-spacing - The row font letter spacing CSS custom property.
 * @cssprop {String} --table-body-row-font-line-height - The row font line height CSS custom property.
 * @cssprop {String} --table-body-row-font-size - The row font size CSS custom property.
 * @cssprop {String} --table-body-row-font-text-decoration - The row font text decoration CSS custom property.
 * @cssprop {String} --table-body-row-font-text-transform - The row font text transform CSS custom property.
 * @cssprop {String} --table-body-row-font-weight - The row font weight CSS custom property.
 * @cssprop {String} --table-body-row-foreground-color - The row foreground color CSS custom property.
 * @cssprop {String} --table-body-row-gap - The row gap CSS custom property.
 * @cssprop {String} --table-body-row-padding-bottom - The row padding bottom CSS custom property.
 * @cssprop {String} --table-body-row-padding-left - The row padding left CSS custom property.
 * @cssprop {String} --table-body-row-padding-right - The row padding right CSS custom property.
 * @cssprop {String} --table-body-row-padding-top - The row padding top CSS custom property.
 * @cssprop {String} --table-body-row-shadow - The row shadow CSS custom property.
 * @cssprop {String} --table-body-row-shadow-blur - The row shadow blur CSS custom property.
 * @cssprop {String} --table-body-row-shadow-color - The row shadow color CSS custom property.
 * @cssprop {String} --table-body-row-shadow-offset-x - The row shadow offset x CSS custom property.
 * @cssprop {String} --table-body-row-shadow-offset-y - The row shadow offset y CSS custom property.
 * @cssprop {String} --table-body-row-shadow-spread - The row shadow spread CSS custom property.
 * @cssprop {String} --table-body-row-transition-duration - The row transition duration CSS custom property.
 * @cssprop {String} --table-body-row-transition-mode - The row transition mode CSS custom property.
 * @cssprop {String} --table-body-row-transition-property - The row transition property CSS custom property.
 * @cssprop {String} --table-body-row-translate - The row translate CSS custom property.
 *
 * @fires selected {SelectedEvent} - Fired when the row is selected.
 * @fires deselected {DeselectedEvent} - Fired when the row is deselected.
 *
 * @example
 * Selectable body row inside a table body:
 * ```html
 * <mosaik-table selection-mode="single" selection-type="row">
 *   <mosaik-table-body>
 *     <mosaik-table-body-row>
 *       <mosaik-table-body-cell text="Alice"></mosaik-table-body-cell>
 *       <mosaik-table-body-cell text="alice@example.com"></mosaik-table-body-cell>
 *     </mosaik-table-body-row>
 *   </mosaik-table-body>
 * </mosaik-table>
 * ```
 *
 * @public
 */
let TableBodyRowElement = class TableBodyRowElement extends Themeable(Valueable(Selectable(TableRowBaseElement))) {
    // #region Fields
    _inheritance = addInheritanceConsumerController(this, {
        context: TABLE_INHERITANCE_CONTEXT
    });
    _clickSubscription;
    _lastSelectionMode;
    _lastSelectionType;
    // #endregion
    // #region Ctor
    /**
     * @public
     */
    constructor() {
        super();
        this._clickSubscription = null;
        this._lastSelectionMode = TableSelectionMode.None;
        this._lastSelectionType = TableSelectionType.Row;
    }
    // #endregion
    // #region Properties
    /**
     * Returns the `is` property.
     *
     * @public
     * @static
     * @readonly
     */
    static get is() {
        return 'mosaik-table-body-row';
    }
    // #endregion
    // #region Methods
    /**
     * @public
     * @override
     */
    disconnectedCallback() {
        super.disconnectedCallback();
        this._clickSubscription?.dispose();
    }
    /**
     * @protected
     * @override
     */
    onApplyTemplate() {
        super.onApplyTemplate();
        this.updateSelectionClickHandler();
    }
    /**
     * Re-evaluates the click handler when inherited selection properties change.
     *
     * Note: `selectionMode` and `selectionType` are inherited via context, not
     * declared Lit properties. Lit's `requestUpdate` can silently skip updates
     * for undeclared properties, so we compare with tracked values.
     *
     * @protected
     * @override
     */
    updated(changedProperties) {
        super.updated(changedProperties);
        const selectionMode = this._inheritance.get('selectionMode', TableSelectionMode.None);
        const selectionType = this._inheritance.get('selectionType', TableSelectionType.Row);
        if (selectionMode !== this._lastSelectionMode || selectionType !== this._lastSelectionType) {
            this._lastSelectionMode = selectionMode;
            this._lastSelectionType = selectionType;
            this.updateSelectionClickHandler();
        }
    }
    /**
     * Sets up or tears down the click handler based on the inherited selection config.
     *
     * @private
     */
    updateSelectionClickHandler() {
        this._clickSubscription?.dispose();
        this._clickSubscription = null;
        const selectionMode = this._inheritance.get('selectionMode', TableSelectionMode.None);
        const selectionType = this._inheritance.get('selectionType', TableSelectionType.Row);
        if (selectionMode !== TableSelectionMode.None && selectionType === TableSelectionType.Row) {
            const isInBody = DomServiceLocator.current.findAncestor(this, TableBodyElement) !== null;
            if (isInBody && this._table) {
                this._clickSubscription = this.on('click', () => this.handleRowClick());
            }
        }
    }
    /**
     * Handles click events for row selection.
     *
     * @private
     */
    handleRowClick() {
        if (this.disabled || !this._table) {
            return;
        }
        this._table.handleRowSelect(this);
    }
};
TableBodyRowElement = __decorate([
    Component({
        selector: 'mosaik-table-body-row',
        template: tableBodyRowElementTemplate,
        themes: {
            joy: tableBodyRowElementJoyStyle,
            memphis: tableBodyRowElementMemphisStyle,
            cosmopolitan: tableBodyRowElementCosmopolitanStyle
        },
        imports: []
    }),
    __metadata("design:paramtypes", [])
], TableBodyRowElement);
export { TableBodyRowElement };
//# sourceMappingURL=TableBodyRowElement.js.map