@extends('layout.app')

@section('content')

    <div class="card">
        <div class="card-body">
            <form action="" id="search" class="resellerRechargeLog">
                <div class="row">
                    <div class="col-md-12">
                        <div class="form-group">
                            <label>Select Reseller</label>
                            <select name="reseller" id="reseller" class=" form-control">
                                <option value="">Select One</option>
                                @foreach ($reseller as $r)
                                    <option value="{{ $r->id }}">{{ $r->name }}</option>
                                @endforeach
                            </select>
                        </div>
                    </div>
                    <div class="col-md-12">
                        <label class='block uppercase tracking-wide 
                                                            text-gray-700 text-xs font-bold mb-2'>Select POP
                        </label>
                        <select name="pop" id="pop" class="form-control">
                            <option value="all"> Select One</option>
                        </select>
                    </div>
                    <div class="col-md-12">
                        <div class="form-group float-right mt-2">
                            <button @click="search" class="btn btn-primary" type="submit" id="searchBtn"><i
                                    class="fa fa-search"></i> Search</button>
                            <button class="btn btn-info" type="reset" id="reset">Reset</button>
                        </div>
                    </div>
                </div>

                {{-- <div id="result">

                </div> --}}

            </form>


        </div>
    </div>


    <div class="mt-2 card">
        <div class="card-body">
            {{-- @if (isset($print_url) && !empty($print_url))
                <a href="{{ route($print_url) }}" target="_blank"><i class="fa fa-print"></i></a>
            @endif

            <input type="text" id="customer_search" name="customer_search" class="float-right">

            <br>

            <div id="processing">
                <div>Processing.....</div>
            </div> --}}



            <div id="customer_list_body">
                <div class="table-responsive" >
                    <table id="result" class="table">
                        <thead>
                            <tr>
                                <th scope="col" class="no-wrap">
                                    ID
                                </th>
                                <th scope="col" class="no-wrap">
                                    User name
                                </th>
                                <th scope="col" class="no-wrap">
                                    Status
                                </th>
                                <th scope="col" class="no-wrap">
                                    Expire
                                </th>
                                <th scope="col" class="no-wrap">
                                    Bill Info
                                </th>
                                <th scope="col" class="no-wrap">
                                    Package
                                </th>
                                <th scope="col" class="no-wrap">
                                    POP
                                </th>
                                <th>
                                    Name
                                </th>
                                <th scope="col" style="width:350px">
                                    User Info
                                </th>
                                <th scope="col" class="no-wrap">
                                    Created Date
                                </th>
                                <th scope="col" class="noprin">
                                </th>
                            </tr>
                        </thead>
                        <tbody>
                            @foreach ($list as $r)
                                <tr @if ($r->clients_status == 'deactive') class="deactive" @endif>
                                    <td class="text-center">
                                        <a class="btn btn-info btn-block btn-xs"
                                            href="{{ route('getPaymentHistory', $r->client_id) }}">@php(printf('CID%04d', $r->client_id))</a>
                                        <a href="{{ route('getCustomerLogHistory', $r->userid) }}"
                                            class="noprint btn btn-primary btn-xs btn-block">Log</a>
                                    </td>
                                    <td class="no-wrap">
                                        {{ $r->userid }}
                                        <br>
                                        {{ $r->password }}
                                        <br>
                                        @if (isset($online) && in_array($r->userid, $online))
                                            <span class="btn btn-success btn-xs">Online</span>
                                        @else
                                            <span class="btn btn-danger btn-xs">Ofline</span>
                                        @endif
                                    </td>
                                    @if ($r->clients_status == 'expired')
                                        <td style="background:red" class="deactive">
                                            <x-Custom.Status status="{{ $r->clients_status }}" />
                                        </td>
                                    @elseif($r->clients_status == 'deactive')
                                        <td style="background:red">
                                            <x-Custom.Status status="{{ $r->clients_status }}" />
                                        </td>
                                    @elseif($r->clients_status == 'active')
                                        <td style="background:rgb(0, 119, 255)">
                                            <x-Custom.Status status="{{ $r->clients_status }}" />
                                        </td>
                                    @elseif($r->clients_status == 'disable')
                                        <td style="background:rgb(243, 187, 4)">
                                            <x-Custom.Status status="{{ $r->clients_status }}" />
                                        </td>
                                    @elseif($r->client_approval == 'pending')
                                        <td>
                                            {{ $r->client_approval }}
                                        </td>
                                    @else
                                        <td>
                                            <x-Custom.Status status="{{ $r->clients_status }}" />
                                        </td>
                                    @endif
                                    @if ($r->clients_status == 'expired')
                                        <td style="background:red" class="whitespace-nowrap">
                                            {{ date('d-M-Y', strtotime($r->expire_date)) }}
                                        </td>
                                    @else
                                        <td style="background:rgb(0, 119, 255)" class="whitespace-nowrap">
                                            {{ date('d-M-Y', strtotime($r->expire_date)) }}
                                        </td>
                                    @endif
                                    <td>
                                        <p style="font-size:14px;">
                                            B Cycle: {{ $r->billing_cycle }} <br>
                                        B Amount: @role('Sub Reseller') @if ($r->subreseller == 'yes') {{ $r->sub_package_rate }}  @else {{ $r->package_rate }} @endif @else
                                        {{ $r->package_rate }} @endrole <br>
                                        OTC : {{ $r->otc }}</p>
                                </td>
                                <td class="no-wrap">
                                    @role('Sub Reseller')
                                        @if ($r->subreseller == 'yes')
                                            {{ $r->sub_package_name }}
                                        @else
                                            {{ $r->package_name }}
                                        @endif
                                    @else
                                        {{ $r->package_name }}
                                    @endrole
                                </td>
                                <td class="no-wrap">
                                    {{ $r->popname ?? '' }}
                                </td>
                                <td>
                                    <p style="font-size:14px;">
                                        Name: {{ $r->clients_name ?? '' }}, <br>
                                        C No: {{ $r->contact_no ?? '' }}</p>
                                </td>
                                <td style="width:350px;">
                                    <p style="font-size:14px;">
                                        Flat No: {{ $r->flat_no ?? '' }} ,
                                        Building Name: {{ $r->building_name ?? '' }} ,<br>
                                        Road No: {{ $r->road_no ?? '' }} ,<br>
                                        Block/Sector: {{ $r->block_sector ?? '' }} ,
                                        Area : {{ $r->area ?? '' }} </p>
                                </td>
                                <td class="whitespace-nowrap">
                                    {{ date('d-M-Y', strtotime($r->created_at)) }}
                                </td>
                                <td class="text-center noprint" style="width:160px;">
                                    <div class="dropdown">
                                        <button class="btn btn-primary dropdown-toggle" type="button"
                                            id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true"
                                            aria-expanded="false">
                                            Action
                                        </button>
                                        <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
                                            <a href="{{ route('clients.show', $r->client_id) }}"
                                                class="dropdown-item">Details</a>
                                            @can('mac-customer_edit')
                                                <a href="{{ route('clients.edit', $r->client_id) }}"
                                                    class="dropdown-item">Edit</a>
                                            @endcan
                                            <div class="mb-1"></div>
                                            @if ($r->client_approval == 'pending')
                                                @can('new-customer-approve')
                                                    <form method="POST" action="{{ route('clinetApprove', $r->id) }}">
                                                        @method('post')
                                                        @csrf
                                                        <input type="hidden" name="user_approve"
                                                            value="{{ $r->id }}">
                                                        <button
                                                            onclick="return confirm('Are you sure you want to Approved this user ?');"
                                                            type="submit" class="dropdown-item">Approve</button>
                                                    </form>
                                                @endcan
                                            @endif
                                            @if ($r->clients_status == 'disable')
                                                @can('id-enable')
                                                    <a href="{{ route('idEnable', $r->client_id) }}"
                                                        onclick="return confirm('Are you sure you want to Enable the ID?');"
                                                        class="dropdown-item">Enable</a>
                                                @endcan
                                            @endif
                                            @if ($r->clients_status == 'active')
                                                @can('id-disable')
                                                    <a href="{{ route('idDisable', $r->client_id) }}"
                                                        onclick="return confirm('Are you sure you want to Disable the ID?');"
                                                        class="confirmDisable dropdown-item">Disable</a>
                                                @endcan
                                            @endif
                                            @can('mac-customer_destroy')
                                                <form method="POST"
                                                    action="{{ route('clients.destroy', $r->client_id) }}">
                                                    @method('DELETE')
                                                    @csrf
                                                    <button
                                                        onclick="return confirm('Are you sure you want to Delete this user ?');"
                                                        type="submit" class="dropdown-item">Delete</button>
                                                </form>
                                            @endcan
                                            @can('customer-recharge')
                                                @if ($r->clients_status == 'active')
                                                @endif
                                                @if ($r->clients_status == 'expired')
                                                @endif
                                            @endcan
                                        </div>
                                    </div>
                                </td>
                            </tr>
                        @endforeach
                    </tbody>
                </table>
            </div>
        </div>
    </div>
    <div class="card-footer">
    </div>
