import { loadDataTable, tomSelect, jodit, datepicker, datetimepicker, timepicker, swiper } from '../plugins';
import { Guard } from '../utils';
import { Crud } from './crud';
import { Ajax } from './ajax';
export class App {
    static boot(config) {
        this.config = config;
        if (typeof this.config?.element === 'string' && this.config?.element !== '')
            if (Guard.hasElement(this.config?.element)) {
                // Plugin dataTable
                if (Guard.isPlugin(this.config?.plugin) && this.config?.plugin?.dataTable) {
                    loadDataTable(this.config?.element, this.config);
                }
                // ajax request
                if (Guard.isPlugin(this.config?.plugin) && this.config?.validation) {
                    Ajax.post(this.config);
                }
                if (!Guard.isPlugin(this.config?.plugin)) {
                    Ajax.make(this.config);
                }
            }
    }
    static bootPlugin() {
        if (this.config?.plugin?.select) {
            tomSelect(this.config?.plugin?.select);
        }
        if (this.config?.plugin?.jodit) {
            jodit(this.config?.plugin?.jodit);
        }
        if (this.config?.plugin?.datepicker) {
            datepicker(this.config?.plugin?.datepicker);
        }
        if (this.config?.plugin?.timepicker) {
            timepicker(this.config?.plugin?.timepicker);
        }
        if (this.config?.plugin?.datetimepicker) {
            datetimepicker(this.config?.plugin?.datetimepicker);
        }
        if (this.config?.plugin?.swiper) {
            swiper(this.config?.plugin?.swiper);
        }
    }
    static bootTable() {
        const el = this.config?.element;
        if (typeof el !== 'string' || !el)
            return;
        window[el] = (_table, api, op) => {
            // PDF
            if (this.pdfConfig?.btn) {
                Crud.downloadPdf({ ...op, ...this.pdfConfig });
            }
            // Excel
            if (this.excelConfig?.btn) {
                Crud.downloadExcel({ ...op, ...this.excelConfig });
            }
            // BULK Update
            if (this.updateConfig?.element) {
                Crud.bulkUpdate({ ...this.updateConfig, api });
            }
            // BULK Delete
            if (this.deleteConfig?.element) {
                Crud.bulkDelete({ ...this.deleteConfig, api });
            }
        };
    }
    static table(config) {
        this.boot(config);
        this.bootTable();
        return this;
    }
    static request(config) {
        this.config = config;
        return this;
    }
    static submit(config) {
        this.config = config;
        Ajax.post(this.config);
        return this;
    }
    static create(config) {
        this.boot(config);
        this.bootPlugin();
        return this;
    }
    static update(config) {
        this.config = config;
        return this;
    }
    static destroy(config) {
        this.config = config;
        return this;
    }
    static bulkUpdate(config) {
        this.updateConfig = config;
        return this;
    }
    static bulkDelete(config) {
        this.deleteConfig = config;
        return this;
    }
    static downloadPdf(config) {
        this.pdfConfig = config;
        return this;
    }
    static downloadExcel(config) {
        this.excelConfig = config;
        return this;
    }
    static beforeSuccess(callback) {
        this.beforeSuccessHandler = callback;
        return this;
    }
    static success(callback) {
        this.successHandler = callback;
        return this;
    }
    static onSuccess(callback) {
        this.successHandler = callback;
        return this;
    }
    static afterSuccess(callback) {
        this.afterSuccessHandler = callback;
        return this;
    }
    static plugin(config) {
        this.config = config;
        this.bootPlugin();
        return this;
    }
    static legacy(config, callback) {
        const {} = config;
        callback();
        return this;
    }
}
App.config = {};
App.deleteConfig = {};
App.updateConfig = {};
App.pdfConfig = {};
App.excelConfig = {};
//# sourceMappingURL=app.js.map