// #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 { Focusable } from '../../../Behaviors/Focusable';
import { Themeable } from '../../../Behaviors/Themeable';
import { ResizeController } from '../../../Controllers/ResizeController';
import { Attribute } from '../../../Decorators/AttributeDecorator';
import { Component } from '../../../Decorators/ComponentDecorator';
import { Property } from '../../../Decorators/PropertyDecorator';
import { CustomElement } from '../../Abstracts/CustomElement';
import { colorEditorHueSliderElementTemplate } from './ColorEditorHueSliderElementTemplate';
import { colorEditorHueSliderElementCosmopolitanStyle } from './Themes/ColorEditorHueSliderElement.Cosmopolitan';
import { colorEditorHueSliderElementJoyStyle } from './Themes/ColorEditorHueSliderElement.Joy';
import { colorEditorHueSliderElementMemphisStyle } from './Themes/ColorEditorHueSliderElement.Memphis';
// #endregion
/**
 * Color Editor Hue Slider - A slider for selecting hue values in the color spectrum.
 *
 * @description
 * The Color Editor Hue Slider component provides a horizontal slider displaying
 * the full hue spectrum (0-360 degrees). Users can drag or click to select
 * a hue value which is commonly used in HSV/HSL color pickers.
 *
 * @name ColorEditorHueSlider
 * @element mosaik-color-editor-hue-slider
 * @category Media
 *
 * @csspart thumb - The draggable indicator showing current hue position
 *
 * @cssprop {String} --color-editor-hue-slider-background-color - The editor hue slider background color CSS custom property.
 * @cssprop {String} --color-editor-hue-slider-border-color - The editor hue slider border color CSS custom property.
 * @cssprop {String} --color-editor-hue-slider-border-radius - The editor hue slider border radius CSS custom property.
 * @cssprop {String} --color-editor-hue-slider-border-style - The editor hue slider border style CSS custom property.
 * @cssprop {String} --color-editor-hue-slider-border-width - The editor hue slider border width CSS custom property.
 * @cssprop {String} --color-editor-hue-slider-focus-ring-active-width - The editor hue slider focus ring active width CSS custom property.
 * @cssprop {String} --color-editor-hue-slider-focus-ring-color - The editor hue slider focus ring color CSS custom property.
 * @cssprop {String} --color-editor-hue-slider-focus-ring-inward-offset - The editor hue slider focus ring inward offset CSS custom property.
 * @cssprop {String} --color-editor-hue-slider-focus-ring-outward-offset - The editor hue slider focus ring outward offset CSS custom property.
 * @cssprop {String} --color-editor-hue-slider-font-family - The editor hue slider font family CSS custom property.
 * @cssprop {String} --color-editor-hue-slider-font-letter-spacing - The editor hue slider font letter spacing CSS custom property.
 * @cssprop {String} --color-editor-hue-slider-font-line-height - The editor hue slider font line height CSS custom property.
 * @cssprop {String} --color-editor-hue-slider-font-size - The editor hue slider font size CSS custom property.
 * @cssprop {String} --color-editor-hue-slider-font-text-decoration - The editor hue slider font text decoration CSS custom property.
 * @cssprop {String} --color-editor-hue-slider-font-text-transform - The editor hue slider font text transform CSS custom property.
 * @cssprop {String} --color-editor-hue-slider-font-weight - The editor hue slider font weight CSS custom property.
 * @cssprop {String} --color-editor-hue-slider-foreground-color - The editor hue slider foreground color CSS custom property.
 * @cssprop {String} --color-editor-hue-slider-gap - The editor hue slider gap CSS custom property.
 * @cssprop {String} --color-editor-hue-slider-height - The editor hue slider height CSS custom property.
 * @cssprop {String} --color-editor-hue-slider-padding-bottom - The editor hue slider padding bottom CSS custom property.
 * @cssprop {String} --color-editor-hue-slider-padding-left - The editor hue slider padding left CSS custom property.
 * @cssprop {String} --color-editor-hue-slider-padding-right - The editor hue slider padding right CSS custom property.
 * @cssprop {String} --color-editor-hue-slider-padding-top - The editor hue slider padding top CSS custom property.
 * @cssprop {String} --color-editor-hue-slider-shadow - The editor hue slider shadow CSS custom property.
 * @cssprop {String} --color-editor-hue-slider-shadow-blur - The editor hue slider shadow blur CSS custom property.
 * @cssprop {String} --color-editor-hue-slider-shadow-color - The editor hue slider shadow color CSS custom property.
 * @cssprop {String} --color-editor-hue-slider-shadow-offset-x - The editor hue slider shadow offset x CSS custom property.
 * @cssprop {String} --color-editor-hue-slider-shadow-offset-y - The editor hue slider shadow offset y CSS custom property.
 * @cssprop {String} --color-editor-hue-slider-shadow-spread - The editor hue slider shadow spread CSS custom property.
 * @cssprop {String} --color-editor-hue-slider-thumb-background-color - The editor hue slider thumb background color CSS custom property.
 * @cssprop {String} --color-editor-hue-slider-thumb-border-color - The editor hue slider thumb border color CSS custom property.
 * @cssprop {String} --color-editor-hue-slider-thumb-border-radius - The editor hue slider thumb border radius CSS custom property.
 * @cssprop {String} --color-editor-hue-slider-thumb-border-width - The editor hue slider thumb border width CSS custom property.
 * @cssprop {String} --color-editor-hue-slider-thumb-shadow - The editor hue slider thumb shadow CSS custom property.
 * @cssprop {String} --color-editor-hue-slider-thumb-size - The editor hue slider thumb size CSS custom property.
 * @cssprop {String} --color-editor-hue-slider-transition-duration - The editor hue slider transition duration CSS custom property.
 * @cssprop {String} --color-editor-hue-slider-transition-mode - The editor hue slider transition mode CSS custom property.
 * @cssprop {String} --color-editor-hue-slider-transition-property - The editor hue slider transition property CSS custom property.
 * @cssprop {String} --color-editor-hue-slider-translate - The editor hue slider translate CSS custom property.
 * @cssprop {String} --color-editor-hue-slider-width - The editor hue slider width CSS custom property.
 *
 * @fires hueChanged {HueChangedEvent} - Fired when the hue value changes via user interaction
 *
 * @example
 * Basic usage:
 * ```html
 * <mosaik-color-editor-hue-slider></mosaik-color-editor-hue-slider>
 * ```
 *
 * @example
 * With an initial hue value:
 * ```html
 * <mosaik-color-editor-hue-slider hue="120"></mosaik-color-editor-hue-slider>
 * ```
 *
 * @public
 */
