// #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 { Emit } from '../../../../events/Decorators/EmitDecorator';
import { Disableable } from '../../../Behaviors/Disableable';
import { Fitable } from '../../../Behaviors/Fitable';
import { Orientable } from '../../../Behaviors/Orientable';
import { Slottable } from '../../../Behaviors/Slottable';
import { Themeable } from '../../../Behaviors/Themeable';
import { addInheritanceProviderController } from '../../../Controllers/InheritanceProviderController';
import { Component } from '../../../Decorators/ComponentDecorator';
import { Watch } from '../../../Decorators/WatchDecorator';
import { IconElement } from '../../Media/Icon/IconElement';
import { PipElement } from '../../Primitives/Pip/PipElement';
import { TextElement } from '../../Primitives/Text/TextElement';
import { SelectorElement } from '../Abstracts/Selector/SelectorElement';
import { stepperElementTemplate } from './StepperElementTemplate';
import { STEPPER_INHERITANCE_CONTEXT } from './StepperInheritanceContext';
import { StepperItemElement } from './StepperItemElement';
import { stepperElementCosmopolitanStyle } from './Themes/StepperElement.Cosmopolitan';
import { stepperElementJoyStyle } from './Themes/StepperElement.Joy';
import { stepperElementMemphisStyle } from './Themes/StepperElement.Memphis';
// #endregion
/**
 * Stepper - A multi-step workflow component for guiding users through sequential processes.
 *
 * @description
 * The Stepper component provides a visual representation of a multi-step process, guiding users
 * through a sequence of steps to complete a task or workflow. It displays step headers with icons
 * or numbers, optional descriptions, and maintains the current active step state. The stepper
 * supports both horizontal and vertical orientations, step state indicators (pending, completed,
 * error), and allows users to navigate between steps by clicking on step headers. It's ideal for
 * forms, wizards, onboarding flows, and any sequential process that benefits from visual progress
 * tracking.
 *
 * @name Stepper
 * @element mosaik-stepper
 * @category Selectors
 *
 * @slot ${`step-${index}`} - The ${`step-${index}`} slot.
 * @slot footer - Custom footer content below the stepper content
 * @slot steps - The stepper item elements (mosaik-stepper-item)
 *
 * @csspart connector - The line connecting steps
 * @csspart content - The content part.
 * @csspart footer - The footer container
 * @csspart header - The header container with step indicators
 * @csspart content - The main content area for active step
 * @csspart step-body - The vertical step body containing connector and step content
 * @csspart step-container - Individual step header container
 * @csspart step-description - The step description text
 * @csspart step-header - The step header text
 * @csspart step-icon - The step icon/number wrapper
 * @csspart step-optional - The optional/hint text
 * @csspart step-state - The pip element for step icon or number
 * @csspart step-text - The step text container
 *
 * @cssprop {String} --stepper-connector-background - The background color of connectors
 * @cssprop {String} --stepper-connector-margin - The margin around connectors
 * @cssprop {String} --stepper-connector-radius - The border radius of connectors
 * @cssprop {String} --stepper-connector-size - The thickness of connector lines
 * @cssprop {String} --stepper-content-gap - The spacing in the content area
 * @cssprop {String} --stepper-description-size - The font size for descriptions
 * @cssprop {String} --stepper-focus-outline-offset - The offset of focus outlines
 * @cssprop {String} --stepper-focus-outline-width - The width of focus outlines
 * @cssprop {String} --stepper-font-family - The font family for stepper text
 * @cssprop {String} --stepper-font-letter-spacing - The font letter spacing CSS custom property.
 * @cssprop {String} --stepper-font-line-height - The font line height CSS custom property.
 * @cssprop {String} --stepper-font-size - The font size CSS custom property.
 * @cssprop {String} --stepper-font-text-decoration - The font text decoration CSS custom property.
 * @cssprop {String} --stepper-font-text-transform - The font text transform CSS custom property.
 * @cssprop {String} --stepper-font-weight - The font weight CSS custom property.
 * @cssprop {String} --stepper-foreground-color - The text and icon color
 * @cssprop {String} --stepper-gap - The spacing between steps and elements
 * @cssprop {String} --stepper-header-padding-vertical - The vertical padding for step headers
 * @cssprop {String} --stepper-icon-border-width - The border width of step icons
 * @cssprop {String} --stepper-icon-radius - The border radius of step icons
 * @cssprop {String} --stepper-icon-shadow - The drop shadow for step icons
 * @cssprop {String} --stepper-icon-size - The size of step icons
 * @cssprop {String} --stepper-padding-bottom - The padding bottom CSS custom property.
 * @cssprop {String} --stepper-padding-left - The padding left CSS custom property.
 * @cssprop {String} --stepper-padding-right - The padding right CSS custom property.
 * @cssprop {String} --stepper-padding-top - The padding top CSS custom property.
 * @cssprop {String} --stepper-shadow - The shadow CSS custom property.
 * @cssprop {String} --stepper-shadow-blur - The shadow blur CSS custom property.
 * @cssprop {String} --stepper-shadow-color - The shadow color CSS custom property.
 * @cssprop {String} --stepper-shadow-offset-x - The shadow offset x CSS custom property.
 * @cssprop {String} --stepper-shadow-offset-y - The shadow offset y CSS custom property.
 * @cssprop {String} --stepper-shadow-spread - The shadow spread CSS custom property.
 * @cssprop {String} --stepper-step-padding-vertical - The vertical padding for step buttons
 * @cssprop {String} --stepper-text-gap - The spacing between text elements
 * @cssprop {String} --stepper-transition-duration - The transition duration CSS custom property.
 * @cssprop {String} --stepper-transition-mode - The transition mode CSS custom property.
 * @cssprop {String} --stepper-transition-property - The transition property CSS custom property.
 * @cssprop {String} --stepper-translate - The translate CSS custom property.
 * @cssprop {String} --stepper-vertical-connector-length - The length of vertical connectors
 * @cssprop {String} --stepper-vertical-connector-margin - The margin for vertical connectors
 *
 * @fires activeStepChanged {ActiveStepChangedEvent} - Fired when the active step changes
 * @fires connected {ConnectedEvent} - Fired when connected to the DOM
 * @fires changed {PropertyChangedEvent} - Fired when properties change
 *
 * @dependency mosaik-pip - The Pip element.
 * @dependency mosaik-text - The Text element.
 *
 * @example
 * Basic horizontal stepper:
 * ```html
 * <mosaik-stepper>
 *   <mosaik-stepper-item header="Account Details" is-active>
 *     <p>Enter your account information.</p>
 *   </mosaik-stepper-item>
 *   <mosaik-stepper-item header="Verification">
 *     <p>Verify your email address.</p>
 *   </mosaik-stepper-item>
 *   <mosaik-stepper-item header="Completion">
 *     <p>Your account is ready!</p>
 *   </mosaik-stepper-item>
 * </mosaik-stepper>
 * ```
 *
 * @example
 * Vertical stepper with descriptions:
 * ```html
 * <mosaik-stepper orientation="vertical">
 *   <mosaik-stepper-item header="Step 1" description="Choose your plan" state="completed"></mosaik-stepper-item>
 *   <mosaik-stepper-item header="Step 2" description="Enter payment details" is-active></mosaik-stepper-item>
 *   <mosaik-stepper-item header="Step 3" description="Confirm order"></mosaik-stepper-item>
 * </mosaik-stepper>
 * ```
 *
 * @example
 * Stepper with step states and hints:
 * ```html
 * <mosaik-stepper>
 *   <mosaik-stepper-item header="Upload" state="completed"></mosaik-stepper-item>
 *   <mosaik-stepper-item header="Process" state="error" hint="Required"></mosaik-stepper-item>
 *   <mosaik-stepper-item header="Finish" state="pending"></mosaik-stepper-item>
 * </mosaik-stepper>
 * ```
 *
 * @public
 */
