@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="{{ url()->previous()}}">
                        <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-crown text-warning me-2"></i>Wallet History
            </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">
                <thead>
                    <tr>
                        <th>Sno</th>
                        <th>Date & Time</th>
                        <th>User ID</th>
                        <th>User Name</th>
                        <th>Phone</th>
                        <th>Credit</th>
                        <th>Debit</th>
                     <th>Type</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 = [
        {
            name: 'Ammu',
            id: 'OM4306',
            phone: '9710585890',
            ref: '2153.23',
            team: '38758.02',
            credit: '5000.00',
            debit: '1500.00',
            type: 'Credit',
            last_wallet: '3000.00',
            investment: 'Unpaid',
            date: '12/10/2025',
            to: '12/12/2025'
        },
    ];

    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,
                render: function (data, type, row, meta) {
                    return meta.row + 1;
                }
            },

            {
                data: 'date'
            },

            {
                data: 'to'
            },

            {
                data: null,
                render: function (data, type, row) {
                    return row.name;
                }
            },

            {
                data: 'phone'
            },

            /* CREDIT COLUMN */
            {
                data: 'credit',
                render: function (data) {
                    return `<span class="badge bg-success">₹ ${data}</span>`;
                }
            },

            /* DEBIT COLUMN */
            {
                data: 'debit',
                render: function (data) {
                    return `<span class="badge bg-danger">₹ ${data}</span>`;
                }
            },
            {
                data:'type'
            }


        ]
    });

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

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

});
</script>

@endsection