"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MenuItem = void 0;
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
var host_config_1 = require("../host-config");
var constants_1 = require("./constants");
var MenuItem = /** @class */ (function () {
    function MenuItem(key, value) {
        this._isEnabled = true;
        this.key = key;
        this._value = value;
    }
    MenuItem.prototype.click = function () {
        if (this.isEnabled && this.onClick) {
            this.onClick(this);
        }
    };
    MenuItem.prototype.updateCssClasses = function () {
        if (this._element) {
            var effectiveHostConfig = this._hostConfig ? this._hostConfig : host_config_1.defaultHostConfig;
            this._element.className = effectiveHostConfig.makeCssClassName("ac-ctrl");
            this._element.classList.add(effectiveHostConfig.makeCssClassName(this.isEnabled ? "ac-ctrl-dropdown-item" : "ac-ctrl-dropdown-item-disabled"));
            if (!this.isEnabled) {
                this._element.classList.add(effectiveHostConfig.makeCssClassName("ac-disabled"));
            }
        }
    };
    MenuItem.prototype.toString = function () {
        return this.value;
    };
    MenuItem.prototype.render = function (hostConfig) {
        var _this = this;
        this._hostConfig = hostConfig;
        if (!this._element) {
            this._element = document.createElement("span");
            this._element.innerText = this.value;
            this._element.setAttribute("role", "menuitem");
            if (!this.isEnabled) {
                this._element.setAttribute("aria-disabled", "true");
            }
            this._element.setAttribute("aria-current", "false");
            this._element.onmouseup = function (_e) {
                _this.click();
            };
            this._element.onkeydown = function (e) {
                if (e.key === constants_1.Constants.keys.enter) {
                    e.stopPropagation();
                    e.preventDefault();
                    _this.click();
                }
            };
            this.updateCssClasses();
        }
        return this._element;
    };
    Object.defineProperty(MenuItem.prototype, "value", {
        get: function () {
            return this._value;
        },
        set: function (newValue) {
            this._value = newValue;
            if (this._element) {
                this._element.innerText = newValue;
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MenuItem.prototype, "isEnabled", {
        get: function () {
            return this._isEnabled;
        },
        set: function (value) {
            if (this._isEnabled !== value) {
                this._isEnabled = value;
                this.updateCssClasses();
            }
        },
        enumerable: false,
        configurable: true
    });
    return MenuItem;
}());
exports.MenuItem = MenuItem;
//# sourceMappingURL=menu-item.js.map