// #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 { Sizeable } from '../../../Behaviors/Sizeable';
import { Themeable } from '../../../Behaviors/Themeable';
import { Component } from '../../../Decorators/ComponentDecorator';
import { Property } from '../../../Decorators/PropertyDecorator';
import { CustomElement } from '../../Abstracts/CustomElement';
import { emojiElementTemplate } from './EmojiElementTemplate';
import { emojiElementCosmopolitanStyle } from './Themes/EmojiElement.Cosmopolitan';
import { emojiElementJoyStyle } from './Themes/EmojiElement.Joy';
import { emojiElementMemphisStyle } from './Themes/EmojiElement.Memphis';
// #endregion
/**
 * The `EmojiElement` element.
 *
 * @cssprop {String} --emoji-background-color - The background color CSS custom property.
 * @cssprop {String} --emoji-font-family - The font family CSS custom property.
 * @cssprop {String} --emoji-font-letter-spacing - The font letter spacing CSS custom property.
 * @cssprop {String} --emoji-font-line-height - The font line height CSS custom property.
 * @cssprop {String} --emoji-font-size - The font size CSS custom property.
 * @cssprop {String} --emoji-font-text-decoration - The font text decoration CSS custom property.
 * @cssprop {String} --emoji-font-text-transform - The font text transform CSS custom property.
 * @cssprop {String} --emoji-font-weight - The font weight CSS custom property.
 * @cssprop {String} --emoji-gap - The gap CSS custom property.
 * @cssprop {String} --emoji-padding-bottom - The padding bottom CSS custom property.
 * @cssprop {String} --emoji-padding-left - The padding left CSS custom property.
 * @cssprop {String} --emoji-padding-right - The padding right CSS custom property.
 * @cssprop {String} --emoji-padding-top - The padding top CSS custom property.
 * @cssprop {String} --emoji-shadow - The shadow CSS custom property.
 * @cssprop {String} --emoji-shadow-blur - The shadow blur CSS custom property.
 * @cssprop {String} --emoji-shadow-color - The shadow color CSS custom property.
 * @cssprop {String} --emoji-shadow-offset-x - The shadow offset x CSS custom property.
 * @cssprop {String} --emoji-shadow-offset-y - The shadow offset y CSS custom property.
 * @cssprop {String} --emoji-shadow-spread - The shadow spread CSS custom property.
 * @cssprop {String} --emoji-transition-duration - The transition duration CSS custom property.
 * @cssprop {String} --emoji-transition-mode - The transition mode CSS custom property.
 * @cssprop {String} --emoji-transition-property - The transition property CSS custom property.
 * @cssprop {String} --emoji-translate - The translate CSS custom property.
 *
 * @example
 * ```html
 * <!-- Basic emoji (set unicode or emoji via JavaScript) -->
 * <mosaik-emoji></mosaik-emoji>
 *
 * <!-- Sized emoji -->
 * <mosaik-emoji size="large"></mosaik-emoji>
 * ```
 *
 * @public
 */
let EmojiElement = class EmojiElement extends Themeable(Sizeable(CustomElement)) {
    // #region Fields
    _unicode;
    // #endregion
    // #region Ctor
    /**
     * @public
     */
    constructor() {
        super();
        this._unicode = '';
    }
    // #endregion
    // #region Properties
    /**
     * Returns the `is` property.
     * The `is` property represents natural name of this element.
     *
     * @public
     * @static
     * @readonly
     */
    static get is() {
        return 'mosaik-emoji';
    }
    /**
     * Gets or sets the `unicode` property.
     *
     * @public
     */
    get unicode() {
        return this._unicode;
    }
    set unicode(value) {
        const normalized = this.normalizeUnicodeInput(value);
        if (this._unicode !== normalized) {
            this._unicode = normalized;
            this.requestUpdate('unicode');
            this.requestUpdate('emoji');
        }
    }
    /**
     * Gets or sets the emoji as a rendered string.
     * Setting this will update the unicode property (normalized, hyphen-separated, uppercase hex).
     *
     * @public
     */
    get emoji() {
        return this.transformUnicodeToEmoji(this._unicode);
    }
    set emoji(value) {
        const unicode = this.transformEmojiToUnicode(value);
        if (unicode !== this._unicode) {
            this._unicode = unicode;
            this.requestUpdate('unicode');
            this.requestUpdate('emoji');
        }
    }
    // #endregion
    // #region Methods
    /**
     * Converts the current unicode value to its emoji string.
     *
     * @public
     */
    toEmoji() {
        return this.transformUnicodeToEmoji(this.unicode);
    }
    /**
     * Converts the current emoji string to a normalized unicode representation.
     * Returns an uppercase, hyphen-separated hex codepoint string (e.g., "1F469-200D-1F4BB").
     *
     * @public
     */
    toUnicode() {
        return this.transformEmojiToUnicode(this.emoji);
    }
    /**
     * Transforms the specified unicode value to emoji.
     * Supports multi-codepoint sequences separated by "-", spaces, or prefixed with "U+" / "0x".
     *
     * @protected
     */
    transformUnicodeToEmoji(value) {
        if (value === undefined || value === null) {
            return '';
        }
        const tokens = value.replace(/(U\+|0x)/gi, ' ').match(/[0-9a-fA-F]{1,8}/g) ?? [];
        if (tokens.length === 0) {
            return '';
        }
        const codePoints = tokens
            .map((t) => parseInt(t, 16))
            .filter((cp) => Number.isFinite(cp));
        return codePoints.map((cp) => String.fromCodePoint(cp)).join('');
    }
    /**
     * Transforms the specified emoji string to a normalized unicode representation.
     * Returns uppercase hex codepoints joined by "-" (keeps all variation selectors and ZWJ sequences).
     *
     * @protected
     */
    transformEmojiToUnicode(value) {
        if (value === undefined || value === null || value === '') {
            return '';
        }
        const codePointsHex = [];
        for (const ch of value) {
            const cp = ch.codePointAt(0) ?? undefined;
            if (cp !== undefined) {
                codePointsHex.push(cp.toString(16).toUpperCase());
            }
        }
        return codePointsHex.join('-');
    }
    /**
     * Normalizes input for the unicode property into a canonical, uppercase, hyphen-separated hex string.
     *
     * @private
     */
    normalizeUnicodeInput(value) {
        if (value === undefined || value === null || value.trim() === '') {
            return '';
        }
        const tokens = value.replace(/(U\+|0x)/gi, ' ').match(/[0-9a-fA-F]{1,8}/g) ?? [];
        return tokens.map((t) => t.toUpperCase()).join('-');
    }
};
__decorate([
    Property({ type: String }),
    __metadata("design:type", String),
    __metadata("design:paramtypes", [String])
], EmojiElement.prototype, "unicode", null);
__decorate([
    Property({ type: String }),
    __metadata("design:type", String),
    __metadata("design:paramtypes", [String])
], EmojiElement.prototype, "emoji", null);
EmojiElement = __decorate([
    Component({
        selector: 'mosaik-emoji',
        template: emojiElementTemplate,
        themes: {
            joy: emojiElementJoyStyle,
            memphis: emojiElementMemphisStyle,
            cosmopolitan: emojiElementCosmopolitanStyle
        },
        host: {
            role: 'text'
        },
        imports: []
    }),
    __metadata("design:paramtypes", [])
], EmojiElement);
export { EmojiElement };
//# sourceMappingURL=EmojiElement.js.map