@extends('Admin.layout')

<link rel="stylesheet" href="https://cdn.datatables.net/1.13.6/css/jquery.dataTables.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@tabler/icons-webfont@latest/tabler-icons.min.css">

@section('content')
    <meta name="csrf-token" content="{{ csrf_token() }}">

    <style>
        .dataTables_info,
        .dataTables_paginate {
            padding: 0 18px 18px !important;
        }
    </style>

    <div class="row align-items-center justify-content-between mb-3 mt-3 m-2">
        <div class="col-auto">
            <h5 class="page-title">
                <button type="button" class="btn btn-icon bg-white me-2" style="box-shadow: 0px 9px 12px -2px #66328E1F;">
                    <a href="{{ route('admin.diamond_bob_payout') }}">
                        <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 d="M15 6l-6 6l6 6" />
                        </svg>
                    </a>
                </button><i class="ti tabler-diamond text-warning me-2"></i>Diamond BDB Payout
            </h5>
        </div>
    </div>

    <div class="card main-card m-2">

        <div class="top-filter p-3">
            <div class="row g-3 align-items-end d-flex justify-content-end">
                <div class="col-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-lg-2 col-md-6">
                    <label class="form-label">From Date</label>
                    <input type="date" class="form-control">
                </div>

                <div class="col-lg-2 col-md-6">
                    <label class="form-label">To Date</label>
                    <input type="date" class="form-control">
                </div>

                <div class="col-lg-2 col-md-6">
                    <label class="form-label">User Name</label>
                    <input type="text" class="form-control" placeholder="Search user">
                </div>

                <div class="col-lg-1 col-md-6">
                    <button class="btn btn-primary w-100">
                        <i class="ti tabler-search me-1"></i> Search
                    </button>
                </div>
                <div class="col-md-3 ms-auto">
                    <input type="text" id="customSearch" class="form-control" placeholder="Search table...">
                </div>

                <div class="col-lg-1 col-md-6">
                    <button class="btn btn-label-secondary w-100">
                        <i class="ti tabler-download me-1"></i> Export
                    </button>
                </div>

            </div>
        </div>
        <div class="table-responsive table-wrap">
            <table class="table w-100" id="usersTable">
                <!-- TABLE HEADER -->
                <thead>
                    <tr>
                        <th>
                            <input type="checkbox" id="selectAll">
                        </th>
                        <th>Sno</th>
                        <th>Date</th>
                        <th>User&nbsp;Details</th>
                        <th>Investment</th>
                        <th>Account Details</th>
                        <th>Address</th>
                        <th>Amount</th>
                        <th>TDS</th>
                        <th>Pan No</th>
                        <th>Admin Charge</th>
                        <th>Payable Amount</th>
                        <th>Status</th>
                    </tr>
                </thead>
                <tbody></tbody>
            </table>
        </div>

    </div>

    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script src="https://cdn.datatables.net/1.13.6/js/jquery.dataTables.min.js"></script>

    <script>
        $(document).ready(function () {

            const users = [
                {
                    date: '12/10/2025',
                    name: 'Name',
                    id: 'OM1234',
                    investment: '500000',
                    phone: '2158.23',
                    ac_name: 'Name',
                    ac_num: '2345800',
                    ifsc: 'HDFC679',
                    ref: 'Address',
                    amt: '38758.02',
                    tds: '58.0',
                    pan: 'PBDF0976',
                    charge: '58.0',
                    pay: '1234',
                    sts: 'Unpaid'
                },
                {
                    date: '12/10/2025',
                    name: 'Name',
                    id: 'OM1234',
                    investment: '500000',
                    phone: '2158.23',
                    ac_name: 'Name',
                    ac_num: '2345800',
                    ifsc: 'HDFC679',
                    ref: 'Address',
                    amt: '38758.02',
                    tds: '58.0',
                    pan: 'PBDF0976',
                    charge: '58.0',
                    pay: '1234',
                    sts: 'Unpaid'
                },
                {
                    date: '12/10/2025',
                    name: 'Name',
                    id: 'OM1234',
                    investment: '500000',
                    phone: '2158.23',
                    ac_name: 'Name',
                    ac_num: '2345800',
                    ifsc: 'HDFC679',
                    ref: 'Address',
                    amt: '38758.02',
                    tds: '58.0',
                    pan: 'PBDF0976',
                    charge: '58.0',
                    pay: '1234',
                    sts: 'Unpaid'
                },

            ];

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

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

                columns: [

                    {
                        data: null,
                        orderable: false,
                        searchable: false,
                        render: function (data, type, row, meta) {
                            return `
                        <input type="checkbox" class="row-checkbox" value="${meta.row}">
                    `;
                        }
                    },

                    {
                        data: null,
                        render: function (data, type, row, meta) {
                            return meta.row + 1;
                        }
                    },

                    {
                        data: 'date'
                    },

                    {
                        data: null,
                        render: function (data, type, row) {
                            return `
                        <div class="d-flex flex-column gap-2">
                            <div>User Name: ${row.name}</div>
                            <div>User ID : ${row.id}</div>

                        </div>
                    `;
                        }
                    },

                    {
                        data: 'investment'
                    },
                    {
                        data: null,
                        render: function (data, type, row) {
                            return `
                        <div class="d-flex flex-column gap-2">
                            <div>Account Name: ${row.ac_name}</div>
                            <div>Account Number : ${row.ac_num}</div>
                            <div>IFSC Code : ${row.ifsc}</div>
                        </div>
                    `;
                        }
                    },

                    {
                        data: 'ref'
                    },

                    {
                        data: 'amt'
                    },
                    {
                        data: 'tds'
                    },

                    {
                        data: 'pan'
                    },

                    {
                        data: 'charge'
                    },

                    {
                        data: 'pay'
                    },



                    {
                        data: 'sts',
                        render: function (data) {
                            return ` <span class="text-primary fw-bold">${data}</span>`;
                        }
                    },
                ]
            });

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

            $('#pageLength').change(function () {
                table.page.len($(this).val()).draw();
            });
            $('#selectAll').on('click', function () {
                $('.row-checkbox').prop('checked', $(this).prop('checked'));
            });

            $('#usersTable').on('change', '.row-checkbox', function () {
                let total = $('.row-checkbox').length;
                let checked = $('.row-checkbox:checked').length;

                $('#selectAll').prop('checked', total === checked);
            });

        });
    </script>

@endsection