@extends($activeTemplate . 'layouts.master')
@section('content')
    <div class="transaction-section padding-top padding-bottom">
        <div class="container">
            <div class="row justify-content-center">

            </div>
            <div class="primary-bg item-rounded">
                <table class="deposite-table">
                    <thead class="custom--table">
                        <tr>
                            <th>@lang('Date')</th>
                            <th>@lang('Code')</th>
                            <th>@lang('Published At')</th>
                            <th>@lang('Expires At')</th>
                            <th>@lang('Used At')</th>
                            <th>@lang('Status')</th>
                        </tr>
                    </thead>
                    <tbody>
                        @forelse($coupons as $coupon)
                            <tr style="color: {{ $coupon->expires_at > now() ? 'green' : 'red' }}">
                                <td>{{ showDateTime($coupon->created_at) }}</td>
                                <td> <span id="coupon-code-{{ $coupon->id }}">{{ $coupon->code }}</span>
                                <button class="button-copy"
                                        onclick="copyToClipboard('coupon-code-{{ $coupon->id }}')"><i
                                            class="fa fa-copy me-0"></i></button>
                                </td>
                                <td>{{ showDateTime($coupon->published_at) }}</td>
                                <td>{{ showDateTime($coupon->expires_at) }}</td>
                                <td>{{ showDateTime($coupon->used_at) }}</td>
                                <td>
                                    @if ($coupon->status == 1)
                                        <span class="badge badge--success">@lang('Used')</span>
                                    @elseif($coupon->status == 0)
                                        <span class="badge badge--danger">@lang('Unused')</span>
                                    @else
                                        <span class="badge badge-secondary">--</span>
                                    @endif
                                </td>

                            </tr>
                        @empty
                            <tr>
                                <td colspan="100%">{{ __($emptyMessage) }}</td>
                            </tr>
                        @endforelse
                    </tbody>
                </table>
                @if ($coupons->hasPages())
                    <div class="py-3">
                        {{ paginateLinks($coupons) }}
                    </div>
                @endif
            </div>
        </div>
    </div>
@endsection

@push('script')
    <script>
        function copyToClipboard(elementId) {
            var textToCopy = document.getElementById(elementId).textContent.trim();
            var input = document.createElement("input");
            input.setAttribute('value', textToCopy);
            document.body.appendChild(input);
            input.select();
            document.execCommand("copy");
            document.body.removeChild(input);
            notify('success', 'Coupon copied to clipboard');
        }
    </script>
@endpush


@push('style')
<style>
    .button-copy {
        /* padding: 0.25rem 0.5rem; */
        font-size: 0.8rem;
        border: 1px solid #ccc;
        border-radius: 3px;
        background-color: #f0f0f0;
    }
</style>
@endpush
