@extends('admin.layouts.app')

@section('panel')
    <div class="row gy-4">
        <div class="col-lg-4 col-md-4">
            <div class="card overflow-hidden box--shadow1">
                <div class="card-body">
                    <h5 class="mb-20 text-muted">
                        @if ($withdrawal->branch)
                            @lang('Withdrawn from') {{ __(@$withdrawal->branch->name) }}
                        @else
                            @lang('Withdrawn Via') {{ __(@$withdrawal->method->name) }}
                        @endif
                    </h5>
                    <ul class="list-group">
                        <li class="list-group-item d-flex justify-content-between align-items-center">
                            @lang('Date')
                            <span class="fw-bold">{{ showDateTime($withdrawal->created_at) }}</span>
                        </li>

                        <li class="list-group-item d-flex justify-content-between align-items-center">
                            @lang('Trx Number')
                            <span class="fw-bold">{{ $withdrawal->trx }}</span>
                        </li>
                        <li class="list-group-item d-flex justify-content-between align-items-center">
                            @lang('Username')

                            <span class="fw-bold">
                                @can('admin.users.detail')
                                    <a href="{{ route('admin.users.detail', $withdrawal->user_id) }}"><span>@</span>{{ @$withdrawal->user->username }}</a>
                                @else
                                    {{ @$withdrawal->user->username }}
                                @endcan
                            </span>
                        </li>

                        @if ($withdrawal->branch)
                            <li class="list-group-item d-flex justify-content-between align-items-center">
                                @lang('Branch')
                                @can('admin.branch.details')
                                    <a href="{{ route('admin.branch.details', $withdrawal->branch_id) }}" class="fw-bold text--primary">{{ __(@$withdrawal->branch->name) }}</a>
                                @else
                                    {{ __(@$withdrawal->branch->name) }}
                                @endcan
                            </li>

                            <li class="list-group-item d-flex justify-content-between align-items-center">
                                @lang('Withdrawn By')
                                @can('admin.branch.staff.details')
                                    <a href="{{ route('admin.branch.staff.details', $withdrawal->branch_staff_id) }}" class="fw-bold text--primary">{{ __(@$withdrawal->branchStaff->name) }}</a>
                                @else
                                    {{ __(@$withdrawal->branchStaff->name) }}
                                @endcan
                            </li>
                        @else
                            <li class="list-group-item d-flex justify-content-between align-items-center">
                                @lang('Method')
                                <span class="fw-bold">{{ __($withdrawal->method->name) }}</span>
                            </li>
                        @endif

                        <li class="list-group-item d-flex justify-content-between align-items-center">
                            @lang('Amount')
                            <span class="fw-bold">{{ showAmount($withdrawal->amount) }}</span>
                        </li>

                        <li class="list-group-item d-flex justify-content-between align-items-center">
                            @lang('Charge')
                            <span class="fw-bold">{{ showAmount($withdrawal->charge) }}</span>
                        </li>

                        <li class="list-group-item d-flex justify-content-between align-items-center">
                            @lang('After Charge')
                            <span class="fw-bold">{{ showAmount($withdrawal->after_charge) }}</span>
                        </li>
                        <li class="list-group-item d-flex justify-content-between align-items-center">
                            @lang('Rate')
                            <span class="fw-bold">1 {{ __(gs('cur_text')) }} = {{ showAmount($withdrawal->rate, currencyFormat: false) }} {{ __($withdrawal->currency) }}</span>
                        </li>

                        <li class="list-group-item d-flex justify-content-between align-items-center">
                            @lang('Payable')
                            <span class="fw-bold">{{ showAmount($withdrawal->final_amount, currencyFormat: false) }} {{ __($withdrawal->currency) }}</span>
                        </li>

                        <li class="list-group-item d-flex justify-content-between align-items-center">
                            @lang('Status')
                            @php echo $withdrawal->statusBadge @endphp
                        </li>

                        @if ($withdrawal->admin_feedback)
                            <li class="list-group-item">
                                <span class="text-black">@lang('Admin Response')</span>
                                <p class="mt-1">{{ __($withdrawal->admin_feedback) }}</p>
                            </li>
                        @endif
                    </ul>
                </div>
            </div>
        </div>
        <div class="col-lg-8 col-md-8">
            <div class="card overflow-hidden box--shadow1">
                <div class="card-body">
                    <h5 class="card-title border-bottom pb-2">@lang('User Withdraw Information')</h5>

                    @if ($details != null)
                        @foreach (json_decode($details) as $val)
                            <div class="row mt-4">
                                <div class="col-md-12">
                                    <h6>{{ __($val->name) }}</h6>
                                    @if ($val->type == 'checkbox')
                                        {{ implode(',', $val->value) }}
                                    @elseif($val->type == 'file')
                                        @if ($val->value)
                                            <a href="{{ route('admin.download.attachment', encrypt(getFilePath('verify') . '/' . $val->value)) }}"><i class="fa-regular fa-file"></i> @lang('Attachment') </a>
                                        @else
                                            @lang('No File')
                                        @endif
                                    @else
                                        <p>{{ __($val->value) }}</p>
                                    @endif
                                </div>
                            </div>
                        @endforeach
                    @endif

                    @can(['admin.withdraw.data.approve', 'admin.withdraw.data.reject'])
                        @if ($withdrawal->status == Status::PAYMENT_PENDING)
                            <div class="row mt-4">
                                <div class="col-md-12">
                                    @can('admin.withdraw.data.approve')
                                        <button class="btn btn-outline--success btn-sm ms-1" data-bs-toggle="modal" data-bs-target="#approveModal">
                                            <i class="las la-check"></i> @lang('Approve')
                                        </button>
                                    @endcan

                                    @can('admin.withdraw.data.reject')
                                        <button class="btn btn-outline--danger btn-sm ms-1" data-bs-toggle="modal" data-bs-target="#rejectModal">
                                            <i class="las la-ban"></i> @lang('Reject')
                                        </button>
                                    @endcan
                                </div>
                            </div>
                        @endif
                    @endcan
                </div>
            </div>
        </div>
    </div>

    @can('admin.withdraw.data.approve')
        {{-- APPROVE MODAL --}}
        <div id="approveModal" class="modal fade" tabindex="-1" role="dialog">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title">@lang('Approve Withdrawal Confirmation')</h5>
                        <button type="button" class="close" data-bs-dismiss="modal" aria-label="Close">
                            <i class="las la-times"></i>
                        </button>
                    </div>
                    <form action="{{ route('admin.withdraw.data.approve') }}" method="POST">
                        @csrf
                        <input type="hidden" name="id" value="{{ $withdrawal->id }}">
                        <div class="modal-body">
                            <p>@lang('Have you sent') <span class="fw-bold withdraw-amount text--success"></span>?</p>
                            <p class="withdraw-detail"></p>
                            <textarea name="details" class="form-control" value="{{ old('details') }}" rows="3" placeholder="@lang('Provide the details. eg: transaction number')" required></textarea>
                        </div>
                        <div class="modal-footer">
                            <button type="submit" class="btn btn--primary w-100 h-45">@lang('Submit')</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    @endcan

    @can('admin.withdraw.data.reject')
        {{-- REJECT MODAL --}}
        <div id="rejectModal" class="modal fade" tabindex="-1" role="dialog">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title">@lang('Reject Withdrawal Confirmation')</h5>
                        <button type="button" class="close" data-bs-dismiss="modal" aria-label="Close">
                            <i class="las la-times"></i>
                        </button>
                    </div>
                    <form action="{{ route('admin.withdraw.data.reject') }}" method="POST">
                        @csrf
                        <input type="hidden" name="id" value="{{ $withdrawal->id }}">
                        <div class="modal-body">
                            <div class="form-group">
                                <label>@lang('Reason of Rejection')</label>
                                <textarea name="details" class="form-control" rows="3" value="{{ old('details') }}" required></textarea>
                            </div>
                        </div>
                        <div class="modal-footer">
                            <button type="submit" class="btn btn--primary w-100 h-45">@lang('Submit')</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    @endcan
@endsection
