// #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 { Disableable } from '../../../Behaviors/Disableable';
import { DropDownable } from '../../../Behaviors/DropDownable';
import { Themeable } from '../../../Behaviors/Themeable';
import { Valueable } from '../../../Behaviors/Valueable';
import { ClickOutsideController } from '../../../Controllers/ClickOutsideController';
import { Attribute } from '../../../Decorators/AttributeDecorator';
import { Component } from '../../../Decorators/ComponentDecorator';
import { Property } from '../../../Decorators/PropertyDecorator';
import { Watch } from '../../../Decorators/WatchDecorator';
import { Placement } from '../../../Types/Placement';
import { CustomElement } from '../../Abstracts/CustomElement';
import { FloatingElement } from '../../Primitives/Floating/FloatingElement';
import { PortalElement } from '../../Primitives/Portal/PortalElement';
import { ColorEditorElement } from '../ColorEditor/ColorEditorElement';
import { IColorPalette } from '../ColorEditor/IColorPalette';
import { ColorSwatchElement } from '../ColorSwatch/ColorSwatchElement';
import { colorPickerElementTemplate } from './ColorPickerElementTemplate';
import { colorPickerElementCosmopolitanStyle } from './Themes/ColorPickerElement.Cosmopolitan';
import { colorPickerElementJoyStyle } from './Themes/ColorPickerElement.Joy';
import { colorPickerElementMemphisStyle } from './Themes/ColorPickerElement.Memphis';
// #endregion
/**
 * Color Picker - A user interface component for selecting colors using the ColorEditor.
 *
 * @description
 * The Color Picker component provides a dropdown interface for selecting colors using
 * the comprehensive ColorEditor component. It displays a color swatch that, when clicked,
 * opens a dropdown containing the full color editing experience.
 *
 * @element mosaik-color-picker
 * @category Media
 *
 * @slot - Default slot for custom trigger content.
 *
 * @csspart editor - The color editor element.
 * @csspart popup - The floating dropdown container.
 * @csspart portal - The portal part.
 * @csspart swatch - The color swatch trigger element.
 *
 * @cssprop {String} --color-picker-background-color - The picker background color CSS custom property.
 * @cssprop {String} --color-picker-border-color - The picker border color CSS custom property.
 * @cssprop {String} --color-picker-border-radius - The picker border radius CSS custom property.
 * @cssprop {String} --color-picker-border-style - The picker border style CSS custom property.
 * @cssprop {String} --color-picker-border-width - The picker border width CSS custom property.
 * @cssprop {String} --color-picker-font-family - The picker font family CSS custom property.
 * @cssprop {String} --color-picker-font-letter-spacing - The picker font letter spacing CSS custom property.
 * @cssprop {String} --color-picker-font-line-height - The picker font line height CSS custom property.
 * @cssprop {String} --color-picker-font-size - The picker font size CSS custom property.
 * @cssprop {String} --color-picker-font-text-decoration - The picker font text decoration CSS custom property.
 * @cssprop {String} --color-picker-font-text-transform - The picker font text transform CSS custom property.
 * @cssprop {String} --color-picker-font-weight - The picker font weight CSS custom property.
 * @cssprop {String} --color-picker-foreground-color - The picker foreground color CSS custom property.
 * @cssprop {String} --color-picker-gap - The picker gap CSS custom property.
 * @cssprop {String} --color-picker-padding-bottom - The picker padding bottom CSS custom property.
 * @cssprop {String} --color-picker-padding-left - The picker padding left CSS custom property.
 * @cssprop {String} --color-picker-padding-right - The picker padding right CSS custom property.
 * @cssprop {String} --color-picker-padding-top - The picker padding top CSS custom property.
 * @cssprop {String} --color-picker-shadow - The picker shadow CSS custom property.
 * @cssprop {String} --color-picker-shadow-blur - The picker shadow blur CSS custom property.
 * @cssprop {String} --color-picker-shadow-color - The picker shadow color CSS custom property.
 * @cssprop {String} --color-picker-shadow-offset-x - The picker shadow offset x CSS custom property.
 * @cssprop {String} --color-picker-shadow-offset-y - The picker shadow offset y CSS custom property.
 * @cssprop {String} --color-picker-shadow-spread - The picker shadow spread CSS custom property.
 * @cssprop {String} --color-picker-size - The picker size CSS custom property.
 * @cssprop {String} --color-picker-transition-duration - The picker transition duration CSS custom property.
 * @cssprop {String} --color-picker-transition-mode - The picker transition mode CSS custom property.
 * @cssprop {String} --color-picker-transition-property - The picker transition property CSS custom property.
 * @cssprop {String} --color-picker-translate - The picker translate CSS custom property.
 *
 * @fires colorChanged {ColorChangedEvent} - Fired when the color value changes.
 *
 * @dependency mosaik-color-editor - The Color Editor element.
 * @dependency mosaik-color-swatch - The Color Swatch element.
 * @dependency mosaik-floating - The Floating element.
 * @dependency mosaik-portal - The Portal element.
 *
 * @example
 * Basic usage with an initial color value:
 * ```html
 * <mosaik-color-picker value="#e91e63"></mosaik-color-picker>
 * ```
 *
 * @example
 * With HSL format and disabled:
 * ```html
 * <mosaik-color-picker value="#1976d2" format="hsl" disabled></mosaik-color-picker>
 * ```
 *
 * @public
 */
