var _a;
import { __assign, __decorate, __extends } from "tslib";
import { Component, Emit, Prop } from 'vue-property-decorator';
import { ModulVue } from '../../utils/vue/vue';
import { MAdd } from '../add/add';
import { ADD_NAME, ICON_BUTTON_NAME, REPEATER_NAME } from '../component-names';
import { MIconButton } from '../icon-button/icon-button';
import WithRender from './repeater.html?style=./repeater.scss';
var MRepeater = /** @class */ (function (_super) {
    __extends(MRepeater, _super);
    function MRepeater() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    MRepeater.prototype.mounted = function () {
        if (!this.$scopedSlots.row && !this.$scopedSlots.item) {
            throw new Error('MRepeater requires content to be provided through row or item slot.');
        }
    };
    MRepeater.prototype.onAddBtnClick = function () { };
    MRepeater.prototype.onDeleteBtnClick = function (index) { };
    MRepeater.prototype.getRowProps = function (item, index) {
        return __assign(__assign({}, this.getItemProps(item, index)), { canDelete: this.canDelete });
    };
    MRepeater.prototype.getRowListeners = function (item, index) {
        var _this = this;
        return {
            onDelete: function () { return _this.onDeleteBtnClick(index); }
        };
    };
    MRepeater.prototype.getItemKey = function (item, index) {
        return this.itemKey ? item[this.itemKey] : index;
    };
    MRepeater.prototype.getItemProps = function (item, index) {
        return {
            item: item, index: index
        };
    };
    Object.defineProperty(MRepeater.prototype, "addBtnLabel", {
        get: function () {
            return this.addButtonLabel || this.$i18n.translate('m-repeater:add');
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MRepeater.prototype, "deleteBtnLabel", {
        get: function () {
            return this.deleteButtonLabel || this.$i18n.translate('m-repeater:delete');
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MRepeater.prototype, "canAdd", {
        get: function () {
            return this.operations.canAdd && this.list.length < this.maxItemCount;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MRepeater.prototype, "canDelete", {
        get: function () {
            return this.operations.canDelete && this.list.length > this.minItemCount;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MRepeater.prototype, "itemTag", {
        get: function () {
            return this.tag === 'ul' ? 'li' : 'span';
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MRepeater.prototype, "hasRowSlot", {
        get: function () {
            return !!this.$scopedSlots.row;
        },
        enumerable: false,
        configurable: true
    });
    __decorate([
        Prop({
            required: true
        })
    ], MRepeater.prototype, "list", void 0);
    __decorate([
        Prop()
    ], MRepeater.prototype, "addButtonLabel", void 0);
    __decorate([
        Prop()
    ], MRepeater.prototype, "deleteButtonLabel", void 0);
    __decorate([
        Prop()
    ], MRepeater.prototype, "emptyMessage", void 0);
    __decorate([
        Prop({
            default: 'ul'
        })
    ], MRepeater.prototype, "tag", void 0);
    __decorate([
        Prop()
    ], MRepeater.prototype, "itemKey", void 0);
    __decorate([
        Prop({
            default: function () { return ({
                canAdd: true,
                canDelete: true
            }); }
        })
    ], MRepeater.prototype, "operations", void 0);
    __decorate([
        Prop({
            default: 0
        })
    ], MRepeater.prototype, "minItemCount", void 0);
    __decorate([
        Prop({
            default: Infinity
        })
    ], MRepeater.prototype, "maxItemCount", void 0);
    __decorate([
        Emit('add')
    ], MRepeater.prototype, "onAddBtnClick", null);
    __decorate([
        Emit('delete')
    ], MRepeater.prototype, "onDeleteBtnClick", null);
    MRepeater = __decorate([
        WithRender,
        Component({
            components: (_a = {},
                _a[ICON_BUTTON_NAME] = MIconButton,
                _a[ADD_NAME] = MAdd,
                _a)
        })
    ], MRepeater);
    return MRepeater;
}(ModulVue));
export { MRepeater };
var RepeaterPlugin = {
    install: function (v) {
        v.component(REPEATER_NAME, MRepeater);
    }
};
export default RepeaterPlugin;
//# sourceMappingURL=repeater.js.map