// #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 { Emit } from '../../../../../Events/Decorators/EmitDecorator';
import { HTMLElementEventEmitter } from '@breadstone/mosaik-elements';
import { Valueable } from '../../../../Behaviors/Valueable';
import { Attribute } from '../../../../Decorators/AttributeDecorator';
import { CustomElement } from '../../../Abstracts/CustomElement';
// #endregion
/**
 * The `{@link SelectorItemElement}` element.
 *
 * @fires selected - Called when the element is selected.
 * @fires unselected - Called when the element is unselected.
 *
 * @public
 * @abstract
 */
export class SelectorItemElement extends Valueable(CustomElement) {
    // #region Fields
    _selected;
    _unselected;
    _isSelected;
    // #endregion
    // #region Ctor
    /**
     * @public
     */
    constructor() {
        super();
        this._isSelected = false;
        this._selected = new HTMLElementEventEmitter(this, 'selected');
        this._unselected = new HTMLElementEventEmitter(this, 'unselected');
    }
    // #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-selector-item';
    }
    /**
     * Gets or sets the `isSelected` property.
     *
     * @public
     * @attr
     */
    get isSelected() {
        return this._isSelected;
    }
    set isSelected(value) {
        if (this._isSelected !== value) {
            this._isSelected = value;
            this.requestUpdate('isSelected');
        }
    }
    /**
     * Gets the index of the item.
     *
     * @public
     * @readonly
     */
    get index() {
        return this.parent.items.indexOf(this);
    }
    /**
     * Gets the `displayText` property.
     *
     * @public
     * @readonly
     * @hidden
     */
    get displayText() {
        return this.textContent?.trim() ?? '';
    }
    /**
     * Called when <ACTION>.
     * Provides reference to `{@link IEventDetail}` as event detail.
     *
     * @public
     * @readonly
     * @eventProperty
     */
    get selected() {
        return this._selected;
    }
    /**
     * Called when <ACTION>.
     * Provides reference to `{@link IEventDetail}` as event detail.
     *
     * @public
     * @readonly
     * @eventProperty
     */
    get unselected() {
        return this._unselected;
    }
    // #endregion
    // #region Methods
    /**
     * This method is invoked when the `isSelected` property is changed to `true`.
     *
     * @internal
     * @virtual
     */
    select(forceUpdate = false) {
        if (!this._isSelected) {
            this._isSelected = true;
            this._selected.emit();
            if (forceUpdate) {
                this.parent.select(this);
            }
        }
    }
    /**
     * This method is invoked when the `isSelected` property is changed to `false`.
     *
     * @internal
     * @virtual
     */
    unselect(forceUpdate = false) {
        if (this._isSelected) {
            this._isSelected = false;
            this._unselected.emit();
            if (forceUpdate) {
                this.parent.unselect(this);
            }
        }
    }
}
__decorate([
    Attribute({ type: Boolean, useDefault: true }),
    __metadata("design:type", Boolean),
    __metadata("design:paramtypes", [Boolean])
], SelectorItemElement.prototype, "isSelected", null);
__decorate([
    Emit(),
    __metadata("design:type", Object),
    __metadata("design:paramtypes", [])
], SelectorItemElement.prototype, "selected", null);
__decorate([
    Emit(),
    __metadata("design:type", Object),
    __metadata("design:paramtypes", [])
], SelectorItemElement.prototype, "unselected", null);
//# sourceMappingURL=SelectorItemElement.js.map