// #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 { HTMLElementEventEmitter } from '@breadstone/mosaik-elements';
import { getSlotElements } from '../../../../Dom/Slot';
import { Emit } from '../../../../events/Decorators/EmitDecorator';
import { Disableable } from '../../../Behaviors/Disableable';
import { Fitable } from '../../../Behaviors/Fitable';
import { Slottable } from '../../../Behaviors/Slottable';
import { Themeable } from '../../../Behaviors/Themeable';
import { addInheritanceProviderController } from '../../../Controllers/InheritanceProviderController';
import { Attribute } from '../../../Decorators/AttributeDecorator';
import { Component } from '../../../Decorators/ComponentDecorator';
import { Watch } from '../../../Decorators/WatchDecorator';
import { ToolbarElement } from '../../Grouping/Toolbar/ToolbarElement';
import { TitleLayoutElement } from '../../Layouts/Title/TitleLayoutElement';
import { SelectorElement } from '../Abstracts/Selector/SelectorElement';
import { wizardElementCosmopolitanStyle } from './Themes/WizardElement.Cosmopolitan';
import { wizardElementJoyStyle } from './Themes/WizardElement.Joy';
import { wizardElementMemphisStyle } from './Themes/WizardElement.Memphis';
import { wizardElementTemplate } from './WizardElementTemplate';
import { WIZARD_INHERITANCE_CONTEXT } from './WizardInheritanceContext';
import { WizardStepElement } from './WizardStepElement';
// #endregion
/**
 * Wizard - A component that allows users to navigate through steps to complete a task.
 *
 * @element mosaik-wizard
 * @category Selector
 *
 * @slot footer - The footer slot.
 * @slot header - The header slot.
 * @slot header-after - The header after slot.
 * @slot header-before - The header before slot.
 * @slot steps - The steps slot.
 *
 * @csspart content - The content part.
 * @csspart footer - The footer part.
 * @csspart header - The header part.
 * @csspart toolbar - The toolbar part.
 *
 * @cssprop {String} --wizard-border-color - The border color CSS custom property.
 * @cssprop {String} --wizard-font-family - The font family CSS custom property.
 * @cssprop {String} --wizard-font-letter-spacing - The font letter spacing CSS custom property.
 * @cssprop {String} --wizard-font-line-height - The font line height CSS custom property.
 * @cssprop {String} --wizard-font-size - The font size CSS custom property.
 * @cssprop {String} --wizard-font-text-decoration - The font text decoration CSS custom property.
 * @cssprop {String} --wizard-font-text-transform - The font text transform CSS custom property.
 * @cssprop {String} --wizard-font-weight - The font weight CSS custom property.
 * @cssprop {String} --wizard-gap - The gap CSS custom property.
 * @cssprop {String} --wizard-padding-bottom - The padding bottom CSS custom property.
 * @cssprop {String} --wizard-padding-left - The padding left CSS custom property.
 * @cssprop {String} --wizard-padding-right - The padding right CSS custom property.
 * @cssprop {String} --wizard-padding-top - The padding top CSS custom property.
 * @cssprop {String} --wizard-shadow - The shadow CSS custom property.
 * @cssprop {String} --wizard-shadow-blur - The shadow blur CSS custom property.
 * @cssprop {String} --wizard-shadow-color - The shadow color CSS custom property.
 * @cssprop {String} --wizard-shadow-offset-x - The shadow offset x CSS custom property.
 * @cssprop {String} --wizard-shadow-offset-y - The shadow offset y CSS custom property.
 * @cssprop {String} --wizard-shadow-spread - The shadow spread CSS custom property.
 * @cssprop {String} --wizard-transition-duration - The transition duration CSS custom property.
 * @cssprop {String} --wizard-transition-mode - The transition mode CSS custom property.
 * @cssprop {String} --wizard-transition-property - The transition property CSS custom property.
 * @cssprop {String} --wizard-translate - The translate CSS custom property.
 *
 * @fires activeStepChanged {ActiveStepChangedEvent} - Fired when the active step has changed.
 *
 * @dependency mosaik-title-layout - The Title Layout element.
 * @dependency mosaik-toolbar - The Toolbar element.
 *
 * @example
 * Basic wizard with steps:
 * ```html
 * <mosaik-wizard>
 *   <mosaik-wizard-step header="Welcome" is-active>
 *     <p>Welcome to the setup wizard.</p>
 *   </mosaik-wizard-step>
 *   <mosaik-wizard-step header="Configuration">
 *     <p>Configure your preferences.</p>
 *   </mosaik-wizard-step>
 *   <mosaik-wizard-step header="Finish">
 *     <p>Setup complete!</p>
 *   </mosaik-wizard-step>
 * </mosaik-wizard>
 * ```
 *
 * @public
 */