let StepperElement = class StepperElement extends Themeable(Slottable(Fitable(Disableable(Orientable(SelectorElement))))) {
    // #region Fields
    _provider = addInheritanceProviderController(this, {
        context: STEPPER_INHERITANCE_CONTEXT,
        values: () => ({
            disabled: this.disabled
        })
    });
    _activeStepChanged;
    // #endregion
    // #region Ctor
    /**
     * @public
     */
    constructor() {
        super();
        this._activeStepChanged = new HTMLElementEventEmitter(this, 'activeStepChanged');
    }
    // #endregion
    // #region Properties
    /**
     * Returns the `is` property.
     *
     * @public
     * @static
     * @override
     * @readonly
     */
    // eslint-disable-next-line @typescript-eslint/ban-ts-comment
    // @ts-ignore
    static get is() {
        return 'mosaik-stepper';
    }
    /**
     * Returns the `items` property.
     *
     * @public
     * @override
     * @readonly
     */
    get items() {
        return Array.from(this.children)
            .filter((child) => child.tagName.toLowerCase() === StepperItemElement.is);
    }
    /**
     * Gets the active index of the stepper.
     *
     * @public
     * @readonly
     */
    get activeIndex() {
        return this.items.findIndex((x) => x.isActive);
    }
    /**
     * Gets the first step indicator.
     *
     * @public
     * @readonly
     */
    get isFirstStep() {
        return this.activeIndex === 0;
    }
    /**
     * Gets the last step indicator.
     *
     * @public
     * @readonly
     */
    get isLastStep() {
        return this.activeIndex === this.items.length - 1;
    }
    /**
     * Called when the active step has changed.
     * Provides reference to `IActiveStepChangedEventDetail` as event detail.
     *
     * @public
     * @readonly
     * @eventProperty
     */
    get activeStepChanged() {
        return this._activeStepChanged;
    }
    // #endregion
    // #region Methods
    /**
     * @protected
     * @template
     */
    onSlotChange() {
        this.syncStepSlots();
        this.requestUpdate('items');
        this.ensureActiveStep();
    }
    /**
     * Handles slotted item changes from the Slottable behavior.
     *
     * @public
     * @override
     */
    onSlotChanges(slotName) {
        super.onSlotChanges(slotName);
        this.onSlotChange();
    }
    /**
     * Handles a step invocation from the header.
     *
     * @private
     * @param step - The step that has been invoked.
     */
    onStepInvoked(step) {
        if (this.disabled || step.disabled) {
            return;
        }
        const index = this.items.indexOf(step);
        if (index >= 0) {
            this.select(index);
        }
    }
    /**
     * 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] ?? null,
            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;
        }
    }
    /**
     * @protected
     */
    onOrientationPropertyChanged() {
        this.syncStepSlots();
        this.requestUpdate('items');
    }
    /**
     * Assigns step items to the collector slot in horizontal mode and to per-step slots in vertical mode.
     *
     * @private
     */
    syncStepSlots() {
        this.items.forEach((item, index) => {
            const slotName = this.orientation === 'vertical'
                ? `step-${index}`
                : 'steps';
            if (item.slot !== slotName) {
                item.slot = slotName;
            }
        });
    }
};
__decorate([
    Emit({ eventName: 'activeStepChanged' }),
    __metadata("design:type", Object),
    __metadata("design:paramtypes", [])
], StepperElement.prototype, "activeStepChanged", null);
__decorate([
    Watch('selectedIndex'),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Number, Number]),
    __metadata("design:returntype", void 0)
], StepperElement.prototype, "onSelectedIndexPropertyChanged", null);
__decorate([
    Watch('orientation'),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", void 0)
], StepperElement.prototype, "onOrientationPropertyChanged", null);
StepperElement = __decorate([
    Component({
        selector: 'mosaik-stepper',
        template: stepperElementTemplate,
        themes: {
            joy: stepperElementJoyStyle,
            memphis: stepperElementMemphisStyle,
            cosmopolitan: stepperElementCosmopolitanStyle
        },
        options: {
            mode: 'open',
            delegatesFocus: true
        },
        host: {
            tabIndex: '0',
            role: 'tablist'
        },
        imports: [
            StepperItemElement,
            IconElement,
            TextElement,
            PipElement
        ]
    }),
    __metadata("design:paramtypes", [])
], StepperElement);
export { StepperElement };
//# sourceMappingURL=StepperElement.js.map