import { buildEndpoint } from './urlBuilder';
document.addEventListener('DOMContentLoaded', function() {
    const membershipTable = $('#membershipTable');

    if (membershipTable.length) {
        membershipTable.DataTable({
            processing: true,
            serverSide: true,
            scrollX: true,
            autoWidth: false,
            ajax: {
                url: buildEndpoint('admin-fit/membership/json'),
                type: 'GET'
            },
            columns: [
                { data: 'name', name: 'name' ,className: 'text-center'},
                { data: 'days', name: 'days', className: 'text-center' },
                { data: 'price', name: 'price', className: 'text-center' },
                {
                    data: null,
                    name: 'edit',
                    className: 'text-center',
                    orderable: false,
                    searchable: false,
                    render: function(data, type, row) {
                        return `
                            <div class="d-flex justify-content-end gap-2">
                                <a href="${buildEndpoint(`admin-fit/membership/${row.id}/edit`)}" class="btn btn-sm btn-warning">Editar</a>
                            </div>
                        `;
                    }
                }
            ],
            order: [[0, 'desc']]
            ,
            language: {
            "processing":     "Procesando...",
            "search":         "Buscar:",
            "lengthMenu":     "Mostrar _MENU_ registros",
            "info":           "Mostrando registros del _START_ al _END_ de un total de _TOTAL_ registros",
            "infoEmpty":      "Mostrando registros del 0 al 0 de un total de 0 registros",
            "infoFiltered":   "(filtrado de un total de _MAX_ registros)",
            "infoPostFix":    "",
            "loadingRecords": "Cargando...",
            "zeroRecords":    "No se encontraron resultados",
            "emptyTable":     "Ningún dato disponible en esta tabla",
            "paginate": {
                "first":      "Primero",
                "previous":   "Anterior",
                "next":       "Siguiente",
                "last":       "Último"
            },
            "aria": {
                "sortAscending":  ": Activar para ordenar la columna de manera ascendente",
                "sortDescending": ": Activar para ordenar la columna de manera descendente"
            }
        }
        });

    }
});