"use strict";
Vue.component("costom-select-column-filter", {
    template: "\n    \t<div class=\"ibiz-ag-filter select-filter\">\n\t        <select ref=\"select\" @change=\"valueChanged\">\n\t            <option style='display: none'></option>\n\t            <template v-for=\"item of items\">\n                    <option v-if=\"item.value.toLowerCase() == value.toLowerCase()\" :value=\"item.value\" selected=\"selected\">{{ item.text }}</option>\n                    <option v-else :value=\"item.value\">{{ item.text }}</option>\n\t            </template>\n\t        </select>\n\t        <Icon :class=\"{selectClear: value != ''}\" type=\"ios-close-circle\" @click=\"clear\"/>\n        </div>\n    ",
    data: function () {
        return {
            value: '',
            items: [],
            http: IBizHttp.getInstance(),
            grid: null,
            searchName: ''
        };
    },
    beforeMount: function () {
        var _this = this;
        var column = this.params.column.colDef;
        this.searchName = column.searchName;
        this.grid = this.params.grid;
        if (Object.is(this.params.selectType, 'STATIC')) {
            var viewController = this.grid.getViewController();
            this.items = viewController.getCodeList(this.params.codelistId).data;
        }
        else if (Object.is(this.params.selectType, 'DYNAMIC')) {
            var param = {};
            this.http.post(this.params.url, param).subscribe(function (success) {
                if (success.ret === 0) {
                    _this.items = success.items.slice();
                }
            }, function (error) {
                console.log(error);
            });
        }
    },
    mounted: function () {
        var _this = this;
        this.$nextTick(function () {
            if (_this.grid && _this.grid.colFilterParams) {
                _this.value = _this.grid.colFilterParams[_this.searchName];
                if (_this.value) {
                    _this.params.onFloatingFilterChanged({
                        model: _this.buildModel()
                    });
                }
            }
        });
    },
    methods: {
        valueChanged: function (event) {
            this.value = event.target.value;
            this.params.onFloatingFilterChanged({
                model: this.buildModel()
            });
        },
        clear: function () {
            this.value = "";
            this.$refs.select.value = "";
            this.params.onFloatingFilterChanged({
                model: this.buildModel()
            });
        },
        // onParentModelChanged(parentModel) {
        // 	if(parentModel) {
        // 		this.value = parentModel.filter;
        // 	} else {
        //         if(this.value) {
        //             setTimeout(() => {
        //                 this.params.onFloatingFilterChanged({
        //                     model: this.buildModel()
        //                 });
        //             }, 50)
        //         }
        //     }
        // },
        buildModel: function () {
            return {
                filterType: 'text',
                type: 'contains',
                filter: this.value ? this.value : 'undefined'
            };
        }
    }
});
