// #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 { Attribute } from '../../../Decorators/AttributeDecorator';
import { Component } from '../../../Decorators/ComponentDecorator';
import { Property } from '../../../Decorators/PropertyDecorator';
import { CustomElement } from '../../Abstracts/CustomElement';
import { colorEditorSwatchElementTemplate } from './ColorEditorSwatchElementTemplate';
import { colorEditorSwatchElementCosmopolitanStyle } from './Themes/ColorEditorSwatchElement.Cosmopolitan';
import { colorEditorSwatchElementJoyStyle } from './Themes/ColorEditorSwatchElement.Joy';
import { colorEditorSwatchElementMemphisStyle } from './Themes/ColorEditorSwatchElement.Memphis';
// #endregion
/**
 * Color Editor Swatch - A color preview element with optional copy functionality.
 *
 * @name ColorEditorSwatch
 * @element mosaik-color-editor-swatch
 *
 * @description
 * The Color Editor Swatch component displays a preview of a color with an optional
 * copy-to-clipboard button. It includes a checkerboard background pattern to indicate
 * transparency levels and automatically adjusts border visibility based on color
 * brightness.
 *
 * @category Media
 *
 * @fires swatchCopy {SwatchCopyEvent} - Fired when the color is copied to clipboard
 *
 * @csspart color - The color display area
 * @csspart copy-button - The copy to clipboard button overlay
 *
 * @public
 */
let ColorEditorSwatchElement = class ColorEditorSwatchElement extends Themeable(Disableable(Focusable(CustomElement))) {
    // #region Fields
    _swatchCopy;
    _color;
    _copyable;
    // #endregion
    // #region Ctor
    /**
     * Constructs a new instance of the ColorEditorSwatchElement class.
     *
     * @public
     */
    constructor() {
        super();
        this._swatchCopy = new HTMLElementEventEmitter(this, 'swatchCopy');
        this._color = '#ff0000';
        this._copyable = false;
    }
    // #endregion
    // #region Properties
    /**
     * Returns the `{@link is}` property.
     * The `{@link is}` property represents natural name of this element.
     *
     * @public
     * @static
     * @readonly
     */
    static get is() {
        return 'mosaik-color-editor-swatch';
    }
    /**
     * Gets or sets the color to display.
     *
     * @public
     * @attr
     */
    get color() {
        return this._color;
    }
    set color(value) {
        if (this._color !== value) {
            this._color = value;
            this.requestUpdate('color');
        }
    }
    /**
     * Gets or sets whether the swatch shows a copy button on hover.
     *
     * @public
     */
    get copyable() {
        return this._copyable;
    }
    set copyable(value) {
        if (this._copyable !== value) {
            this._copyable = value;
            this.requestUpdate('copyable');
        }
    }
    /**
     * Called when the color is copied to clipboard.
     * Provides reference to `{@link ISwatchCopyEventDetail}` as event detail.
     *
     * @public
     * @readonly
     * @eventProperty
     */
    get swatchCopy() {
        return this._swatchCopy;
    }
    // #endregion
    // #region Methods
    /**
     * Handles click on the copy button.
     *
     * @public
     */
    async pick() {
        try {
            await navigator.clipboard.writeText(this._color);
            this._swatchCopy.emit({ color: this._color });
        }
        catch (error) {
            console.error('Failed to copy color to clipboard:', error);
        }
    }
    /**
     * @private
     */
    onPick(event) {
        event.stopPropagation();
        void this.pick();
    }
};
__decorate([
    Attribute({ type: String }),
    __metadata("design:type", String),
    __metadata("design:paramtypes", [String])
], ColorEditorSwatchElement.prototype, "color", null);
__decorate([
    Property({
        type: Boolean,
        useDefault: true
    }),
    __metadata("design:type", Boolean),
    __metadata("design:paramtypes", [Boolean])
], ColorEditorSwatchElement.prototype, "copyable", null);
__decorate([
    Emit({ eventName: 'swatchCopy' }),
    __metadata("design:type", Object),
    __metadata("design:paramtypes", [])
], ColorEditorSwatchElement.prototype, "swatchCopy", null);
ColorEditorSwatchElement = __decorate([
    Component({
        selector: 'mosaik-color-editor-swatch',
        template: colorEditorSwatchElementTemplate,
        themes: {
            joy: colorEditorSwatchElementJoyStyle,
            memphis: colorEditorSwatchElementMemphisStyle,
            cosmopolitan: colorEditorSwatchElementCosmopolitanStyle
        }
    }),
    __metadata("design:paramtypes", [])
], ColorEditorSwatchElement);
export { ColorEditorSwatchElement };
//# sourceMappingURL=ColorEditorSwatchElement.js.map