let WizardElement = class WizardElement extends Themeable(Slottable(Fitable(Disableable(SelectorElement)))) {
    // #region Fields
    _provider = addInheritanceProviderController(this, {
        context: WIZARD_INHERITANCE_CONTEXT,
        values: () => ({
            disabled: this.disabled
        })
    });
    _activeStepChanged;
    _name;
    // #endregion
    // #region Ctor
    /**
     * @public
     */
    constructor() {
        super();
        this._name = '';
        this._activeStepChanged = new HTMLElementEventEmitter(this, 'activeStepChanged');
    }
    // #endregion
    // #region Properties
    /**
     * Returns the `is` property.
     * The `is` property represents natural name of this element.
     *
     * @public
     * @static
     * @override
     * @readonly
     */
    // eslint-disable-next-line @typescript-eslint/ban-ts-comment
    // @ts-ignore
    static get is() {
        return 'mosaik-wizard';
    }
    /**
     * Gets or sets the `name` property.
     *
     * @public
     * @attr
     */
    get name() {
        return this._name;
    }
    set name(value) {
        if (this._name !== value) {
            this._name = value;
            this.requestUpdate('name');
        }
    }
    /**
     * Returns the `items` property.
     *
     * @public
     * @override
     * @readonly
     */
    get items() {
        return getSlotElements(this.shadowRoot, 'steps');
    }
    /**
     * Gets the active index of the wizard.
     *
     * @public
     * @readonly
     */
    get activeIndex() {
        return this.items.findIndex((x) => x.isActive);
    }
    /**
     * Gets the first step of the wizard.
     *
     * @public
     * @readonly
     */
    get isFirstStep() {
        return this.activeIndex === 0;
    }
    /**
     * Gets the last step of the wizard.
     *
     * @public
     * @readonly
     */
    get isLastStep() {
        return this.activeIndex === this.items.length - 1;
    }
    /**
     * Called when the active step has changed.
     * Provides reference to `IEventDetail` as event detail.
     *
     * @public
     * @readonly
     * @eventProperty
     */
    get activeStepChanged() {
        return this._activeStepChanged;
    }
    // #endregion
    // #region Methods
    /**
     * @protected
     * @template
     */
    onSlotChange() {
        this.requestUpdate('items');
        this.ensureActiveStep();
    }
    /**
     * Ensures that at least one step is active.
     * If no step is active, the first step will be selected.
     *
     * @protected
     */
    ensureActiveStep() {
        const { items } = this;
        if (items.length === 0) {
            return;
        }
        const hasActiveStep = items.some((x) => x.isActive);
        if (!hasActiveStep) {
            this.select(0);
        }
    }
    /**
     * @protected
     * @override
     */
    onSelectionChanged(oldIndex, newIndex) {
        if (oldIndex === newIndex) {
            return;
        }
        const items = this.items;
        const args = {
            cancel: false,
            oldStep: items[oldIndex],
            previousIndex: oldIndex,
            newStep: items[newIndex],
            newIndex: newIndex,
            direction: newIndex > oldIndex ? 'forward' : 'backward',
            totalSteps: items.length
        };
        this.onActiveStepChanged(args);
        if (!args.cancel) {
            super.onSelectionChanged(oldIndex, newIndex);
        }
    }
    /**
     * Emits the `activeStepChanged` event.
     *
     * @protected
     */
    onActiveStepChanged(args) {
        this._activeStepChanged.emit(args);
    }
    /**
     * @protected
     */
    onSelectedIndexPropertyChanged(_prev, next) {
        const { items } = this;
        const { length } = items;
        for (let i = 0; i < length; i++) {
            const item = items[i];
            item.isActive = i === next;
        }
    }
};
__decorate([
    Attribute({ type: String }),
    __metadata("design:type", String),
    __metadata("design:paramtypes", [String])
], WizardElement.prototype, "name", null);
__decorate([
    Emit({ eventName: 'activeStepChanged' }),
    __metadata("design:type", Object),
    __metadata("design:paramtypes", [])
], WizardElement.prototype, "activeStepChanged", null);
__decorate([
    Watch('selectedIndex'),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Number, Number]),
    __metadata("design:returntype", void 0)
], WizardElement.prototype, "onSelectedIndexPropertyChanged", null);
WizardElement = __decorate([
    Component({
        selector: 'mosaik-wizard',
        template: wizardElementTemplate,
        themes: {
            joy: wizardElementJoyStyle,
            memphis: wizardElementMemphisStyle,
            cosmopolitan: wizardElementCosmopolitanStyle
        },
        options: {
            mode: 'open',
            delegatesFocus: true
        },
        host: {
            tabIndex: '0',
            role: 'tablist'
        },
        imports: [
            WizardStepElement,
            ToolbarElement,
            TitleLayoutElement
        ]
    }),
    __metadata("design:paramtypes", [])
], WizardElement);
export { WizardElement };
//# sourceMappingURL=WizardElement.js.map