<?php

namespace App\Traits\Datatable;

trait WithConfiguration
{
    public function configure(): void
    {
        $this->setPrimaryKey('id')
            // Table Configuration
            ->setTableWrapperAttributes([
                'class' => 'overflow-x-auto bg-white shadow ring-1 ring-gray-200 rounded-lg',
            ])
            ->setEmptyMessage('Tidak ada data yang ditemukan.')
            ->setQueryStringDisabled()
            ->setColumnSelectDisabled()
            ->setQueryStringStatusForSearch(false)
            ->setQueryStringStatusForSort(false)
            ->setTableAttributes([
                'class' => 'table table-bordered table-hover align-middle text-nowrap',
            ])

            // Header
            ->setTheadAttributes([
                'class' => 'bg-gray-100 border-b border-gray-200',
            ])

            // Search
            ->setSearchPlaceholder('Cari data...')
            ->setSearchFieldAttributes([
                'class' => 'block w-full max-w-xs px-3 py-2 border border-gray-200 rounded-md focus:outline-none focus:ring-0 focus:ring-emerald-500 focus:border-emerald-500 sm:text-sm',
            ])

            // Sorting
            ->setSortingPillsDisabled()
            ->setSingleSortingEnabled()
            ->setDefaultSort('created_at', 'desc')

            // Filter
            ->setFilterPillsDisabled()
            ->setFilterPopoverAttributes(
                [
                    'class' => 'w-50',
                    'default-width' => false,
                    'default-colors' => true,
                    'default-styling' => true,
                    'x-transition:enter' => 'transition ease-out duration-100',
                ]
            )

            // Pagination
            ->setPerPageFieldAttributes([
                'class' => 'block w-full max-w-xs px-3 py-2 border border-gray-200 rounded-md focus:outline-none focus:ring-0 focus:ring-emerald-500 focus:border-emerald-500 sm:text-sm',
                'default-colors' => true,
                'default-styles' => true,
            ])
            ->setPaginationEnabled(true)
            ->setDefaultPerPage(25)
            ->setPerPageAccepted([25, 50, 100, 1000]);

        if (property_exists($this, 'refreshTime') && $this->refreshTime !== null) {
            $this->setRefreshTime($this->refreshTime);
        }
    }
}
