var _a;
import { __decorate, __extends } from "tslib";
import Component from 'vue-class-component';
import { Emit, Model, Prop } from 'vue-property-decorator';
import { InputLabel } from '../../mixins/input-label/input-label';
import { InputManagement } from '../../mixins/input-management/input-management';
import { InputState } from '../../mixins/input-state/input-state';
import { InputWidth } from '../../mixins/input-width/input-width';
import { MediaQueries } from '../../mixins/media-queries/media-queries';
import uuid from '../../utils/uuid/uuid';
import { ModulVue } from '../../utils/vue/vue';
import { I18N_NAME, ICON_BUTTON_NAME, ICON_NAME, INPUT_STYLE_NAME, SELECT_NAME, VALIDATION_MESSAGE_NAME } from '../component-names';
import { MI18n } from '../i18n/i18n';
import { MIconButton } from '../icon-button/icon-button';
import { MIcon } from '../icon/icon';
import { MInputStyle } from '../input-style/input-style';
import { MOpacityTransition } from '../transitions/opacity-transition/opacity-transition';
import { MValidationMessage } from '../validation-message/validation-message';
import { MBaseSelect } from './base-select/base-select';
import WithRender from './select.html?style=./select.scss';
var MSelect = /** @class */ (function (_super) {
    __extends(MSelect, _super);
    function MSelect() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.id = SELECT_NAME + "-" + uuid.generate();
        _this.open = false;
        return _this;
    }
    MSelect.prototype.onSelect = function (option, index, $event) {
        this.$emit('select-item', option, index, $event);
        this.as().model = this.options[index];
    };
    MSelect.prototype.onOpen = function () { };
    MSelect.prototype.onClose = function () { };
    Object.defineProperty(MSelect.prototype, "hasItems", {
        get: function () {
            return this.options && this.options.length > 0;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(MSelect.prototype, "isEmpty", {
        get: function () {
            return this.as().hasValue || (this.open) ? false : true;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(MSelect.prototype, "isClearable", {
        get: function () {
            return this.clearable !== undefined ? this.clearable && this.hasItems && this.as().hasValue && this.isSelectable : this.hasItems && this.as().hasValue && this.isSelectable && !this.as().requiredMarker;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(MSelect.prototype, "selectedItems", {
        get: function () {
            if (this.value) {
                return [this.value];
            }
            return [];
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(MSelect.prototype, "isSelectable", {
        get: function () {
            return !this.as().isDisabled &&
                !this.as().isReadonly;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(MSelect.prototype, "internalLabelUp", {
        get: function () {
            return !this.as().isReadonly ? this.as().labelUp : true;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(MSelect.prototype, "internalPlaceholder", {
        get: function () {
            return !this.as().isReadonly ? this.as().placeholder : '';
        },
        enumerable: true,
        configurable: true
    });
    MSelect.prototype.onReset = function () {
        this.as().model = '';
    };
    MSelect.prototype.onKeyDownDelete = function (event) {
        if (event.key === 'Delete' && this.isClearable) {
            this.onReset();
        }
    };
    __decorate([
        Model('input'),
        Prop()
    ], MSelect.prototype, "value", void 0);
    __decorate([
        Prop()
    ], MSelect.prototype, "options", void 0);
    __decorate([
        Prop()
    ], MSelect.prototype, "clearable", void 0);
    __decorate([
        Prop({ default: false })
    ], MSelect.prototype, "virtualScroll", void 0);
    __decorate([
        Prop()
    ], MSelect.prototype, "listMinWidth", void 0);
    __decorate([
        Emit('open')
    ], MSelect.prototype, "onOpen", null);
    __decorate([
        Emit('close')
    ], MSelect.prototype, "onClose", null);
    MSelect = __decorate([
        WithRender,
        Component({
            components: (_a = {
                    MBaseSelect: MBaseSelect,
                    MOpacityTransition: MOpacityTransition
                },
                _a[INPUT_STYLE_NAME] = MInputStyle,
                _a[ICON_NAME] = MIcon,
                _a[VALIDATION_MESSAGE_NAME] = MValidationMessage,
                _a[I18N_NAME] = MI18n,
                _a[ICON_BUTTON_NAME] = MIconButton,
                _a),
            mixins: [
                InputState,
                MediaQueries,
                InputManagement,
                InputWidth,
                InputLabel
            ]
        })
    ], MSelect);
    return MSelect;
}(ModulVue));
export { MSelect };
var SelectPlugin = {
    install: function (v, options) {
        v.component(SELECT_NAME, MSelect);
    }
};
export default SelectPlugin;
//# sourceMappingURL=select.js.map