@extends(template().'layout.master2')

@section('content2')

<div class="dashboard-body-part bg-black min-h-screen py-8 px-4">
    <div class="max-w-6xl mx-auto space-y-10">

        <div class="grid grid-cols-1 lg:grid-cols-12 gap-6 items-end">
            <div class="lg:col-span-4">
                <a href="{{ route('user.dashboard') }}" class="inline-flex items-center text-zinc-500 hover:text-emerald-500 transition-colors group mb-4">
                    <i class="bi bi-arrow-left mr-2 group-hover:-translate-x-1 transition-transform"></i> 
                    <span class="text-[10px] font-black uppercase tracking-[0.2em]">{{ __('Back to Terminal') }}</span>
                </a>
                <h4 class="text-white text-2xl font-black tracking-tighter uppercase">{{ __('Affiliate Center') }}</h4>
            </div>

            <div class="lg:col-span-8 w-full">
                <div class="relative group">
                    <label class="block text-[10px] font-black uppercase tracking-[0.2em] text-zinc-500 mb-2 ml-1">
                        {{ __('Your Unique Referral Gateway') }}
                    </label>
                    <div class="flex items-center bg-zinc-900/50 border border-zinc-800 rounded-2xl overflow-hidden focus-within:ring-2 focus-within:ring-emerald-500/40 transition-all">
                        <input type="text" id="refer-link" 
                            class="flex-1 bg-transparent border-none px-4 py-3.5 text-zinc-200 text-sm focus:ring-0 placeholder:text-zinc-700 font-medium"
                            value="{{ route('user.register', @Auth::user()->username) }}" readonly>
                        
                        <button type="button" 
                            class="bg-emerald-600 hover:bg-emerald-500 text-white px-6 py-3.5 font-black text-[10px] uppercase tracking-widest transition-all active:scale-95"
                            onclick="copyLink()">
                            <span id="copytext">{{ __('Copy Link') }}</span>
                        </button>
                    </div>
                </div>
            </div>
        </div>

        <div class="grid grid-cols-2 md:grid-cols-4 gap-4">
            <div class="bg-zinc-950 border border-zinc-800 p-4 rounded-2xl">
                <p class="text-[10px] font-black uppercase tracking-widest text-zinc-500 mb-1">Total Comms</p>
                <p class="text-white font-mono font-bold">{{ number_format($commison->sum('amount'), 2) }}</p>
            </div>
            </div>

        <div class="relative bg-zinc-950 border border-zinc-800 rounded-[2.5rem] overflow-hidden shadow-2xl">
            <div class="absolute -top-24 -left-24 w-64 h-64 bg-emerald-500/5 blur-[100px] rounded-full"></div>

            <div class="relative z-10 p-6 md:p-8">
                <div class="flex flex-col xl:flex-row xl:items-center justify-between gap-6 mb-8">
                    <div>
                        <h5 class="text-white font-black text-sm uppercase tracking-widest">{{ __('Commission Ledger') }}</h5>
                        <p class="text-zinc-500 text-[10px] font-medium mt-1 uppercase tracking-tighter">{{ __('Tracking real-time affiliate network growth') }}</p>
                    </div>

                    <form action="" method="get" class="flex flex-wrap items-center gap-3">
                        <div class="relative">
                            <input type="date" name="date"
                                class="bg-zinc-900 border border-zinc-800 text-zinc-400 rounded-xl px-4 py-2 text-[10px] font-bold uppercase focus:outline-none focus:ring-2 focus:ring-emerald-500/40 transition-all">
                        </div>
                        <button type="submit"
                            class="bg-zinc-100 hover:bg-white text-black font-black px-6 py-2.5 rounded-xl transition-all text-[10px] uppercase tracking-widest">
                            {{ __('Filter History') }}
                        </button>
                    </form>
                </div>

                <div class="overflow-x-auto">
                    <table class="w-full text-left">
                        <thead>
                            <tr class="border-b border-zinc-800">
                                <th class="px-4 py-4 text-[10px] font-black uppercase tracking-[0.2em] text-zinc-500">{{ __('Source') }}</th>
                                <th class="px-4 py-4 text-[10px] font-black uppercase tracking-[0.2em] text-zinc-500">{{ __('Payout') }}</th>
                                <th class="px-4 py-4 text-[10px] font-black uppercase tracking-[0.2em] text-zinc-500">{{ __('Description') }}</th>
                                <th class="px-4 py-4 text-[10px] font-black uppercase tracking-[0.2em] text-zinc-500 text-right">{{ __('Timestamp') }}</th>
                            </tr>
                        </thead>
                        <tbody class="divide-y divide-zinc-900">
                            @forelse ($commison as $item)
                                <tr class="group hover:bg-zinc-900/30 transition-colors">
                                    <td class="px-4 py-5">
                                        <div class="flex items-center gap-3">
                                            <div class="w-8 h-8 rounded-full bg-emerald-500/10 border border-emerald-500/20 flex items-center justify-center text-emerald-500 text-xs font-bold">
                                                {{ substr(@$item->commissionFrom->username, 0, 1) }}
                                            </div>
                                            <span class="text-zinc-200 text-xs font-bold">{{ @$item->commissionFrom->username }}</span>
                                        </div>
                                    </td>
                                    <td class="px-4 py-5 font-mono text-xs font-bold text-emerald-400">
                                        +{{ number_format($item->amount, 2) }} <span class="text-[10px]">{{ @$general->site_currency }}</span>
                                    </td>
                                    <td class="px-4 py-5">
                                        <span class="text-zinc-500 text-xs font-medium">{{ $item->purpouse }}</span>
                                    </td>
                                    <td class="px-4 py-5 text-right">
                                        <span class="text-zinc-600 text-[10px] font-black uppercase">{{ $item->created_at->format('M d, Y') }}</span>
                                    </td>
                                </tr>
                            @empty
                                <tr>
                                    <td class="px-4 py-12 text-center" colspan="100%">
                                        <i class="bi bi-inbox text-zinc-800 text-4xl mb-4 block"></i>
                                        <span class="text-zinc-600 text-[10px] font-black uppercase tracking-widest">{{ __('No network data detected') }}</span>
                                    </td>
                                </tr>
                            @endforelse
                        </tbody>
                    </table>
                </div>

                @if($commison->hasPages())
                <div class="mt-8 pt-8 border-t border-zinc-900">
                    {{ $commison->links('backend.partial.paginate') }}
                </div>
                @endif
            </div>
        </div>
    </div>
</div>

<script>
    function copyLink() {
        const link = document.getElementById('refer-link');
        navigator.clipboard.writeText(link.value);
        const btnText = document.getElementById('copytext');
        btnText.innerText = '{{ __('Copied!') }}';
        setTimeout(() => {
            btnText.innerText = '{{ __('Copy Link') }}';
        }, 2000);
    }
</script>

@endsection