@extends('Admin.layout')
<style>
    .dt-search,
    .dt-length {
        display: none !important;
    }
</style>
@section('content')

    <div class="row d-flex justify-content-between">
        <div class="col-auto">
            <h5>Salary Report</h5>
        </div>
        <div class="col-auto">
            <a href="{{ route('admin.salary_gen') }}"><button class="btn btn-primary">Generate Salary</button></a>
        </div>
    </div>

    <div class="row mt-5">
        <div class="col-lg-12">
            <div class="card">

                <div class="card-body">
                    <div class="row g-3 align-items-center justify-content-between">

                        <!-- LEFT -->
                        <div class="col-12 col-lg-auto">

                            <select id="pageLength" class="form-select">
                                <option value="10">10</option>
                                <option value="25">25</option>
                                <option value="50">50</option>
                                <option value="100">100</option>
                                <option value="All">All</option>
                            </select>

                        </div>

                        <div class="col-12 col-lg-auto">

                            <div class="d-flex flex-column flex-sm-row align-items-stretch align-items-sm-center gap-2">


                                <input type="text" id="customSearch" class="form-control" placeholder="Search table...">

                                <button class="btn btn-label-secondary">
                                    Export
                                </button>
                            </div>

                        </div>

                    </div>

                    <div class="table-responsive">
                        <table id="usersTable" class="table table-striped table-bordered align-middle nowrap w-100">
                            <thead>
                                <tr>

                                    <th>#</th>
                                    <th>Date</th>
                                    <th>Month</th>
                                    <th>Year</th>
                                    <th>Entries</th>
                                    <th>Action</th>
                                </tr>
                            </thead>
                            <tbody>
                            </tbody>
                        </table>

                    </div>
                </div>
            </div>
        </div>
    </div>
    <script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>

    <script src="https://cdn.datatables.net/1.13.8/js/jquery.dataTables.min.js"></script>

    <script src="https://cdn.datatables.net/1.13.8/js/dataTables.bootstrap5.min.js"></script>
<script>
    $(document).ready(function () {

        const data = [
            {
                id: 1,
                date: '18 May 2026',
                month: 'May',
                year: '2026',
                entries: 125
            },
            {
                id: 2,
                date: '15 April 2026',
                month: 'April',
                year: '2026',
                entries: 98
            },
            {
                id: 3,
                date: '10 March 2026',
                month: 'March',
                year: '2026',
                entries: 110
            },
            {
                id: 4,
                date: '12 February 2026',
                month: 'February',
                year: '2026',
                entries: 89
            },
            {
                id: 5,
                date: '08 January 2026',
                month: 'January',
                year: '2026',
                entries: 135
            }
        ];

        let table = $('#usersTable').DataTable({
            data: data,
            pageLength: 10,
            ordering: false,
            searching: true,
            info: true,
            lengthChange: false,

            columnDefs: [
                {
                    targets: '_all',
                    className: 'text-nowrap text-center align-middle'
                }
            ],

            columns: [

                {
                    data: 'id'
                },

                {
                    data: 'date'
                },

                {
                    data: 'month',
                    render: function (data) {
                        return `
                            <span class="badge-month">
                                ${data}
                            </span>
                        `;
                    }
                },

                {
                    data: 'year'
                },

                {
                    data: 'entries',
                    render: function (data) {
                        return `
                            <span class="entries-badge">
                                ${data} Entries
                            </span>
                        `;
                    }
                },

                {
                    data: null,
                    orderable: false,
                    searchable: false,
                    render: function () {
                        return `
                          <div class="d-flex justify-content-center gap-2">

                             <a href="{{ route('admin.salary_list') }}">
                                <i class="ti tabler-eye menu-icon"></i>
                            </a>
                             <a href="#" data-bs-toggle="modal" data-bs-target="#delete">
                                <i class="ti tabler-trash menu-icon text-danger"></i>
                            </a>
                            </div>
                        `;
                    }
                }

            ]
        });

        // Custom Search
        $('#customSearch').keyup(function () {
            table.search($(this).val()).draw();
        });

        // Page Length Change
        $('#pageLength').change(function () {
            let value = $(this).val() === 'All' ? -1 : parseInt($(this).val());
            table.page.len(value).draw();
        });

    });
</script>


@endsection