</div>

<style>
    div#processing {
        display: none;
    }

    div#processing div {
        background: rgba(0, 0, 0, .5);
        position: fixed;
        width: 100vw;
        height: 100vh;
        color: #fff;
        text-align: center;
        vertical-align: middle;
        display: flex;
        justify-content: center;
        align-items: center;
    }

    @media print {
        a {
            text-decoration: none !important;
            color: #222 !important;
        }

        th {
            font-size: 10px !important;
            padding: 2px !important;
            text-align: center;
        }

        tr {
            font-size: 10px !important;
            margin: 2px !important;
            padding: 2px !important;
        }

        td {
            font-size: 10px !important;
            margin: 2px !important;
            padding: 2px !important;
        }

        table {
            width: 100%;
        }

        .shadow {
            box-shadow: none;
        }

        tr th:last-child {
            display: none !important;
        }

        tr td:last-child {
            display: none !important;
        }

    }

</style>


@endsection

@section('ajax')

<script type="text/javascript">
    $(function() {
        $('#reset').click(function() {
            $('#result').html('');
            $('#pop').html('<option value="all">Select One</option>');
        });

        $('#searchBtn').on('click', function(e) {
            e.preventDefault();
            $('body').append('<div id="processing">processing.....</div>');
            $.ajax({
                type: 'get',
                url: '{{ route('pendingCustomerSearch') }}',
                data: $('#search').serialize(),
                success: function(result) {
                    $('#result').html(result);
                    $('#processing').remove();

                }
            });
        });


        $('#reseller').on('change', function(e) {
            e.preventDefault();
            $('body').append('<div class="hidden" id="processing">processing.....</div>');

            $.ajax({
                type: 'get',
                url: '{{ route('getResellerPopList') }}',
                data: {
                    id: $(this).val()
                },
                success: function(result) {
                    $('#pop').html(result);
                    $('#processing').remove();
                }
            });
        });

    });
</script>

@endsection
