@section('title', 'Withdrawal Management')
@section('withdrawal-management', 'active')
@include('adminDashboard.layout.header')

<div class="main-content">
    <section class="section">
        <div class="section-body">
            <div class="row">
                <div class="col-12">
                    @if (session('success'))
                    <div class="alert alert-success">
                        {{ session('success') }}
                    </div>
                    @endif
                    <div class="card">
                        <div class="card-header">
                            <h4>Withdrawal Requests</h4>
                        </div>
                        <form id="withdrawalHistoryForm">
                            @csrf
                            <div class="card-body">
                                <div class="row">
                                    <div class="col-md-4">
                                        <div class="form-group">
                                            <label>Search User by Mobile</label>
                                            <input type="text" class="form-control" name="user_mobile" id="user_mobile" required>
                                            <div id="user_error" class="error"></div>
                                        </div>
                                    </div>
                                </div>
                                <div class="card-footer p-0">
                                    <input type="submit" class="btn btn-primary mr-1" value="Submit" />
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-12">
                    <div class="card">
                        <div class="card-body p-0">
                            <div class="table-responsive">
                                <table class="table table-striped table-md">
                                    <tr>
                                        <th>ID</th>
                                        <th>Mobile</th>
                                        <th>Amount</th>
                                        <th>Payout</th>
                                        <th>Date</th>
                                        <th>Status</th>
                                        <th>Action</th>
                                    </tr>
                                    <tbody id="withdrawal_table">
                                        @if (count($withdrawals) > 0)
                                        @foreach ($withdrawals as $key => $withdrawal)
                                        <tr>
                                            <td>{{ $withdrawal->id }}</td>
                                            <td>
                                                @if (env('DEMO'))
                                                {{ substr_replace($withdrawal->user->mobile, '*****', 3, 5) }}
                                                @else
                                                {{ $withdrawal->user->mobile }}
                                                @endif
                                            </td>
                                            <td>{{ $withdrawal->amount }}</td>
                                            <td>{{ $withdrawal->payout }}</td>
                                            <td>{{ $withdrawal->created_at }}</td>
                                            <td>
                                                @if ($withdrawal->status == 0)
                                                Pending
                                                @elseif($withdrawal->status == 1)
                                                Approved
                                                @elseif($withdrawal->status == 2)
                                                Rejected
                                                @elseif($withdrawal->status == 3)
                                                Agree
                                                @endif
                                            </td>
                                            <td>
                                                <button type="button" onclick="gatherWithdrawalInfo('{{ $withdrawal->id }}')" class="badge badge-success" style="border:none;" data-toggle="modal" data-target="#exampleModal"><i class="fas fa-ellipsis-h"></i></button>
                                                <a href="{{ url('/admin/withdrawal/delete/' . $withdrawal->id) }}" class="text-decoration-none">
                                                    <div class="badge badge-danger"><i class="material-icons font_size_14">delete</i></div>
                                                </a>
                                            </td>
                                        </tr>
                                        @endforeach
                                        @else
                                        <td colspan="7" class="text-center">No Data Found.</td>
                                        @endif
                                    </tbody>
                                </table>
                            </div>
                        </div>
                        <div class="card-footer text-right" id="pagination">
                            <nav class="d-inline-block">
                                {{ $withdrawals->links('adminDashboard.pagination') }}
                            </nav>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="formModal" aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="formModal">Loading...</h5>
                    <button type="button" class="close" id="mainModal" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <div class="row">
                        <div class="col-12 flex">
                            <div class="col-6">
                                <p>Bank Name</p>
                            </div>
                            <div class="col-6">
                                <p id="bank_name"></p>
                            </div>
                        </div>
                        <div class="col-12 flex">
                            <div class="col-6">
                                <p>Actual Name</p>
                            </div>
                            <div class="col-6">
                                <p id="actual_name"></p>
                            </div>
                        </div>
                        <div class="col-12 flex">
                            <div class="col-6">
                                <p>UPI Id</p>
                            </div>
                            <div class="col-6">
                                <p id="upi"></p>
                            </div>
                        </div>
                        <div class="col-12 flex">
                            <div class="col-6">
                                <p>Account</p>
                            </div>
                            <div class="col-6">
                                <p id="bank_account"></p>
                            </div>
                        </div>
                        <div class="col-12 flex">
                            <div class="col-6">
                                <p>IFSC</p>
                            </div>
                            <div class="col-6">
                                <p id="ifsc"></p>
                            </div>
                        </div>
                        <div class="col-12 flex">
                            <div class="col-6">
                                <p>Account Mobile</p>
                            </div>
                            <div class="col-6">
                                <p id="mobile"></p>

                            </div>
                        </div>
                        <div class="col-12 flex">
                            <div class="col-6">
                                <p>Email</p>
                            </div>
                            <div class="col-6">
                                <p id="email"></p>
                            </div>
                        </div>
                        <div class="col-12 flex">
                            <div class="col-6">
                                <p>Total Withdrawal</p>
                            </div>
                            <div class="col-6">
                                <p id="total_withdrawal"></p>

                            </div>
                        </div>
                        <div class="col-12 flex">
                            <div class="col-6">
                                <p>Total Recharge</p>
                            </div>
                            <div class="col-6">
                                <p id="total_recharge"></p>

                            </div>
                        </div>
                        <div class="col-12 flex">
                            <div class="col-6">
                                <p>Total Rewards</p>
                            </div>
                            <div class="col-6">
                                <p id="total_rewards"></p>

                            </div>
                        </div>
                        <div class="col-12 flex">
                            <div class="col-6">
                                <p>Total Bet</p>
                            </div>
                            <div class="col-6">
                                <p id="total_bet"></p>

                            </div>
                        </div>
                        <div class="col-12 flex">
                            <div class="col-6">
                                <p>Total Betting Amount Won</p>
                            </div>
                            <div class="col-6">
                                <p id="total_betting"></p>

                            </div>
                        </div>
                        <div class="col-12 flex">
                            <div class="col-6">
                                <p>Total Commission</p>
                            </div>
                            <div class="col-6">
                                <p id="total_commission"></p>

                            </div>
                        </div>
                        <div class="col-12 flex">
                            <div class="col-6">
                                <p>Total Interest</p>
                            </div>
                            <div class="col-6">
                                <p id="total_interest"></p>

                            </div>
                        </div>
                        <div class="col-12 flex">
                            <div class="col-6">
                                <p>State</p>
                            </div>
                            <div class="col-6">
                                <p id="state"></p>

                            </div>
                        </div>
                        <div class="col-12 flex">
                            <div class="col-6">
                                <p>City</p>
                            </div>
                            <div class="col-6">
                                <p id="city"></p>

                            </div>
                        </div>
                        <div class="col-12 flex">
                            <div class="col-6">
                                <p>Address</p>
                            </div>
                            <div class="col-6">
                                <p id="address"></p>
                            </div>
                        </div>
                        <div class="col-12 flex" id="reject_reason_section" style="display: none;">
                            <div class="col-6">
                                <p>Rejection Reason</p>
                            </div>
                            <div class="col-6">
                                <p id="rejection_reason"></p>
                            </div>
                        </div>
                    </div>
                    <div class="col-12 text-center" id="withdrawal_actions">
                    </div>
                </div>
            </div>
        </div>
    </div>



    <div class="modal fade" id="exampleModal1" tabindex="-1" role="dialog" aria-labelledby="formModal1" aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="formModal1">Rejection Reason</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <form action="{{ url('/admin/withdrawal/disapprove') }}" method="post">
                        @csrf
                        <input type="hidden" name="reject_id" value="">
                        <div class="row">
                            <div class="col-12 flex">
                                <textarea name="reason" class="form-control" id="reason" required rows="10"></textarea>
                            </div>
                            <div class="col-12">
                                <input type="submit" value="Submit" class="btn btn-success mt-2">
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

</div>
</div>
@include('adminDashboard.layout.footer')