let ColorPickerElement = class ColorPickerElement extends Themeable(DropDownable(Disableable(Valueable(CustomElement)))) {
    // #region Fields
    _clickOutsideController;
    _floatingElement;
    _value;
    _format;
    _showAlpha;
    _showInputs;
    _showPalette;
    _showEyeDropper;
    _showSwatch;
    _palettes;
    _selectedPalette;
    // #endregion
    // #region Ctor
    /**
     * @public
     */
    constructor() {
        super();
        this._value = '#ff0000';
        this._format = 'hex';
        this._showAlpha = false;
        this._showInputs = false;
        this._showPalette = false;
        this._showEyeDropper = false;
        this._showSwatch = false;
        this._palettes = IColorPalette.allPalettes();
        this._selectedPalette = IColorPalette.MATERIAL_PALETTE.title;
        this._clickOutsideController = new ClickOutsideController(this, {
            skipInitial: true,
            ignored: () => [this._floatingElement],
            callback: () => this.onClickedOutside()
        });
        // Set dropdown defaults
        Object.assign(this, {
            dropDownPlacement: Placement.BottomStart,
            dropDownMaxHeight: 'auto',
            dropDownWidth: 'auto'
        });
    }
    // #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-picker';
    }
    /**
     * Gets or sets the `value` property.
     *
     * @public
     * @override
     */
    get value() {
        return this._value;
    }
    set value(value) {
        if (this._value !== value) {
            this._value = value;
            this.requestUpdate('value');
        }
    }
    /**
     * Gets or sets the color format for the inputs.
     *
     * @public
     */
    get format() {
        return this._format;
    }
    set format(value) {
        if (this._format !== value) {
            this._format = value;
            this.requestUpdate('format');
        }
    }
    /**
     * Gets or sets whether to show the alpha slider and input.
     *
     * @public
     */
    get showAlpha() {
        return this._showAlpha;
    }
    set showAlpha(value) {
        if (this._showAlpha !== value) {
            this._showAlpha = value;
            this.requestUpdate('showAlpha');
        }
    }
    /**
     * Gets or sets whether to show the color inputs.
     *
     * @public
     */
    get showInputs() {
        return this._showInputs;
    }
    set showInputs(value) {
        if (this._showInputs !== value) {
            this._showInputs = value;
            this.requestUpdate('showInputs');
        }
    }
    /**
     * Gets or sets whether to show the color palette.
     *
     * @public
     */
    get showPalette() {
        return this._showPalette;
    }
    set showPalette(value) {
        if (this._showPalette !== value) {
            this._showPalette = value;
            this.requestUpdate('showPalette');
        }
    }
    /**
     * Gets or sets whether to show the eye dropper button.
     *
     * @public
     */
    get showEyeDropper() {
        return this._showEyeDropper;
    }
    set showEyeDropper(value) {
        if (this._showEyeDropper !== value) {
            this._showEyeDropper = value;
            this.requestUpdate('showEyeDropper');
        }
    }
    /**
     * Gets or sets whether to show the color swatch preview in the editor.
     *
     * @public
     */
    get showSwatch() {
        return this._showSwatch;
    }
    set showSwatch(value) {
        if (this._showSwatch !== value) {
            this._showSwatch = value;
            this.requestUpdate('showSwatch');
        }
    }
    /**
     * Gets or sets the available color palettes.
     *
     * @public
     */
    get palettes() {
        return this._palettes;
    }
    set palettes(value) {
        if (this._palettes !== value) {
            this._palettes = value;
            this.requestUpdate('palettes');
        }
    }
    /**
     * Gets or sets the currently selected palette name.
     *
     * @public
     */
    get selectedPalette() {
        return this._selectedPalette;
    }
    set selectedPalette(value) {
        if (this._selectedPalette !== value) {
            this._selectedPalette = value;
            this.requestUpdate('selectedPalette');
        }
    }
    // #endregion
    // #region Methods
    /**
     * @public
     * @override
     */
    connectedCallback() {
        super.connectedCallback();
        this.on('click', (event) => {
            const target = event.target;
            // Only toggle if clicking on the swatch or host, not the editor
            if (target.closest('mosaik-color-editor')) {
                return;
            }
            this.toggle();
        });
    }
    /**
     * @protected
     * @override
     */
    onApplyTemplate() {
        super.onApplyTemplate();
        this._floatingElement = this.getTemplatePart('popup');
    }
    /**
     * Handles changes from the color editor.
     *
     * @private
     * @template
     */
    onEditorChange(event) {
        event.stopPropagation();
        this.value = event.detail.color;
        this.emit('colorChanged', { detail: this.value });
    }
    /**
     * @protected
     */
    onIsDropDownOpenPropertyChanged(_prev, next) {
        if (next) {
            if (this.disabled) {
                this.close();
                return;
            }
            this._clickOutsideController.observe();
        }
        else {
            this._clickOutsideController.unobserve();
        }
    }
    /**
     * @private
     */
    onClickedOutside() {
        this.close();
    }
};
__decorate([
    Attribute({ type: String }),
    __metadata("design:type", Object),
    __metadata("design:paramtypes", [Object])
], ColorPickerElement.prototype, "value", null);
__decorate([
    Attribute({ type: String }),
    __metadata("design:type", String),
    __metadata("design:paramtypes", [String])
], ColorPickerElement.prototype, "format", null);
__decorate([
    Property({
        type: Boolean,
        useDefault: true
    }),
    __metadata("design:type", Boolean),
    __metadata("design:paramtypes", [Boolean])
], ColorPickerElement.prototype, "showAlpha", null);
__decorate([
    Property({
        type: Boolean,
        useDefault: true
    }),
    __metadata("design:type", Boolean),
    __metadata("design:paramtypes", [Boolean])
], ColorPickerElement.prototype, "showInputs", null);
__decorate([
    Property({
        type: Boolean,
        useDefault: true
    }),
    __metadata("design:type", Boolean),
    __metadata("design:paramtypes", [Boolean])
], ColorPickerElement.prototype, "showPalette", null);
__decorate([
    Property({
        type: Boolean,
        useDefault: true
    }),
    __metadata("design:type", Boolean),
    __metadata("design:paramtypes", [Boolean])
], ColorPickerElement.prototype, "showEyeDropper", null);
__decorate([
    Property({
        type: Boolean,
        useDefault: true
    }),
    __metadata("design:type", Boolean),
    __metadata("design:paramtypes", [Boolean])
], ColorPickerElement.prototype, "showSwatch", null);
__decorate([
    Property({ type: Array }),
    __metadata("design:type", Array),
    __metadata("design:paramtypes", [Array])
], ColorPickerElement.prototype, "palettes", null);
__decorate([
    Attribute({
        type: String,
        attribute: 'selected-palette'
    }),
    __metadata("design:type", String),
    __metadata("design:paramtypes", [String])
], ColorPickerElement.prototype, "selectedPalette", null);
__decorate([
    Watch('isDropDownOpen', { waitUntilFirstUpdate: true }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Boolean, Boolean]),
    __metadata("design:returntype", void 0)
], ColorPickerElement.prototype, "onIsDropDownOpenPropertyChanged", null);
ColorPickerElement = __decorate([
    Component({
        selector: 'mosaik-color-picker',
        template: colorPickerElementTemplate,
        themes: {
            joy: colorPickerElementJoyStyle,
            memphis: colorPickerElementMemphisStyle,
            cosmopolitan: colorPickerElementCosmopolitanStyle
        },
        imports: [
            ColorEditorElement,
            ColorSwatchElement,
            FloatingElement,
            PortalElement
        ]
    }),
    __metadata("design:paramtypes", [])
], ColorPickerElement);
export { ColorPickerElement };
//# sourceMappingURL=ColorPickerElement.js.map