// #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 { Appearanceable } from '../../../Behaviors/Appearanceable';
import { Disableable } from '../../../Behaviors/Disableable';
import { Invalidable } from '../../../Behaviors/Invalidable';
import { Labelable } from '../../../Behaviors/Labelable';
import { TextFormattable } from '../../../Behaviors/TextFormattable';
import { Themeable } from '../../../Behaviors/Themeable';
import { Valueable } from '../../../Behaviors/Valueable';
import { Variantable } from '../../../Behaviors/Variantable';
import { addInheritanceConsumerController } from '../../../Controllers/InheritanceConsumerController';
import { Attribute } from '../../../Decorators/AttributeDecorator';
import { Component } from '../../../Decorators/ComponentDecorator';
import { LabelPosition } from '../../../Types/LabelPosition';
import { ToggableElement } from '../../Primitives/Abstracts/Toggable/ToggableElement';
import { CheckmarkElement } from '../../Primitives/Checkmark/CheckmarkElement';
import { FocusRingElement } from '../../Primitives/FocusRing/FocusRingElement';
import { TextElement } from '../../Primitives/Text/TextElement';
import { radioElementTemplate } from './RadioElementTemplate';
import { RADIO_GROUP_INHERITANCE_CONTEXT } from './RadioGroupInheritanceContext';
import { radioElementCosmopolitanStyle } from './Themes/RadioElement.Cosmopolitan';
import { radioElementJoyStyle } from './Themes/RadioElement.Joy';
import { radioElementMemphisStyle } from './Themes/RadioElement.Memphis';
// #endregion
/**
 * Radio - A UI element allowing users to select a single option from a list.
 *
 * @description
 * The Radio component allows users to select one option from a group of mutually exclusive choices.
 * Radio buttons are typically used in forms where only one selection is allowed from a set of options.
 * They work best when grouped together and provide clear, distinct choices to users.
 *
 * @name Radio
 * @element mosaik-radio
 * @category Inputs
 *
 * @slot checkmark - The checkmark slot.
 * @slot label - The label slot.
 *
 * @csspart input - the input part.
 * @csspart focusRing - the focus ring part.
 * @csspart checkmark - the checkmark part.
 * @csspart label - the label part.
 * @csspart hint - the hint part.
 *
 * @dependency {FocusRingElement} mosaik-focus-ring - The focus ring element.
 * @dependency {CheckmarkElement} mosaik-checkmark - The checkmark element.
 * @dependency {TextElement} mosaik-text - The text element.
 *
 * @example
 * ```html
 * <mosaik-radio name="size" value="small" label="Small"></mosaik-radio>
 * <mosaik-radio name="size" value="medium" label="Medium"></mosaik-radio>
 * <mosaik-radio name="size" value="large" label="Large"></mosaik-radio>
 * ```
 *
 * @public
 */