let ColorEditorHueSliderElement = class ColorEditorHueSliderElement extends Themeable(Disableable(Focusable(CustomElement))) {
    // #region Fields
    _resizeController;
    _hueChanged;
    _hue;
    _step;
    _boundingClientRect;
    _pointerDown;
    // #endregion
    // #region Ctor
    /**
     * Constructs a new instance of the ColorEditorHueSliderElement class.
     *
     * @public
     */
    constructor() {
        super();
        this._hueChanged = new HTMLElementEventEmitter(this, 'hueChanged');
        this._hue = 0;
        this._step = 1;
        this._pointerDown = false;
        this._resizeController = new ResizeController(this, {
            callback: (entries) => {
                for (const entry of entries) {
                    this._boundingClientRect = entry.contentRect;
                }
            }
        });
    }
    // #endregion
    // #region Properties
    /**
     * Returns the `is` property.
     * The `is` property represents natural name of this element.
     *
     * @public
     * @static
     * @readonly
     */
    static get is() {
        return 'mosaik-color-editor-hue-slider';
    }
    /**
     * Gets or sets the hue value (0-360).
     *
     * @public
     * @attr
     */
    get hue() {
        return this._hue;
    }
    set hue(value) {
        if (this._hue !== value) {
            this._hue = Math.max(0, Math.min(360, value));
            this.requestUpdate('hue');
        }
    }
    /**
     * Gets or sets the step increment for the slider.
     *
     * @public
     */
    get step() {
        return this._step;
    }
    set step(value) {
        if (this._step !== value) {
            this._step = Math.max(0.1, value);
            this.requestUpdate('step');
        }
    }
    /**
     * Called when the hue value changes.
     * Provides reference to `IHueChangedEventDetail` as event detail.
     *
     * @public
     * @readonly
     * @eventProperty
     */
    get hueChanged() {
        return this._hueChanged;
    }
    // #endregion
    // #region Methods
    /**
     * @inheritdoc
     * @protected
     */
    connectedCallback() {
        super.connectedCallback();
        this.on('pointerdown', (e) => this.onPointerDown(e));
        this.on('pointermove', (e) => this.onPointerMove(e));
        this.on('pointerup', (e) => this.onPointerUp(e));
        this.on('pointercancel', (e) => this.onPointerUp(e));
        this.on('keydown', (e) => this.onKeyDown(e));
    }
    /**
     * @inheritdoc
     * @protected
     */
    firstUpdated(changedProperties) {
        super.firstUpdated(changedProperties);
        this._boundingClientRect = this.getBoundingClientRect();
    }
    /**
     * @inheritdoc
     * @protected
     */
    updated(changedProperties) {
        super.updated(changedProperties);
        this.setAttribute('aria-valuenow', this._hue.toString());
    }
    /**
     * Handles pointer down events to start dragging.
     *
     * @private
     */
    onPointerDown(event) {
        if (this.disabled) {
            return;
        }
        this._pointerDown = true;
        this.setPointerCapture(event.pointerId);
        this.updateHueFromPointer(event);
    }
    /**
     * Handles pointer move events for dragging.
     *
     * @private
     */
    onPointerMove(event) {
        if (!this._pointerDown || this.disabled) {
            return;
        }
        this.updateHueFromPointer(event);
    }
    /**
     * Handles pointer up events to stop dragging.
     *
     * @private
     */
    onPointerUp(event) {
        if (this._pointerDown) {
            this._pointerDown = false;
            this.releasePointerCapture(event.pointerId);
        }
    }
    /**
     * Handles keyboard navigation.
     *
     * @private
     */
    onKeyDown(event) {
        if (this.disabled) {
            return;
        }
        const step = event.shiftKey ? this._step * 10 : this._step;
        let handled = false;
        switch (event.key) {
            case 'ArrowLeft':
            case 'ArrowDown':
                this.hue = Math.max(0, this._hue - step);
                handled = true;
                break;
            case 'ArrowRight':
            case 'ArrowUp':
                this.hue = Math.min(360, this._hue + step);
                handled = true;
                break;
            case 'Home':
                this.hue = 0;
                handled = true;
                break;
            case 'End':
                this.hue = 360;
                handled = true;
                break;
        }
        if (handled) {
            event.preventDefault();
            this._hueChanged.emit({ hue: this._hue });
        }
    }
    /**
     * Updates the hue from pointer coordinates.
     *
     * @private
     */
    updateHueFromPointer(event) {
        // Always use getBoundingClientRect() for pointer calculations since
        // ResizeObserver's contentRect has left/top = 0 (relative to element, not viewport)
        const rect = this.getBoundingClientRect();
        const x = Math.max(0, Math.min(1, (event.clientX - rect.left) / rect.width));
        this.hue = Math.round(x * 360 / this._step) * this._step;
        this._hueChanged.emit({ hue: this._hue });
    }
};
__decorate([
    Attribute({ type: Number }),
    __metadata("design:type", Number),
    __metadata("design:paramtypes", [Number])
], ColorEditorHueSliderElement.prototype, "hue", null);
__decorate([
    Property({ type: Number }),
    __metadata("design:type", Number),
    __metadata("design:paramtypes", [Number])
], ColorEditorHueSliderElement.prototype, "step", null);
__decorate([
    Emit({ eventName: 'hueChanged' }),
    __metadata("design:type", Object),
    __metadata("design:paramtypes", [])
], ColorEditorHueSliderElement.prototype, "hueChanged", null);
ColorEditorHueSliderElement = __decorate([
    Component({
        selector: 'mosaik-color-editor-hue-slider',
        template: colorEditorHueSliderElementTemplate,
        themes: {
            joy: colorEditorHueSliderElementJoyStyle,
            memphis: colorEditorHueSliderElementMemphisStyle,
            cosmopolitan: colorEditorHueSliderElementCosmopolitanStyle
        },
        host: {
            'tabIndex': '0',
            'role': 'slider',
            'aria-label': 'Hue',
            'aria-valuemin': '0',
            'aria-valuemax': '360'
        }
    }),
    __metadata("design:paramtypes", [])
], ColorEditorHueSliderElement);
export { ColorEditorHueSliderElement };
//# sourceMappingURL=ColorEditorHueSliderElement.js.map