/* eslint-disable @typescript-eslint/naming-convention */
// #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 { Property } from '../Decorators/PropertyDecorator';
import { TextFormatters } from '../Types/TextFormatter';
/**
 * @public
 */
export const TextFormattable = (base) => {
    class TextFormattableElement extends base {
        // #region Fields
        _formatter;
        // #endregion
        // #region Ctor
        /**
         * Constructs a new instance of the `TextFormattableElement` class.
         *
         * @public
         */
        constructor(...args) {
            super(args);
            this._formatter = ITextFormattableProps.DEFAULTS.formatter;
        }
        // #endregion
        // #region Properties
        /**
         * Gets or sets the `formatter` property.
         * The default value is `null`, which means no formatter is set.
         *
         * @public
         */
        get formatter() {
            return this._formatter;
        }
        set formatter(value) {
            if (typeof value === 'string') {
                for (const [key, formatter] of Object.entries(TextFormatters)) {
                    if (key.toLowerCase() === value.toLowerCase()) {
                        value = formatter;
                        break;
                    }
                }
                value = value;
            }
            if (this._formatter !== value) {
                this._formatter = value;
                this.requestUpdate('formatter');
            }
        }
    }
    __decorate([
        Property({
            type: Object,
            converter: (value) => {
                if (typeof value === 'function') {
                    return value;
                }
                if (typeof value === 'string') {
                    for (const [key, formatter] of Object.entries(TextFormatters)) {
                        if (key.toLowerCase() === value.toLowerCase()) {
                            value = formatter;
                            break;
                        }
                    }
                    return value;
                }
                return null;
            }
        }),
        __metadata("design:type", Object),
        __metadata("design:paramtypes", [Object])
    ], TextFormattableElement.prototype, "formatter", null);
    return TextFormattableElement;
};
/**
 * @public
 */
export var ITextFormattableProps;
(function (ITextFormattableProps) {
    ITextFormattableProps.DEFAULTS = {
        formatter: null
    };
})(ITextFormattableProps || (ITextFormattableProps = {}));
//# sourceMappingURL=TextFormattable.js.map