let RadioElement = class RadioElement extends Themeable(Invalidable(Valueable(Variantable(Appearanceable(Disableable(Labelable(TextFormattable(ToggableElement)))))))) {
    // #region Fields
    _inheritance = addInheritanceConsumerController(this, {
        context: RADIO_GROUP_INHERITANCE_CONTEXT
    });
    _inputElement;
    _labelPosition;
    _required;
    _name;
    // #endregion
    // #region Ctor
    /**
     * @public
     */
    constructor() {
        super();
        this._labelPosition = LabelPosition.After;
        this._required = false;
        this._name = '';
    }
    // #endregion
    // #region Properties
    /**
     * Returns the `{@link is}` property.
     * The `{@link is}` property represents natural name of this element.
     *
     * @public
     * @static
     * @override
     * @readonly
     */
    static get is() {
        return 'mosaik-radio';
    }
    /**
     * @inheritDoc
     * When used inside a RadioGroup, inherits the group's disabled state unless explicitly set.
     *
     * @public
     * @override
     */
    get disabled() {
        return this._inheritance.get('disabled', super.disabled);
    }
    set disabled(value) {
        this._inheritance.markExplicit('disabled');
        super.disabled = value;
    }
    /**
     * @inheritdoc
     * When used inside a RadioGroup, inherits the group's appearance unless explicitly set.
     *
     * @public
     * @override
     */
    get appearance() {
        return this._inheritance.get('appearance', super.appearance);
    }
    set appearance(value) {
        this._inheritance.markExplicit('appearance');
        super.appearance = value;
    }
    /**
     * @inheritdoc
     * When used inside a RadioGroup, inherits the group's variant unless explicitly set.
     *
     * @public
     * @override
     */
    get variant() {
        return this._inheritance.get('variant', super.variant);
    }
    set variant(value) {
        this._inheritance.markExplicit('variant');
        super.variant = value;
    }
    /**
     * @inheritdoc
     * When used inside a RadioGroup, inherits the group's dir unless explicitly set.
     *
     * @public
     * @override
     */
    get dir() {
        return this._inheritance.get('dir', super.dir);
    }
    set dir(value) {
        this._inheritance.markExplicit('dir');
        super.dir = value;
    }
    /**
     * Gets or sets the `labelPosition` property.
     *
     * @public
     * @attr
     */
    get labelPosition() {
        return this._labelPosition;
    }
    set labelPosition(value) {
        if (this._labelPosition !== value) {
            this._labelPosition = value;
            this.requestUpdate('labelPosition');
        }
    }
    /**
     * Gets or sets the `required` property.
     *
     * @public
     * @attr
     */
    get required() {
        return this._required;
    }
    set required(value) {
        if (this._required !== value) {
            this._required = value;
            this.requestUpdate('required');
        }
    }
    /**
     * Gets or sets the `name` property.
     * When used inside a RadioGroup, inherits the group's name unless explicitly set.
     *
     * @public
     * @attr
     */
    get name() {
        return this._inheritance.get('name', this._name);
    }
    set name(value) {
        this._inheritance.markExplicit('name');
        if (this._name !== value) {
            this._name = value;
            this.requestUpdate('name');
        }
    }
    // #endregion
    // #region Methods
    /**
     * @public
     * @overload
     */
    connectedCallback() {
        super.connectedCallback();
        this.on('click', (event) => {
            event.stopPropagation();
            // If the radio is already checked, do nothing because radios are single-select and cannot be unchecked.
            if (this._inputElement.checked) {
                return;
            }
            this.toggle();
        });
    }
    /**
     * Resets the element to its initial state.
     *
     * @public
     */
    reset() {
        this.isChecked = false;
        this.invalid = false;
    }
    /**
     * Checks the validity of the element and returns `true` if it is valid; otherwise, `false`.
     *
     * @public
     * @override
     */
    checkValidity() {
        return this.shadowRoot
            ? this._inputElement.checkValidity()
            : true;
    }
    /**
     * @public
     * @override
     */
    check() {
        if (this.disabled) {
            return;
        }
        this._inputElement.focus();
        super.check();
    }
    /**
     * @public
     * @override
     */
    uncheck() {
        if (this.disabled) {
            return;
        }
        this._inputElement.focus();
        super.uncheck();
    }
    /**
     * Toggles the element between checked and unchecked states.
     *
     * @public
     * @override
     */
    toggle() {
        if (this.disabled) {
            return;
        }
        this._inputElement.focus();
        super.toggle();
    }
    /**
     * @protected
     * @override
     */
    onApplyTemplate() {
        super.onApplyTemplate();
        this._inputElement = this.getTemplatePart('input');
    }
};
__decorate([
    Attribute({ type: LabelPosition }),
    __metadata("design:type", String),
    __metadata("design:paramtypes", [String])
], RadioElement.prototype, "labelPosition", null);
__decorate([
    Attribute({
        type: Boolean,
        useDefault: true
    }),
    __metadata("design:type", Boolean),
    __metadata("design:paramtypes", [Boolean])
], RadioElement.prototype, "required", null);
__decorate([
    Attribute({ type: String }),
    __metadata("design:type", String),
    __metadata("design:paramtypes", [String])
], RadioElement.prototype, "name", null);
RadioElement = __decorate([
    Component({
        selector: 'mosaik-radio',
        template: radioElementTemplate,
        themes: {
            joy: radioElementJoyStyle,
            memphis: radioElementMemphisStyle,
            cosmopolitan: radioElementCosmopolitanStyle
        },
        options: {
            mode: 'open',
            delegatesFocus: true
        },
        imports: [
            FocusRingElement,
            CheckmarkElement,
            TextElement
        ]
    }),
    __metadata("design:paramtypes", [])
], RadioElement);
export { RadioElement };
//# sourceMappingURL=RadioElement.js.map