@extends('layouts.invoice-center')
@section('inner-content')
    <div class="d-flex mb-2 pb-2 align-items-center border-bottom">
        <div class="font-size-14 font-weight-bold">Vouchers</div>
        <div moe class="ml-3">
            <a href="" start show class="btn btn-sm btn-primary font-weight-normal text-white">
                + Add Voucher
            </a>
            <form url="/api/giftCard/create" class="mcp-theme-1">
                <p class="mb-2 text-secondary font-weight-bold">Add Voucher</p>
                <div class="mb-2">
                    <label class="text-sm text-secondary mb-1">Company</label>
                    <input type="hidden" name="companyUid" value="{{@$company->uid}}">
                    <input type="text"
                           name="companyName"
                           target-key="uid"
                           target-field="companyUid"
                           autocomplete="off"
                           class="form-control form-control-sm"
                           stag-suggest
                           stag-suggest-ep="/company-suggest"
                           value="{{@$company ? @$company->name : ''}}"
                           {{@$company ? 'disabled readonly' : ''}}
                           required>
                </div>
                <div class="mb-2">
                    <label class="text-sm text-secondary mb-1">Code</label>
                    <input type="text"
                           name="code"
                           autocomplete="off"
                           class="form-control form-control-sm"
                           required>
                </div>
                <div class="mb-2">
                    <label class="text-sm text-secondary mb-1">Amount</label>
                    <input type="text"
                           name="amount"
                           autocomplete="off"
                           class="form-control form-control-sm"
                           required>
                </div>
                <div>
                    <button submit class="btn btn-sm btn-primary mr-2">Submit</button>
                    <button cancel class="btn btn-sm btn-default border">Cancel</button>
                </div>
            </form>
        </div>
    </div>
    @if(count($records))
        <table class="table table-sm table-bordered table-striped">
            <thead>
            <tr>
                <th class="border-bottom-0"></th>
                <th class="border-bottom-0">Company</th>
                <th class="border-bottom-0">Code</th>
                <th class="border-bottom-0">Amount</th>
                <th class="border-bottom-0">Used?</th>
                <th class="border-bottom-0">Created</th>
                <th class="border-bottom-0">Active?</th>
                <th class="border-bottom-0"></th>
            </tr>
            </thead>
            <tbody>
            <?php $i = 1; ?>
            @foreach($records as $record)
                <tr>
                    <td>{{ $i++ }}</td>
                    <td>{{ $record->company ? $record->company->name : '-' }}</td>
                    <td>{{ $record->code ?: '-' }}</td>
                    <td>${{ !is_null($record->amount) ? $record->amount : 0 }}</td>
                    <td>{{ $record->is_used ? 'Yes' : 'No' }}</td>
                    <td>{{ friendly_date($record->created_at) }}</td>
                    <td class="{{ !$record->is_active ? 'text-warning-dark' : ''}}">{{ $record->is_active ? 'Yes' : 'No' }}</td>
                    <td>
                        @if($record->is_active)
                            <div moe class="ml-3">
                                <a href="" start show>Deactivate</a>
                                <form url="/api/giftCard/deactivate" class="mcp-theme-1" right>
                                    <p class="mb-2 text-nowrap">Deactivate this voucher?</p>
                                    <input type="hidden" name="uid" value="{{$record->uid}}">
                                    <div>
                                        <button submit class="btn btn-sm btn-primary mr-2">Submit</button>
                                        <button cancel class="btn btn-sm btn-default border">Cancel</button>
                                    </div>
                                </form>
                            </div>
                        @else
                            <div moe class="ml-3">
                                <a href="" start show>Reactivate</a>
                                <form url="/api/giftCard/reactivate" class="mcp-theme-1" right>
                                    <p class="mb-2 text-nowrap">Reactivate this voucher?</p>
                                    <input type="hidden" name="uid" value="{{$record->uid}}">
                                    <div>
                                        <button submit class="btn btn-sm btn-primary mr-2">Submit</button>
                                        <button cancel class="btn btn-sm btn-default border">Cancel</button>
                                    </div>
                                </form>
                            </div>
                        @endif
                    </td>
                </tr>
            @endforeach
            </tbody>
        </table>
        {{$records->withQueryString()->links()}}
    @else
        <div class="text-secondary">No vouchers yet!</div>
    @endif
@endsection