// #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 { Component } from '../../../Decorators/ComponentDecorator';
import { CustomElement } from '../../Abstracts/CustomElement';
import { TableElement } from './TableElement';
import { tablerowElementTemplate } from './TableRowElementTemplate';
import { tableRowElementJoyStyle } from './Themes/TableRowElement.Joy';
import { tableRowElementRetroStyle } from './Themes/TableRowElement.Retro';
import { tableRowElementCosmopolitanStyle } from './Themes/TableRowElement.Cosmopolitan';
import { Themeable } from '../../../Behaviors/Themeable';
// #endregion
/**
 * Table Row - A horizontal grouping of table cells, representing a single data entry.
 *
 * @element mosaik-table-row
 *
 * @slot - The default slot.
 *
 * @public
 */
let TableRowElement = class TableRowElement extends Themeable(CustomElement) {
    // #region Fields
    _columnsChangedSubscription;
    _hasTableColumns;
    // #endregion
    // #region Ctor
    /**
     * @public
     */
    constructor() {
        super();
        this._columnsChangedSubscription = null;
        this._hasTableColumns = false;
    }
    // #endregion
    // #region Properties
    /**
     * Returns the `is` property.
     *
     * @public
     * @static
     * @readonly
    */
    static get is() {
        return 'mosaik-table-row';
    }
    // #endregion
    // #region Methods
    onSlotChange(event) {
        const slot = event.target;
        // only set the gridTemplateColumns when the parent table has no columns property.
        if (!this._hasTableColumns) {
            this.style.gridTemplateColumns = slot.assignedElements().map(() => '1fr')
                .join(' ');
        }
    }
    /**
     * @public
     * @override
     */
    disconnectedCallback() {
        super.disconnectedCallback();
        this._columnsChangedSubscription?.dispose();
    }
    /**
     * @protected
     * @override
     */
    onApplyTemplate() {
        const table = DomServiceLocator.current.findAncestor(this, TableElement);
        if (table) {
            if (table.columns) {
                this._hasTableColumns = true;
            }
            this.style.gridTemplateColumns = table.columns;
            this._columnsChangedSubscription = table.on('columnsChanged', (d) => {
                if (table.columns) {
                    this._hasTableColumns = true;
                }
                this.style.gridTemplateColumns = d.detail.columns;
            });
        }
    }
};
TableRowElement = __decorate([
    Component({
        selector: 'mosaik-table-row',
        template: tablerowElementTemplate,
        themes: {
            joy: tableRowElementJoyStyle,
            retro: tableRowElementRetroStyle,
            cosmopolitan: tableRowElementCosmopolitanStyle
        },
        imports: []
    }),
    __metadata("design:paramtypes", [])
], TableRowElement);
export { TableRowElement };
//# sourceMappingURL=TableRowElement.js.map