var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
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;
};
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 { ModulVue } from '../../../utils/vue/vue';
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: true,
        configurable: true
    });
    Object.defineProperty(MDropdownItem.prototype, "inactive", {
        get: function () {
            return this.value === undefined;
        },
        enumerable: true,
        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: true,
        configurable: true
    });
    Object.defineProperty(MDropdownItem.prototype, "selected", {
        get: function () {
            return this.root.model === this.value && !this.readonly;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(MDropdownItem.prototype, "focused", {
        get: function () {
            return this.root.focused === this.value && !this.readonly;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(MDropdownItem.prototype, "tabindex", {
        get: function () {
            return this.disabled || this.readonly ? undefined : 0;
        },
        enumerable: true,
        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);
    MDropdownItem = __decorate([
        WithRender,
        Component({
            mixins: [MediaQueries]
        })
    ], MDropdownItem);
    return MDropdownItem;
}(ModulVue));
export { MDropdownItem };
//# sourceMappingURL=dropdown-item.js.map