import { __decorate, __extends } from "tslib";
import Component from 'vue-class-component';
import { Emit, Prop, Ref } from 'vue-property-decorator';
import { ModulVue } from '../../../utils/vue/vue';
import { BaseOption } from '../option';
import { MIcon } from './../../icon/icon';
import WithRender from './option-item.html?style=./option-item.scss';
var MOptionItem = /** @class */ (function (_super) {
    __extends(MOptionItem, _super);
    function MOptionItem() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.hasRoot = false;
        return _this;
    }
    MOptionItem.prototype.mounted = function () {
        var rootNode = this.getParent(function (p) { return p instanceof BaseOption; });
        if (rootNode) {
            this.root = rootNode;
            this.hasRoot = true;
        }
        else {
            console.error('m-option-item need to be inside m-option');
        }
    };
    MOptionItem.prototype.emitClick = function (_event) { };
    MOptionItem.prototype.onClick = function (event) {
        if (!this.disabled) {
            if (this.hasRoot) {
                (this.root).close();
                this.emitClick(event);
            }
        }
        else {
            event.stopPropagation();
        }
    };
    Object.defineProperty(MOptionItem.prototype, "hasIconNameProp", {
        get: function () {
            return !!this.iconName;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MOptionItem.prototype, "hasIcon", {
        get: function () {
            if (this.hasRoot) {
                (this.root).checkIcon(this.hasIconNameProp);
                return (this.root).hasIcon;
            }
            return false;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MOptionItem.prototype, "hasDefaultSlot", {
        get: function () {
            return !!this.$slots.default;
        },
        enumerable: false,
        configurable: true
    });
    __decorate([
        Prop()
    ], MOptionItem.prototype, "iconName", void 0);
    __decorate([
        Prop()
    ], MOptionItem.prototype, "disabled", void 0);
    __decorate([
        Ref('button')
    ], MOptionItem.prototype, "refButton", void 0);
    __decorate([
        Emit('click')
    ], MOptionItem.prototype, "emitClick", null);
    MOptionItem = __decorate([
        WithRender,
        Component({
            components: {
                MIcon: MIcon
            }
        })
    ], MOptionItem);
    return MOptionItem;
}(ModulVue));
export { MOptionItem };
//# sourceMappingURL=option-item.js.map