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

    <h5><button type="button" class="btn btn-icon bg-white me-2 waves-effect waves-light"
            style="box-shadow: 0px 9px 12px -2px #66328E1F;">
            <a href="{{ route('admin.silver_generate') }}">
                <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="#000"
                    stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler">
                    <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
                    <path d="M15 6l-6 6l6 6"></path>
                </svg>
            </a>
        </button>Profit Report</h5>

    <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 class="text-nowrap">#</th>
                                    <th class="text-nowrap">Entry Date</th>
                                    <th class="text-nowrap">From Date</th>
                                    <th class="text-nowrap">To Date</th>
                                    <th class="text-nowrap">Gen Type</th>
                                    <th class="text-nowrap">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 salaryData = [

            {
                id: 1,
                entry_date: '2026-05-17 21:50:56',
                from_date: '2026-05-18 10:00:00',
                to_date: '2026-05-25 10:00:00',
                gen_type: 'Cron'
            },

            {
                id: 2,
                entry_date: '2026-04-15 18:20:10',
                from_date: '2026-04-16 09:30:00',
                to_date: '2026-04-22 09:30:00',
                gen_type: 'Cron'
            },

            {
                id: 3,
                entry_date: '2026-03-10 14:12:45',
                    from_date: '2026-03-11 10:00:00',
                    to_date: '2026-03-17 10:00:00',
                generated_date: '2026-03-11 11:15:00',
                gen_type: 'Manual'
            },

            {
                id: 4,
                entry_date: '2026-02-08 11:45:22',
                from_date: '2026-02-09 08:20:00',
                to_date: '2026-02-16 08:20:00',
                gen_type: 'Cron'
            }

        ];

        let table = $('#usersTable').DataTable({

            data: salaryData,

            pageLength: 10,
            ordering: false,
            searching: true,
            info: true,
            lengthChange: false,

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

            columns: [

                {
                    data: 'id'
                },

                {
                    data: 'entry_date'
                },

                {
                    data: 'from_date'
                },

                {
                    data: 'to_date'
                },

                {
                    data: 'gen_type',
                    render: function (data) {

                        let badgeClass = 'bg-label-primary';

                        if (data === 'Cron') {
                            badgeClass = 'bg-label-info';
                        } else if (data === 'Manual') {
                            badgeClass = 'bg-label-warning';
                        }

                        return `
                            <span class="badge ${badgeClass}">
                                ${data}
                            </span>
                        `;
                    }
                },

                {
                    data: null,
                    orderable: false,
                    searchable: false,
                    render: function () {
                        return `
                            <div class="d-flex flex-column flex-sm-row align-items-stretch align-items-sm-center gap-2 justify-content-center">
                                <a href="{{ route('admin.silver_roi_history')}}" class="btn btn-sm btn-primary">
                                    View
                                </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').on('keyup', function () {
            table.search($(this).val()).draw();
        });

        // Custom Page Length
        $('#pageLength').on('change', function () {

            let value = $(this).val() === 'All'
                ? -1
                : parseInt($(this).val());

            table.page.len(value).draw();

        });

    });
</script>


@endsection
