(function (global, factory) {
    typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('uuid'), require('@sd-angular/core/notify'), require('@sd-angular/core/loading'), require('@angular/material/paginator'), require('@sd-angular/core/export'), require('@sd-angular/core/translate'), require('rxjs'), require('@angular/common'), require('ngx-device-detector'), require('@sd-angular/core/button'), require('@angular/material/slide-toggle'), require('@sd-angular/core/modal'), require('@angular/material/tooltip'), require('@angular/forms'), require('@sd-angular/core/input'), require('@sd-angular/core/utility'), require('@angular/material/icon'), require('@angular/material/menu')) :
    typeof define === 'function' && define.amd ? define('@sd-angular/core/upload-excel', ['exports', '@angular/core', 'uuid', '@sd-angular/core/notify', '@sd-angular/core/loading', '@angular/material/paginator', '@sd-angular/core/export', '@sd-angular/core/translate', 'rxjs', '@angular/common', 'ngx-device-detector', '@sd-angular/core/button', '@angular/material/slide-toggle', '@sd-angular/core/modal', '@angular/material/tooltip', '@angular/forms', '@sd-angular/core/input', '@sd-angular/core/utility', '@angular/material/icon', '@angular/material/menu'], factory) :
    (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global['sd-angular'] = global['sd-angular'] || {}, global['sd-angular'].core = global['sd-angular'].core || {}, global['sd-angular'].core['upload-excel'] = {}), global.ng.core, global.uuid, global['sd-angular'].core.notify, global['sd-angular'].core.loading, global.ng.material.paginator, global['sd-angular'].core.export, global['sd-angular'].core.translate, global.rxjs, global.ng.common, global.ngxDeviceDetector, global['sd-angular'].core.button, global.ng.material.slideToggle, global['sd-angular'].core.modal, global.ng.material.tooltip, global.ng.forms, global['sd-angular'].core.input, global['sd-angular'].core.utility, global.ng.material.icon, global.ng.material.menu));
}(this, (function (exports, core, uuid, notify, loading, paginator, _export, translate, rxjs, common, ngxDeviceDetector, button, slideToggle, modal, tooltip, forms, input, utility, icon, menu) { 'use strict';

    // export type ExcelItem<T> = {
    //   origin?: T;
    //   excelIndex?: number;
    //   validation: SdUploadExcelValidation;
    // } & T;

    /*! *****************************************************************************
    Copyright (c) Microsoft Corporation.

    Permission to use, copy, modify, and/or distribute this software for any
    purpose with or without fee is hereby granted.

    THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
    REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
    AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
    INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
    LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
    OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
    PERFORMANCE OF THIS SOFTWARE.
    ***************************************************************************** */
    /* global Reflect, Promise */
    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 (Object.prototype.hasOwnProperty.call(b, p))
                    d[p] = b[p]; };
        return extendStatics(d, b);
    };
    function __extends(d, b) {
        if (typeof b !== "function" && b !== null)
            throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    }
    var __assign = function () {
        __assign = Object.assign || function __assign(t) {
            for (var s, i = 1, n = arguments.length; i < n; i++) {
                s = arguments[i];
                for (var p in s)
                    if (Object.prototype.hasOwnProperty.call(s, p))
                        t[p] = s[p];
            }
            return t;
        };
        return __assign.apply(this, arguments);
    };
    function __rest(s, e) {
        var t = {};
        for (var p in s)
            if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
                t[p] = s[p];
        if (s != null && typeof Object.getOwnPropertySymbols === "function")
            for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
                if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                    t[p[i]] = s[p[i]];
            }
        return t;
    }
    function __decorate(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;
    }
    function __param(paramIndex, decorator) {
        return function (target, key) { decorator(target, key, paramIndex); };
    }
    function __metadata(metadataKey, metadataValue) {
        if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
            return Reflect.metadata(metadataKey, metadataValue);
    }
    function __awaiter(thisArg, _arguments, P, generator) {
        function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
        return new (P || (P = Promise))(function (resolve, reject) {
            function fulfilled(value) { try {
                step(generator.next(value));
            }
            catch (e) {
                reject(e);
            } }
            function rejected(value) { try {
                step(generator["throw"](value));
            }
            catch (e) {
                reject(e);
            } }
            function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
            step((generator = generator.apply(thisArg, _arguments || [])).next());
        });
    }
    function __generator(thisArg, body) {
        var _ = { label: 0, sent: function () { if (t[0] & 1)
                throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
        return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
        function verb(n) { return function (v) { return step([n, v]); }; }
        function step(op) {
            if (f)
                throw new TypeError("Generator is already executing.");
            while (_)
                try {
                    if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
                        return t;
                    if (y = 0, t)
                        op = [op[0] & 2, t.value];
                    switch (op[0]) {
                        case 0:
                        case 1:
                            t = op;
                            break;
                        case 4:
                            _.label++;
                            return { value: op[1], done: false };
                        case 5:
                            _.label++;
                            y = op[1];
                            op = [0];
                            continue;
                        case 7:
                            op = _.ops.pop();
                            _.trys.pop();
                            continue;
                        default:
                            if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
                                _ = 0;
                                continue;
                            }
                            if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
                                _.label = op[1];
                                break;
                            }
                            if (op[0] === 6 && _.label < t[1]) {
                                _.label = t[1];
                                t = op;
                                break;
                            }
                            if (t && _.label < t[2]) {
                                _.label = t[2];
                                _.ops.push(op);
                                break;
                            }
                            if (t[2])
                                _.ops.pop();
                            _.trys.pop();
                            continue;
                    }
                    op = body.call(thisArg, _);
                }
                catch (e) {
                    op = [6, e];
                    y = 0;
                }
                finally {
                    f = t = 0;
                }
            if (op[0] & 5)
                throw op[1];
            return { value: op[0] ? op[1] : void 0, done: true };
        }
    }
    var __createBinding = Object.create ? (function (o, m, k, k2) {
        if (k2 === undefined)
            k2 = k;
        Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
    }) : (function (o, m, k, k2) {
        if (k2 === undefined)
            k2 = k;
        o[k2] = m[k];
    });
    function __exportStar(m, o) {
        for (var p in m)
            if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
                __createBinding(o, m, p);
    }
    function __values(o) {
        var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
        if (m)
            return m.call(o);
        if (o && typeof o.length === "number")
            return {
                next: function () {
                    if (o && i >= o.length)
                        o = void 0;
                    return { value: o && o[i++], done: !o };
                }
            };
        throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
    }
    function __read(o, n) {
        var m = typeof Symbol === "function" && o[Symbol.iterator];
        if (!m)
            return o;
        var i = m.call(o), r, ar = [], e;
        try {
            while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
                ar.push(r.value);
        }
        catch (error) {
            e = { error: error };
        }
        finally {
            try {
                if (r && !r.done && (m = i["return"]))
                    m.call(i);
            }
            finally {
                if (e)
                    throw e.error;
            }
        }
        return ar;
    }
    /** @deprecated */
    function __spread() {
        for (var ar = [], i = 0; i < arguments.length; i++)
            ar = ar.concat(__read(arguments[i]));
        return ar;
    }
    /** @deprecated */
    function __spreadArrays() {
        for (var s = 0, i = 0, il = arguments.length; i < il; i++)
            s += arguments[i].length;
        for (var r = Array(s), k = 0, i = 0; i < il; i++)
            for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
                r[k] = a[j];
        return r;
    }
    function __spreadArray(to, from, pack) {
        if (pack || arguments.length === 2)
            for (var i = 0, l = from.length, ar; i < l; i++) {
                if (ar || !(i in from)) {
                    if (!ar)
                        ar = Array.prototype.slice.call(from, 0, i);
                    ar[i] = from[i];
                }
            }
        return to.concat(ar || Array.prototype.slice.call(from));
    }
    function __await(v) {
        return this instanceof __await ? (this.v = v, this) : new __await(v);
    }
    function __asyncGenerator(thisArg, _arguments, generator) {
        if (!Symbol.asyncIterator)
            throw new TypeError("Symbol.asyncIterator is not defined.");
        var g = generator.apply(thisArg, _arguments || []), i, q = [];
        return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
        function verb(n) { if (g[n])
            i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
        function resume(n, v) { try {
            step(g[n](v));
        }
        catch (e) {
            settle(q[0][3], e);
        } }
        function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
        function fulfill(value) { resume("next", value); }
        function reject(value) { resume("throw", value); }
        function settle(f, v) { if (f(v), q.shift(), q.length)
            resume(q[0][0], q[0][1]); }
    }
    function __asyncDelegator(o) {
        var i, p;
        return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
        function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
    }
    function __asyncValues(o) {
        if (!Symbol.asyncIterator)
            throw new TypeError("Symbol.asyncIterator is not defined.");
        var m = o[Symbol.asyncIterator], i;
        return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
        function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
        function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
    }
    function __makeTemplateObject(cooked, raw) {
        if (Object.defineProperty) {
            Object.defineProperty(cooked, "raw", { value: raw });
        }
        else {
            cooked.raw = raw;
        }
        return cooked;
    }
    ;
    var __setModuleDefault = Object.create ? (function (o, v) {
        Object.defineProperty(o, "default", { enumerable: true, value: v });
    }) : function (o, v) {
        o["default"] = v;
    };
    function __importStar(mod) {
        if (mod && mod.__esModule)
            return mod;
        var result = {};
        if (mod != null)
            for (var k in mod)
                if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
                    __createBinding(result, mod, k);
        __setModuleDefault(result, mod);
        return result;
    }
    function __importDefault(mod) {
        return (mod && mod.__esModule) ? mod : { default: mod };
    }
    function __classPrivateFieldGet(receiver, state, kind, f) {
        if (kind === "a" && !f)
            throw new TypeError("Private accessor was defined without a getter");
        if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
            throw new TypeError("Cannot read private member from an object whose class did not declare it");
        return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
    }
    function __classPrivateFieldSet(receiver, state, value, kind, f) {
        if (kind === "m")
            throw new TypeError("Private method is not writable");
        if (kind === "a" && !f)
            throw new TypeError("Private accessor was defined without a setter");
        if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
            throw new TypeError("Cannot write private member to an object whose class did not declare it");
        return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
    }

    var SdColumnHiddenPipe = /** @class */ (function () {
        function SdColumnHiddenPipe() {
        }
        SdColumnHiddenPipe.prototype.transform = function (column) {
            if (column.hidden === undefined) {
                return true;
            }
            if (typeof (column.hidden) === 'boolean') {
                return !column.hidden;
            }
            if (typeof (column.hidden) === 'function') {
                return !column.hidden();
            }
            return false;
        };
        return SdColumnHiddenPipe;
    }());
    SdColumnHiddenPipe.decorators = [
        { type: core.Pipe, args: [{
                    name: 'columnHidden'
                },] },
        { type: core.Injectable }
    ];
    SdColumnHiddenPipe.ctorParameters = function () { return []; };

    var _paginator, _subscription, _reset, _reload, _isError, _isWarning, _isSuccess, _parse, _mapItem, _isValidDate, _isValidTime, _isValidDateTime;
    var SdUploadExcel = /** @class */ (function () {
        function SdUploadExcel(ref, exportService, translateService, notifyService, sdColumnHidden, loadingService) {
            var _this = this;
            this.ref = ref;
            this.exportService = exportService;
            this.translateService = translateService;
            this.notifyService = notifyService;
            this.sdColumnHidden = sdColumnHidden;
            this.loadingService = loadingService;
            this.importId = 'I' + uuid.v4();
            this.items = [];
            // originItems: SdExcelItem[] = [];
            this.hasDescription = false;
            this.showing = 'ALL';
            this.filteredItems = [];
            this.viewItems = [];
            this.numberOfSuccess = 0;
            this.numberOfError = 0;
            this.numberOfWarning = 0;
            _paginator.set(this, void 0);
            _subscription.set(this, new rxjs.Subscription());
            this.isDownloadTemplate = false;
            this.sdClosed = new core.EventEmitter();
            this.open = function () {
                __classPrivateFieldGet(_this, _reset).call(_this);
                _this.modal.open();
            };
            this.close = function () {
                _this.modal.close();
            };
            _reset.set(this, function () {
                _this.items = [];
                _this.filteredItems = [];
                _this.viewItems = [];
                _this.numberOfSuccess = 0;
                _this.numberOfError = 0;
                _this.numberOfWarning = 0;
                _this.showing = 'ALL';
            });
            _reload.set(this, function () {
                var pageIndex = __classPrivateFieldGet(_this, _paginator).pageIndex;
                var pageSize = __classPrivateFieldGet(_this, _paginator).pageSize;
                _this.filteredItems = _this.items.filter(function (item) {
                    var validation = item.sd.validation;
                    if (_this.showing === 'SUCCESS') {
                        return !(validation === null || validation === void 0 ? void 0 : validation.error) && !(validation === null || validation === void 0 ? void 0 : validation.warning);
                    }
                    else if (_this.showing === 'WARNING') {
                        return !!(validation === null || validation === void 0 ? void 0 : validation.warning) && !(validation === null || validation === void 0 ? void 0 : validation.error);
                    }
                    else if (_this.showing === 'ERROR') {
                        return !!(validation === null || validation === void 0 ? void 0 : validation.error);
                    }
                    return true;
                });
                _this.viewItems = _this.filteredItems
                    .filter(function (item, index) { return index >= pageIndex * pageSize && index < (pageIndex + 1) * pageSize; });
                _this.numberOfSuccess = _this.items.filter(__classPrivateFieldGet(_this, _isSuccess)).length;
                _this.numberOfError = _this.items.filter(__classPrivateFieldGet(_this, _isError)).length;
                _this.numberOfWarning = _this.items.filter(__classPrivateFieldGet(_this, _isWarning)).length;
            });
            _isError.set(this, function (item) { return !!item.sd.validation.error; });
            _isWarning.set(this, function (item) { var _a, _b; return ((_a = item.sd.validation) === null || _a === void 0 ? void 0 : _a.warning) && !((_b = item.sd.validation) === null || _b === void 0 ? void 0 : _b.error); });
            _isSuccess.set(this, function (item) { var _a, _b; return !((_a = item.sd.validation) === null || _a === void 0 ? void 0 : _a.error) && !((_b = item.sd.validation) === null || _b === void 0 ? void 0 : _b.warning); });
            this.upload = function () { return __awaiter(_this, void 0, void 0, function () {
                var _f, mappingItems, errorValidation, warningValidation, translate, _g, items, file, offset, mappedItems, _h, _j, _k, _l, idx, item, e_1_1, results, results, err_1;
                var e_1, _m;
                var _this = this;
                return __generator(this, function (_o) {
                    switch (_o.label) {
                        case 0:
                            _o.trys.push([0, 17, 18, 19]);
                            _f = this.option, mappingItems = _f.mappingItems, errorValidation = _f.errorValidation, warningValidation = _f.warningValidation;
                            translate = this.translateService.translate;
                            return [4 /*yield*/, this.exportService.uploadXlsx()];
                        case 1:
                            _g = _o.sent(), items = _g.items, file = _g.file;
                            this.hasDescription = this.option.columns.some(function (e) { return !!e.description; });
                            offset = this.hasDescription ? 2 : 1;
                            items.splice(0, offset);
                            if (items.length === 0) {
                                this.notifyService.notify.warning("" + translate("No data to import"));
                                return [2 /*return*/];
                            }
                            if (items.length > this.option.limit) {
                                this.notifyService.notify.warning(translate("Limit rows") + ": " + this.option.limit);
                                return [2 /*return*/];
                            }
                            __classPrivateFieldGet(this, _reset).call(this);
                            // this.originItems = items.map(data => ({
                            //   data,
                            //   sd: {}
                            // }));
                            this.items = items.map(function (data, idx) { return ({
                                data: data,
                                sd: {
                                    excelIndex: idx + (_this.hasDescription ? 4 : 3),
                                    validation: {
                                        data: {}
                                    },
                                    origin: Object.assign({}, data)
                                }
                            }); });
                            if (!mappingItems) return [3 /*break*/, 4];
                            mappedItems = mappingItems(this.items);
                            if (!(mappedItems instanceof Promise)) return [3 /*break*/, 3];
                            this.uploading = true;
                            _h = this;
                            return [4 /*yield*/, mappedItems.finally(function () { return _this.uploading = false; })];
                        case 2:
                            _h.items = (_o.sent());
                            return [3 /*break*/, 4];
                        case 3:
                            this.items = (mappedItems || this.items);
                            _o.label = 4;
                        case 4:
                            this.file = file;
                            this.loadingService.start();
                            _o.label = 5;
                        case 5:
                            _o.trys.push([5, 10, 11, 12]);
                            _j = __values(this.items.entries()), _k = _j.next();
                            _o.label = 6;
                        case 6:
                            if (!!_k.done) return [3 /*break*/, 9];
                            _l = __read(_k.value, 2), idx = _l[0], item = _l[1];
                            return [4 /*yield*/, this.validate(item, idx)];
                        case 7:
                            _o.sent();
                            _o.label = 8;
                        case 8:
                            _k = _j.next();
                            return [3 /*break*/, 6];
                        case 9: return [3 /*break*/, 12];
                        case 10:
                            e_1_1 = _o.sent();
                            e_1 = { error: e_1_1 };
                            return [3 /*break*/, 12];
                        case 11:
                            try {
                                if (_k && !_k.done && (_m = _j.return)) _m.call(_j);
                            }
                            finally { if (e_1) throw e_1.error; }
                            return [7 /*endfinally*/];
                        case 12:
                            if (!(!this.items.some(__classPrivateFieldGet(this, _isError)) && errorValidation)) return [3 /*break*/, 14];
                            return [4 /*yield*/, errorValidation(this.items.map(function (e) { return e.data; }))];
                        case 13:
                            results = _o.sent();
                            results.forEach(function (result) { return _this.items[result.idx].sd.validation.error = result.message; });
                            _o.label = 14;
                        case 14:
                            if (!(!this.items.some(__classPrivateFieldGet(this, _isWarning)) && warningValidation)) return [3 /*break*/, 16];
                            return [4 /*yield*/, warningValidation(this.items.map(function (e) { return e.data; }))];
                        case 15:
                            results = _o.sent();
                            results.forEach(function (result) { return _this.items[result.idx].sd.validation.warning = result.message; });
                            _o.label = 16;
                        case 16:
                            __classPrivateFieldGet(this, _paginator).pageIndex = 0;
                            __classPrivateFieldGet(this, _reload).call(this);
                            this.ref.detectChanges();
                            this.isUploaded = false;
                            return [3 /*break*/, 19];
                        case 17:
                            err_1 = _o.sent();
                            this.notifyService.handle.error(err_1);
                            return [3 /*break*/, 19];
                        case 18:
                            this.loadingService.stop();
                            return [7 /*endfinally*/];
                        case 19: return [2 /*return*/];
                    }
                });
            }); };
            this.validate = function (excelItem, idx) { return __awaiter(_this, void 0, void 0, function () {
                var _a, item, validation, translate, errors, _loop_1, this_1, _f, _g, column, e_2_1;
                var e_2, _h;
                return __generator(this, function (_j) {
                    switch (_j.label) {
                        case 0:
                            item = excelItem.data, validation = excelItem.sd.validation;
                            translate = this.translateService.translate;
                            errors = [];
                            _loop_1 = function (column) {
                                var value, value, value, type, format, val, error, warning, ex_1;
                                return __generator(this, function (_f) {
                                    switch (_f.label) {
                                        case 0:
                                            validation.data[column.field] = {};
                                            if (!this_1.sdColumnHidden.transform(column)) {
                                                return [2 /*return*/, "continue"];
                                            }
                                            _f.label = 1;
                                        case 1:
                                            _f.trys.push([1, 6, , 7]);
                                            if (column.defaultValue !== undefined) {
                                                item[column.field] = (_a = item[column.field]) !== null && _a !== void 0 ? _a : column.defaultValue;
                                            }
                                            else if (column.required && !item[column.field] && item[column.field] !== 0) {
                                                validation.data[column.field].error = "" + translate('required');
                                                errors.push("<strong>[" + (column.title || column.field) + "]</strong> " + validation.data[column.field].error);
                                                return [2 /*return*/, "continue"];
                                            }
                                            if (column.type === 'string') {
                                                value = (item[column.field] || '').toString();
                                                if (column.minLength !== undefined && value.length < column.minLength) {
                                                    validation.data[column.field].error = translate('Min length') + ": " + column.minLength;
                                                    errors.push("<strong>[" + (column.title || column.field) + "]</strong> " + validation.data[column.field].error);
                                                    return [2 /*return*/, "continue"];
                                                }
                                                if (column.maxLength !== undefined && value.length > column.maxLength) {
                                                    validation.data[column.field].error = translate('Max length') + ": " + column.maxLength;
                                                    errors.push("<strong>[" + (column.title || column.field) + "]</strong> " + validation.data[column.field].error);
                                                    return [2 /*return*/, "continue"];
                                                }
                                                item[column.field] = value;
                                            }
                                            else if (column.type === 'number') {
                                                if (item[column.field]) {
                                                    value = +item[column.field];
                                                    if (Number.isNaN(value)) {
                                                        validation.data[column.field].error = item[column.field] + " " + translate('is not a number');
                                                        errors.push("<strong>[" + (column.title || column.field) + "]</strong> " + validation.data[column.field].error);
                                                        return [2 /*return*/, "continue"];
                                                    }
                                                    item[column.field] = value;
                                                }
                                                if (!item[column.field] && item[column.field] !== 0) {
                                                    item[column.field] = undefined;
                                                }
                                                if (column.minValue !== undefined && item[column.field] < column.minValue) {
                                                    validation.data[column.field].error = item[column.field] + " " + translate('Min value') + ": " + column.minValue;
                                                    errors.push("<strong>[" + (column.title || column.field) + "]</strong> " + validation.data[column.field].error);
                                                    return [2 /*return*/, "continue"];
                                                }
                                                if (column.maxValue !== undefined && item[column.field] > column.maxValue) {
                                                    validation.data[column.field].error = item[column.field] + " " + translate('Max value') + ": " + column.maxValue;
                                                    errors.push("<strong>[" + (column.title || column.field) + "]</strong> " + validation.data[column.field].error);
                                                    return [2 /*return*/, "continue"];
                                                }
                                            }
                                            else if (column.type === 'bool') {
                                                if (item[column.field] === 0 || item[column.field] === false) {
                                                    item[column.field] = '0';
                                                }
                                                if (item[column.field] === 1 || item[column.field] === true) {
                                                    item[column.field] = '1';
                                                }
                                                if (item[column.field]) {
                                                    value = +item[column.field];
                                                    if (Number.isNaN(value) || (value !== 0 && value !== 1)) {
                                                        validation.data[column.field].error = "" + translate('Value shoud be 0 or 1');
                                                        errors.push("<strong>[" + (column.title || column.field) + "]</strong> " + validation.data[column.field].error);
                                                    }
                                                    else {
                                                        if (column.parseToBool) {
                                                            item[column.field] = item[column.field] === '1';
                                                        }
                                                    }
                                                }
                                            }
                                            else if (column.type === 'values') {
                                                if (item[column.field] && typeof (item[column.field]) !== 'number' && typeof (item[column.field]) !== 'string') {
                                                    validation.data[column.field].error = item[column.field] + " " + translate('Invalid data type');
                                                    errors.push("<strong>[" + (column.title || column.field) + "]</strong> " + validation.data[column.field].error);
                                                    return [2 /*return*/, "continue"];
                                                }
                                                if (column.checkValueInArray && item[column.field] && !column.values.some(function (e) { return e.toString() === item[column.field].toString(); })) {
                                                    validation.data[column.field].error = item[column.field] + " " + translate('Value not in') + " [" + column.values.join() + "]";
                                                    errors.push("<strong>[" + (column.title || column.field) + "]</strong> " + validation.data[column.field].error);
                                                    return [2 /*return*/, "continue"];
                                                }
                                            }
                                            else if (column.type === 'date' || column.type === 'datetime' || column.type === 'time') {
                                                type = column.type, format = column.format;
                                                val = item[column.field];
                                                if (format && item[column.field]) {
                                                    if (typeof (val) !== 'string') {
                                                        validation.data[column.field].error = translate('Invalid format') + " " + column.format + ": " + val;
                                                        errors.push("<strong>[" + (column.title || column.field) + "]</strong> " + validation.data[column.field].error);
                                                        return [2 /*return*/, "continue"];
                                                    }
                                                    if (type === 'date' && !__classPrivateFieldGet(this_1, _isValidDate).call(this_1, format, val)) {
                                                        validation.data[column.field].error = translate('Invalid format') + " " + column.format + ": " + val;
                                                        errors.push("<strong>[" + (column.title || column.field) + "]</strong> " + validation.data[column.field].error);
                                                        return [2 /*return*/, "continue"];
                                                    }
                                                    if (type === 'time' && !__classPrivateFieldGet(this_1, _isValidTime).call(this_1, format, val)) {
                                                        validation.data[column.field].error = translate('Invalid format') + " " + column.format + ": " + val;
                                                        errors.push("<strong>[" + (column.title || column.field) + "]</strong> " + validation.data[column.field].error);
                                                        return [2 /*return*/, "continue"];
                                                    }
                                                    if (type === 'datetime' && !__classPrivateFieldGet(this_1, _isValidDateTime).call(this_1, format, val)) {
                                                        validation.data[column.field].error = translate('Invalid format') + " " + column.format + ": " + val;
                                                        errors.push("<strong>[" + (column.title || column.field) + "]</strong> " + validation.data[column.field].error);
                                                        return [2 /*return*/, "continue"];
                                                    }
                                                    item[column.field] = Date.parseFrom(val, column.format).toFormat('MM/dd/yyyy HH:mm:ss');
                                                }
                                                if (item[column.field] && !Date.isDate(item[column.field])) {
                                                    validation.data[column.field].error = translate('Invalid date') + ": " + item[column.field];
                                                    errors.push("<strong>[" + (column.title || column.field) + "]</strong> " + validation.data[column.field].error);
                                                    return [2 /*return*/, "continue"];
                                                }
                                            }
                                            if (!(!validation.data[column.field].error && column.errorValidation)) return [3 /*break*/, 3];
                                            return [4 /*yield*/, column.errorValidation(item, item[column.field], idx)];
                                        case 2:
                                            error = _f.sent();
                                            if (error) {
                                                validation.data[column.field].error = "" + error;
                                                errors.push("<strong>[" + (column.title || column.field) + "]</strong> " + validation.data[column.field].error);
                                            }
                                            _f.label = 3;
                                        case 3:
                                            if (!(!validation.data[column.field].warning && column.warningValidation)) return [3 /*break*/, 5];
                                            return [4 /*yield*/, column.warningValidation(item, item[column.field], idx)];
                                        case 4:
                                            warning = _f.sent();
                                            if (warning) {
                                                validation.data[column.field].warning = "" + warning;
                                                validation.warning += "<strong>[" + (column.title || column.field) + "]</strong> " + warning + "<br>";
                                            }
                                            _f.label = 5;
                                        case 5: return [3 /*break*/, 7];
                                        case 6:
                                            ex_1 = _f.sent();
                                            validation.data[column.field].error = "" + ((ex_1 === null || ex_1 === void 0 ? void 0 : ex_1.message) || (ex_1 === null || ex_1 === void 0 ? void 0 : ex_1.error) || ex_1 || 'Có lỗi xảy ra');
                                            errors.push("<strong>[" + (column.title || column.field) + "]</strong> " + validation.data[column.field].error);
                                            return [3 /*break*/, 7];
                                        case 7: return [2 /*return*/];
                                    }
                                });
                            };
                            this_1 = this;
                            _j.label = 1;
                        case 1:
                            _j.trys.push([1, 6, 7, 8]);
                            _f = __values(this.option.columns), _g = _f.next();
                            _j.label = 2;
                        case 2:
                            if (!!_g.done) return [3 /*break*/, 5];
                            column = _g.value;
                            return [5 /*yield**/, _loop_1(column)];
                        case 3:
                            _j.sent();
                            _j.label = 4;
                        case 4:
                            _g = _f.next();
                            return [3 /*break*/, 2];
                        case 5: return [3 /*break*/, 8];
                        case 6:
                            e_2_1 = _j.sent();
                            e_2 = { error: e_2_1 };
                            return [3 /*break*/, 8];
                        case 7:
                            try {
                                if (_g && !_g.done && (_h = _f.return)) _h.call(_f);
                            }
                            finally { if (e_2) throw e_2.error; }
                            return [7 /*endfinally*/];
                        case 8:
                            validation.error = errors.join('<br>');
                            return [2 /*return*/];
                    }
                });
            }); };
            _parse.set(this, function (item) {
                var data = item.data;
                return data;
            });
            _mapItem.set(this, function (item) {
                var data = item.data;
                return data;
            });
            this.accept = function () {
                var _a;
                var successItems = _this.items.filter(__classPrivateFieldGet(_this, _isSuccess)).map(__classPrivateFieldGet(_this, _mapItem));
                var errorItems = _this.items.filter(__classPrivateFieldGet(_this, _isError)).map(__classPrivateFieldGet(_this, _mapItem));
                var warningItems = _this.items.filter(__classPrivateFieldGet(_this, _isWarning)).map(__classPrivateFieldGet(_this, _mapItem));
                (_a = _this.option) === null || _a === void 0 ? void 0 : _a.onAccept(_this.items.map(__classPrivateFieldGet(_this, _mapItem)), successItems, errorItems, warningItems, _this.file);
                _this.isUploaded = true;
            };
            this.setValidation = function (validates) {
                if (Array.isArray(validates)) {
                    validates.forEach(function (validate) {
                        _this.items[validate.idx].sd.validation.error = validate.messageError;
                        _this.items[validate.idx].sd.validation.warning = validate.messageWarning;
                        _this.items[validate.idx].sd.validation.success = validate.messageSuccess;
                    });
                }
                __classPrivateFieldGet(_this, _reload).call(_this);
                _this.ref.detectChanges();
            };
            this.view = function (showing) {
                if (showing === void 0) { showing = 'ALL'; }
                _this.showing = showing;
                __classPrivateFieldGet(_this, _paginator).pageIndex = 0;
                __classPrivateFieldGet(_this, _reload).call(_this);
            };
            this.downloadTemplate = function () { return __awaiter(_this, void 0, void 0, function () {
                var _b, sheets, _f, _g, sheet, _h, _j, _k, e_3_1, columnNotHiddens, excelTemplate;
                var e_3, _l;
                var _this = this;
                return __generator(this, function (_m) {
                    switch (_m.label) {
                        case 0:
                            sheets = [];
                            if (!Array.isArray((_b = this.option) === null || _b === void 0 ? void 0 : _b.sheets)) return [3 /*break*/, 9];
                            _m.label = 1;
                        case 1:
                            _m.trys.push([1, 7, 8, 9]);
                            _f = __values(this.option.sheets), _g = _f.next();
                            _m.label = 2;
                        case 2:
                            if (!!_g.done) return [3 /*break*/, 6];
                            sheet = _g.value;
                            if (!(sheet.name && sheet.items && sheet.fields)) return [3 /*break*/, 5];
                            if (!Array.isArray(sheet.items)) return [3 /*break*/, 3];
                            sheets.push({
                                name: sheet.name,
                                items: sheet.items,
                                fields: sheet.fields
                            });
                            return [3 /*break*/, 5];
                        case 3:
                            _j = (_h = sheets).push;
                            _k = {
                                name: sheet.name
                            };
                            return [4 /*yield*/, sheet.items()];
                        case 4:
                            _j.apply(_h, [(_k.items = _m.sent(),
                                    _k.fields = sheet.fields,
                                    _k)]);
                            _m.label = 5;
                        case 5:
                            _g = _f.next();
                            return [3 /*break*/, 2];
                        case 6: return [3 /*break*/, 9];
                        case 7:
                            e_3_1 = _m.sent();
                            e_3 = { error: e_3_1 };
                            return [3 /*break*/, 9];
                        case 8:
                            try {
                                if (_g && !_g.done && (_l = _f.return)) _l.call(_f);
                            }
                            finally { if (e_3) throw e_3.error; }
                            return [7 /*endfinally*/];
                        case 9:
                            columnNotHiddens = this.option.columns.filter(function (column) { return _this.sdColumnHidden.transform(column); });
                            excelTemplate = {
                                fileName: this.option.fileName || 'Template',
                                columns: columnNotHiddens.map(function (column) {
                                    return {
                                        field: column.field,
                                        title: column.title,
                                        width: column.width,
                                        required: column.required,
                                        description: column.description,
                                        fontColor: column.fontColor,
                                        fill: column.fill
                                    };
                                }),
                                sheets: sheets
                            };
                            this.isDownloadTemplate = true;
                            return [4 /*yield*/, this.exportService.generateTemplate(excelTemplate).finally(function () {
                                    _this.isDownloadTemplate = false;
                                })];
                        case 10:
                            _m.sent();
                            return [2 /*return*/];
                    }
                });
            }); };
            this.export = function () { return __awaiter(_this, void 0, void 0, function () {
                var columns;
                var _this = this;
                return __generator(this, function (_f) {
                    switch (_f.label) {
                        case 0:
                            this.loadingService.start();
                            columns = __spread([{
                                    field: 'sdMessage',
                                    title: this.translateService.translate('Upload message'),
                                    width: '250px',
                                    required: false
                                }], this.option.columns.filter(function (column) { return _this.sdColumnHidden.transform(column); }));
                            return [4 /*yield*/, this.exportService.export({
                                    columns: columns,
                                    items: this.filteredItems.map(function (e) {
                                        var e_4, _f, _g;
                                        var _a, _b, _c, _d, _e;
                                        var result = {};
                                        try {
                                            for (var columns_1 = __values(columns), columns_1_1 = columns_1.next(); !columns_1_1.done; columns_1_1 = columns_1.next()) {
                                                var column = columns_1_1.value;
                                                result = Object.assign(Object.assign({}, result), (_g = {}, _g[column.field] = (_a = e.sd.origin) === null || _a === void 0 ? void 0 : _a[column.field], _g));
                                            }
                                        }
                                        catch (e_4_1) { e_4 = { error: e_4_1 }; }
                                        finally {
                                            try {
                                                if (columns_1_1 && !columns_1_1.done && (_f = columns_1.return)) _f.call(columns_1);
                                            }
                                            finally { if (e_4) throw e_4.error; }
                                        }
                                        return Object.assign(Object.assign({}, result), { sdMessage: (_e = (((_b = e.sd.validation) === null || _b === void 0 ? void 0 : _b.error) || ((_c = e.sd.validation) === null || _c === void 0 ? void 0 : _c.warning) || ((_d = e.sd.validation) === null || _d === void 0 ? void 0 : _d.success))) === null || _e === void 0 ? void 0 : _e.replace(/<strong>/g, '').replace(/<\/strong>/g, '').replace(/<br>/g, '\n') });
                                    })
                                }).finally(this.loadingService.stop)];
                        case 1:
                            _f.sent();
                            return [2 /*return*/];
                    }
                });
            }); };
            _isValidDate.set(this, function (format, value) {
                if ((value === null || value === void 0 ? void 0 : value.length) !== (format === null || format === void 0 ? void 0 : format.length)) {
                    return false;
                }
                var regex = /^(?:(?:31(\/|-|\.)(?:0?[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0?[13-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)0?2\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0?[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0?[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/;
                return regex.test(value);
            });
            _isValidTime.set(this, function (format, value) {
                if ((value === null || value === void 0 ? void 0 : value.length) !== (format === null || format === void 0 ? void 0 : format.length)) {
                    return false;
                }
                return true;
            });
            _isValidDateTime.set(this, function (format, value) {
                if ((value === null || value === void 0 ? void 0 : value.length) !== (format === null || format === void 0 ? void 0 : format.length)) {
                    return false;
                }
                var dates = value === null || value === void 0 ? void 0 : value.split(' ');
                if (dates.length !== 2) {
                    return false;
                }
                var date = dates[0];
                if (!__classPrivateFieldGet(_this, _isValidDate).call(_this, 'dd/MM/yyyy', date)) {
                    return false;
                }
                var time = dates[1];
                var regex = /^(0[0-9]|1[0-9]|2[0-3])(\:)(0[0-9]|[0-5][0-9])$/;
                return regex.test(time);
            });
            this.onClosed = function () {
                _this.sdClosed.emit();
            };
        }
        Object.defineProperty(SdUploadExcel.prototype, "paginator", {
            set: function (paginator) {
                if (paginator && __classPrivateFieldGet(this, _paginator) !== paginator) {
                    __classPrivateFieldSet(this, _paginator, paginator);
                    __classPrivateFieldGet(this, _subscription).add(paginator.page.subscribe(__classPrivateFieldGet(this, _reload)));
                }
            },
            enumerable: false,
            configurable: true
        });
        SdUploadExcel.prototype.ngOnInit = function () {
            this.isUploaded = false;
        };
        SdUploadExcel.prototype.ngOnDestroy = function () {
            __classPrivateFieldGet(this, _subscription).unsubscribe();
        };
        return SdUploadExcel;
    }());
    _paginator = new WeakMap(), _subscription = new WeakMap(), _reset = new WeakMap(), _reload = new WeakMap(), _isError = new WeakMap(), _isWarning = new WeakMap(), _isSuccess = new WeakMap(), _parse = new WeakMap(), _mapItem = new WeakMap(), _isValidDate = new WeakMap(), _isValidTime = new WeakMap(), _isValidDateTime = new WeakMap();
    SdUploadExcel.decorators = [
        { type: core.Component, args: [{
                    selector: 'sd-upload-excel',
                    template: "<sd-modal [title]=\"(option?.title || 'Import Excel')| sdTranslate\" (sdClosed)=\"onClosed()\" #modal>\r\n  <sd-modal-body background=\"#F0F8FF\">\r\n    <div class=\"row mx-0 mb-10\">\r\n      <sd-button *ngIf=\"items?.length\" class=\"mr-5\" (action)=\"view('ALL')\" icon=\"cached\"\r\n        [title]=\"'View all' | sdTranslate\" size=\"sm\"></sd-button>\r\n      <sd-button *ngIf=\"numberOfSuccess\" class=\"mr-5\" (action)=\"view('SUCCESS')\" icon=\"done\" [title]=\"numberOfSuccess\"\r\n        [tooltip]=\"'Number of success rows' | sdTranslate\" size=\"sm\" color=\"success\"></sd-button>\r\n      <sd-button *ngIf=\"numberOfWarning\" class=\"mr-5\" (action)=\"view('WARNING')\" icon=\"warning\"\r\n        [title]=\"numberOfWarning\" [tooltip]=\"'Number of warning rows' | sdTranslate\" size=\"sm\"></sd-button>\r\n      <sd-button *ngIf=\"numberOfError\" class=\"mr-5\" (action)=\"view('ERROR')\" icon=\"error\" [title]=\"numberOfError\"\r\n        color=\"danger\" [tooltip]=\"'Number of error rows' | sdTranslate\" size=\"sm\"></sd-button>\r\n    </div>\r\n    <div class=\"sd-box\">\r\n      <div class=\"sd-box-body p-0\">\r\n        <div class=\"table-responsive\" style=\"position: relative; height:50vh\">\r\n          <table class=\"table table-striped table-sm table-hover table-bordered\">\r\n            <thead class=\"thead-light\">\r\n              <tr>\r\n                <th class=\"text-center position-sticky c-sticky-left\" style=\"width: 50px;vertical-align: middle;\">#</th>\r\n                <th *ngIf=\"filteredItems?.length\" class=\"text-center\"\r\n                  style=\"min-width: 250px; width: 250px;vertical-align: middle;\">\r\n                  {{'Upload message' | sdTranslate}}</th>\r\n                <ng-container *ngFor=\"let column of option.columns\">\r\n                  <th *ngIf=\"column | columnHidden\" [ngStyle]=\"{'min-width':column.width ? column.width : '300px'}\"\r\n                    [matTooltip]=\"column.title\">\r\n                    <span class=\"c-ellipsis\"\r\n                      [ngStyle]=\"{'min-width':column.width ? column.width : '300px', 'max-width':column.width ? column.width : '300px'}\">{{column.title}}</span>\r\n                  </th>\r\n                </ng-container>\r\n              </tr>\r\n            </thead>\r\n            <tbody *ngIf=\"viewItems.length\">\r\n              <tr *ngFor=\"let item of viewItems\">\r\n                <td class=\"text-center position-sticky c-sticky-left\" style=\"width: 50px\">\r\n                  <span class=\"badge\"\r\n                    [ngClass]=\"{'badge-success':!item.sd.validation?.warning && !item.sd.validation?.error, 'badge-warning':item.sd.validation?.warning && !item.sd.validation?.error, 'badge-danger':item.sd.validation?.error}\"\r\n                    style=\"width: 100%\">{{item.sd.excelIndex}}</span>\r\n                </td>\r\n                <td style=\"min-width: 250px; width: 250px\">\r\n                  <div\r\n                    [innerHtml]=\"item.sd.validation?.error || item.sd.validation?.warning || item.sd.validation?.success || ('Success' | sdTranslate)\">\r\n                  </div>\r\n                </td>\r\n                <ng-container *ngFor=\"let column of option.columns\">\r\n                  <td *ngIf=\"column | columnHidden\" class=\"align-middle\" [ngClass]=\"{'table-warning':item.sd.validation?.data[column.field]?.warning && !item.sd.validation?.data[column.field]?.error, \r\n                    'table-danger':item.sd.validation?.data[column.field]?.error}\"\r\n                    [matTooltip]=\"item.sd.validation?.data[column.field]?.error || item.sd.validation?.data[column.field]?.warning\"\r\n                    [ngStyle]=\"{'min-width':column.width ? column.width : '300px'}\" matTooltipPosition=\"above\">\r\n                    <span class=\"c-ellipsis\">\r\n                      <div *ngIf=\"column.type !== 'array'\"\r\n                        [innerHtml]=\"item | columnTransform:column | async | safeHtml\"></div>\r\n                      <ng-container *ngIf=\"column.type === 'array'\">\r\n                        {{item.data[column.field]?.split(column.divideString)?.length}} {{column.unitString}}\r\n                        <button mat-button [matMenuTriggerFor]=\"menu\" class=\"c-mat-menu\">\r\n                          <mat-icon>open_in_new</mat-icon>\r\n                        </button>\r\n                        <mat-menu #menu=\"matMenu\">\r\n                          <div class=\"row mx-0\">\r\n                            <div class=\"col-6\" *ngFor=\"let itemArray of item.data[column.field]?.split(column.divideString)\"\r\n                              [innerHtml]=\"itemArray\">\r\n                            </div>\r\n                          </div>\r\n                        </mat-menu>\r\n                      </ng-container>\r\n                    </span>\r\n                  </td>\r\n                </ng-container>\r\n              </tr>\r\n            </tbody>\r\n          </table>\r\n        </div>\r\n      </div>\r\n      <div class=\"sd-box-footer clearfix\">\r\n        <div style=\"display: flex; align-items: center; align-content: space-between;\">\r\n          <div style=\"flex: 1;\" [innerHTML]=\"option?.note\">\r\n          </div>\r\n          <div style=\"flex: 1;\">\r\n            <mat-paginator [length]=\"filteredItems?.length || 0\" hidePageSize>\r\n            </mat-paginator>\r\n          </div>\r\n        </div>\r\n      </div>\r\n    </div>\r\n  </sd-modal-body>\r\n  <sd-modal-footer *sdDesktop>\r\n    <div class=\"mr-auto\">\r\n      <sd-button class=\"mr-5\" (action)=\"upload()\" icon=\"file_upload\" [title]=\"'Upload' | sdTranslate\" size=\"sm\"\r\n        color=\"info\" [loading]=\"uploading\"></sd-button>\r\n      <sd-button class=\"mr-5\" (action)=\"downloadTemplate()\" icon=\"file_download\" [loading]=\"isDownloadTemplate\"\r\n        [title]=\"'Download template' | sdTranslate\" color=\"info\" type=\"outline\" size=\"sm\">\r\n      </sd-button>\r\n    </div>\r\n    <sd-button *ngIf=\"filteredItems?.length\" class=\"mr-5\" (action)=\"export()\" icon=\"get_app\"\r\n      [title]=\"'Download result' | sdTranslate\" size=\"sm\" color=\"info\" type=\"outline\">\r\n    </sd-button>\r\n    <sd-button (action)=\"accept()\" [title]=\"'Accept' | sdTranslate\"\r\n      [disabled]=\"(numberOfSuccess === 0 && numberOfWarning === 0) || numberOfError > 0 || isUploaded\" color=\"primary\" type=\"fill\" size=\"sm\">\r\n    </sd-button>\r\n  </sd-modal-footer>\r\n  <sd-modal-footer *sdMobileTablet>\r\n    <sd-button style=\"flex: 1; padding-right: 5px;\" (action)=\"upload()\" icon=\"file_upload\"\r\n      [title]=\"'Upload' | sdTranslate\" width=\"100%\" size=\"sm\" color=\"info\" [loading]=\"uploading\"></sd-button>\r\n    <sd-button style=\"flex: 1; padding-left: 5px;\" (action)=\"accept()\" icon=\"check\" [title]=\"'Accept' | sdTranslate\"\r\n      [disabled]=\"(numberOfSuccess === 0 && numberOfWarning === 0) || numberOfError > 0\" color=\"success\" width=\"100%\" size=\"sm\"></sd-button>\r\n  </sd-modal-footer>\r\n</sd-modal>",
                    styles: [".table thead td,.table thead th{padding-bottom:5px;padding-top:5px}.table-striped tbody tr:nth-of-type(2n) .c-sticky-left{background-color:#fff}.table-striped tbody tr:nth-of-type(odd) .c-sticky-left{background-color:#f2f2f2}.c-sticky-left{border-left:none!important;border-right:none!important;left:0!important;z-index:20}.c-ellipsis{display:block;overflow:hidden!important;padding:.1rem;text-overflow:ellipsis;white-space:nowrap}.c-mat-menu{border:none}.c-mat-menu mat-icon{font-size:20px;vertical-align:middle}:host ::ng-deep .mat-paginator-container{height:32px;min-height:32px}:host ::ng-deep .mat-paginator-container .mat-icon-button{height:28px;line-height:28px;width:28px}"]
                },] }
    ];
    SdUploadExcel.ctorParameters = function () { return [
        { type: core.ChangeDetectorRef },
        { type: _export.SdExportService },
        { type: translate.SdTranslateService },
        { type: notify.SdNotifyService },
        { type: SdColumnHiddenPipe },
        { type: loading.SdLoadingService }
    ]; };
    SdUploadExcel.propDecorators = {
        option: [{ type: core.Input }],
        modal: [{ type: core.ViewChild, args: ['modal',] }],
        paginator: [{ type: core.ViewChild, args: [paginator.MatPaginator,] }],
        sdClosed: [{ type: core.Output }]
    };

    var SdColumnTransformPipe = /** @class */ (function () {
        function SdColumnTransformPipe(decimalPipe) {
            var _this = this;
            this.decimalPipe = decimalPipe;
            this.transform = function (rowData, column) { return __awaiter(_this, void 0, void 0, function () {
                var _a, _b, _c, _d, _e, _f, type, transform, value;
                return __generator(this, function (_g) {
                    type = column.type, transform = column.transform;
                    value = rowData.data[column.field];
                    if ((_a = rowData.sd.validation.data[column.field]) === null || _a === void 0 ? void 0 : _a.error) {
                        return [2 /*return*/, (_c = (_b = rowData.sd.origin[column.field]) !== null && _b !== void 0 ? _b : value) !== null && _c !== void 0 ? _c : ''];
                    }
                    if (transform) {
                        return [2 /*return*/, transform(rowData.data, value)];
                    }
                    if (column.type === 'number') {
                        return [2 /*return*/, (_d = Number.toVNCurrency(value)) !== null && _d !== void 0 ? _d : ''];
                    }
                    if (column.type === 'bool') {
                        if (value === '1' || value === true) {
                            return [2 /*return*/, "<div class=\"text-center\"><input type=\"checkbox\" checked disabled></div>"];
                        }
                        else if (value === '0' || value === false) {
                            return [2 /*return*/, "<div class=\"text-center\"><input type=\"checkbox\" disabled></div>"];
                        }
                    }
                    if (column.type === 'date') {
                        return [2 /*return*/, (_e = Date.toFormat(value, column.format || 'dd/MM/yyyy')) !== null && _e !== void 0 ? _e : ''];
                    }
                    if (column.type === 'datetime') {
                        return [2 /*return*/, (_f = Date.toFormat(value, column.format || 'dd/MM/yyyy HH:mm')) !== null && _f !== void 0 ? _f : ''];
                    }
                    return [2 /*return*/, value !== null && value !== void 0 ? value : ''];
                });
            }); };
        }
        return SdColumnTransformPipe;
    }());
    SdColumnTransformPipe.decorators = [
        { type: core.Pipe, args: [{
                    name: 'columnTransform'
                },] }
    ];
    SdColumnTransformPipe.ctorParameters = function () { return [
        { type: common.DecimalPipe }
    ]; };

    var SdUploadExcelModule = /** @class */ (function () {
        function SdUploadExcelModule() {
        }
        return SdUploadExcelModule;
    }());
    SdUploadExcelModule.decorators = [
        { type: core.NgModule, args: [{
                    imports: [
                        common.CommonModule,
                        forms.FormsModule,
                        ngxDeviceDetector.DeviceDetectorModule.forRoot(),
                        slideToggle.MatSlideToggleModule,
                        tooltip.MatTooltipModule,
                        paginator.MatPaginatorModule,
                        slideToggle.MatSlideToggleModule,
                        notify.SdNotifyModule,
                        translate.SdTranslateModule,
                        utility.SdUtilityModule,
                        button.SdButtonModule,
                        modal.SdModalModule,
                        input.SdInputModule,
                        icon.MatIconModule,
                        menu.MatMenuModule
                    ],
                    declarations: [
                        SdUploadExcel,
                        // pipe
                        SdColumnHiddenPipe,
                        SdColumnTransformPipe
                    ],
                    exports: [
                        SdUploadExcel
                    ],
                    providers: [
                        common.DecimalPipe,
                        SdColumnHiddenPipe
                    ]
                },] }
    ];

    /**
     * Generated bundle index. Do not edit.
     */

    exports.SdUploadExcel = SdUploadExcel;
    exports.SdUploadExcelModule = SdUploadExcelModule;
    exports.ɵa = SdColumnHiddenPipe;
    exports.ɵb = SdColumnTransformPipe;

    Object.defineProperty(exports, '__esModule', { value: true });

})));
//# sourceMappingURL=sd-angular-core-upload-excel.umd.js.map
