import Ajax from "../ajax.js";

class MessagesDatatable {
    constructor(domItem) {
        this.item = domItem
        this.datatableItem = this.item.find("#tableMessages")
        this.datatablePresupuestoMessageItem = this.item.find("#tablePresupuestoMessages")
        this.datatablePedidoMessageItem = this.item.find("#tablePedidoMessages")
        this.datatableFacturaMessageItem = this.item.find("#tableFacturaMessages")

        this.datatableColumns = [
            { data: 'created_at', searchable: true, sortable: true },
            { data: 'updated_at', searchable: true, sortable: true },
            { data: 'title', searchable: true, sortable: true },
            { data: 'creator', searchable: false, sortable: false },
            {
                data: 'viewed', searchable: false, sortable: false,
                render: (d, t) => {
                    const iconClass = d == true ? "ti ti-sm ti-check" : "ti ti-sm ti-x"
                    return `<span class="${iconClass}"</span>`
                }
            },
            {
                data: 'action', searchable: false, sortable: false,
                render: (d, t) => {
                    return `<div class="btn-group btn-group-sm">
                    <a href="/chat/${d.type}/${d.modelId}" class="message-edit"><i class="ti ti-eye ti-sm mx-2"></i></a>
                </div>`
                }
            }
        ]



    }
    init() {
        this.datatable = this.datatableItem.DataTable({
            processing: true,
            layout: {
                topStart: 'pageLength',
                topEnd: 'search',
                bottomStart: 'info',
                bottomEnd: 'paging'
            },
            serverSide: true,
            pageLength: 10,
            language: {
                url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json"
            },
            columns: this.datatableColumns,
            ajax: '/messages/datatable'
        });

        this.datatablePresupuestoMessage = this.datatablePresupuestoMessageItem.DataTable({
            processing: true,
            layout: {
                topStart: 'pageLength',
                topEnd: 'search',
                bottomStart: 'info',
                bottomEnd: 'paging'
            },
            serverSide: true,
            pageLength: 10,
            language: {
                url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json"
            },
            columns: this.datatableColumns,
            ajax: '/messages/datatable/presupuesto'
        });
        this.datatablePedidoMessage = this.datatablePedidoMessageItem.DataTable({
            processing: true,
            layout: {
                topStart: 'pageLength',
                topEnd: 'search',
                bottomStart: 'info',
                bottomEnd: 'paging'
            },
            serverSide: true,
            pageLength: 10,
            language: {
                url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json"
            },
            columns: this.datatableColumns,
            ajax: '/messages/datatable/pedido'
        });
        this.datatableFacturaMessage = this.datatableFacturaMessageItem.DataTable({
            processing: true,
            layout: {
                topStart: 'pageLength',
                topEnd: 'search',
                bottomStart: 'info',
                bottomEnd: 'paging'
            },
            serverSide: true,
            pageLength: 10,
            language: {
                url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json"
            },
            columns: this.datatableColumns,
            ajax: '/messages/datatable/factura'
        });

    }

}

export default MessagesDatatable;