import { __decorate, __extends } from "tslib";
import Component from 'vue-class-component';
import { Prop } from 'vue-property-decorator';
import { MediaQueries } from '../../../mixins/media-queries/media-queries';
import { normalizeString } from '../../../utils/str/str';
import uuid from '../../../utils/uuid/uuid';
import { ModulVue } from '../../../utils/vue/vue';
import { MRadioStyle } from '../../radio-style/radio-style';
import WithRender from './dropdown-item.html?style=./dropdown-item.scss';
var BaseDropdown = /** @class */ (function (_super) {
    __extends(BaseDropdown, _super);
    function BaseDropdown() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    return BaseDropdown;
}(ModulVue));
export { BaseDropdown };
var BaseDropdownGroup = /** @class */ (function (_super) {
    __extends(BaseDropdownGroup, _super);
    function BaseDropdownGroup() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    return BaseDropdownGroup;
}(ModulVue));
export { BaseDropdownGroup };
var MDropdownItem = /** @class */ (function (_super) {
    __extends(MDropdownItem, _super);
    function MDropdownItem() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    MDropdownItem.prototype.created = function () {
        var rootNode = this.getParent(function (p) { return p instanceof BaseDropdown; });
        if (rootNode) {
            this.root = rootNode;
        }
        else {
            console.error('m-dropdown-item need to be inside m-dropdown');
        }
        this.group = this.getParent(function (p) { return p instanceof BaseDropdownGroup; });
    };
    Object.defineProperty(MDropdownItem.prototype, "filtered", {
        get: function () {
            if (this.propLabel && !this.nonFilterable) {
                return !this.root.matchFilter(normalizeString(this.propLabel));
            }
            else {
                return false;
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MDropdownItem.prototype, "inactive", {
        get: function () {
            return this.value === undefined;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MDropdownItem.prototype, "propLabel", {
        // Value and label rules
        // - If Value and Label : Value = value, Label = label
        // - If only value : value = value, label = value.toString
        // - If only label : value = label, label = label
        // - If none: value = undef, label = undef and item is flag inactive
        get: function () {
            if (this.label) {
                return this.label;
            }
            else if (this.value) {
                if (typeof this.value === 'string') {
                    return this.value;
                }
                else {
                    return JSON.stringify(this.value);
                }
            }
            else {
                return undefined;
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MDropdownItem.prototype, "selected", {
        get: function () {
            return this.root.model === this.value && !this.readonly;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MDropdownItem.prototype, "focused", {
        get: function () {
            return this.root.focused === this.value && !this.readonly;
        },
        enumerable: false,
        configurable: true
    });
    MDropdownItem.prototype.onClick = function () {
        if (!this.inactive && !this.root.inactive && !this.disabled) {
            this.root.model = this.value;
        }
    };
    __decorate([
        Prop()
    ], MDropdownItem.prototype, "label", void 0);
    __decorate([
        Prop()
    ], MDropdownItem.prototype, "value", void 0);
    __decorate([
        Prop()
    ], MDropdownItem.prototype, "disabled", void 0);
    __decorate([
        Prop()
    ], MDropdownItem.prototype, "readonly", void 0);
    __decorate([
        Prop()
    ], MDropdownItem.prototype, "nonFilterable", void 0);
    __decorate([
        Prop({ default: function () { return "mDropdownItem-" + uuid.generate(); } })
    ], MDropdownItem.prototype, "id", void 0);
    MDropdownItem = __decorate([
        WithRender,
        Component({
            components: {
                MRadioStyle: MRadioStyle
            },
            mixins: [MediaQueries]
        })
    ], MDropdownItem);
    return MDropdownItem;
}(ModulVue));
export { MDropdownItem };
//# sourceMappingURL=dropdown-item.js.map