@extends('layouts.app')
@section('title', 'Purchase Returns')
@section('breadcrumb')
    @include('components.breadcrumb', ['items' => ['Purchase' => null, 'Returns' => null]])
@endsection
@section('content')
<div>
    <div class="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 mb-6">
        <div>
            <h1 class="text-2xl font-bold text-slate-900 dark:text-white">Purchase Returns</h1>
            <p class="text-sm text-slate-500 mt-1">{{ $returns->total() ?? 0 }} records</p>
        </div>
        <x-button variant="warning" icon="plus" :href="route('purchase-return.create')">New Return</x-button>
    </div>
    <x-card :padding="false">
        <div class="overflow-x-auto">
            <table class="w-full text-sm">
                <thead>
                    <tr class="bg-slate-50 dark:bg-slate-900/50 border-b border-slate-200">
                        <th class="px-4 py-3 text-left text-[11px] font-bold uppercase text-slate-500">Voucher</th>
                        <th class="px-4 py-3 text-left text-[11px] font-bold uppercase text-slate-500">Date</th>
                        <th class="px-4 py-3 text-left text-[11px] font-bold uppercase text-slate-500">Supplier</th>
                        <th class="px-4 py-3 text-left text-[11px] font-bold uppercase text-slate-500">Reason</th>
                        <th class="px-4 py-3 text-right text-[11px] font-bold uppercase text-slate-500">Refund</th>
                        <th class="px-4 py-3 text-center text-[11px] font-bold uppercase text-slate-500">Actions</th>
                    </tr>
                </thead>
                <tbody class="divide-y divide-slate-100">
                    @forelse($returns as $r)
                    <tr class="hover:bg-slate-50/50">
                        <td class="px-4 py-3 text-xs font-mono font-semibold text-primary-600">{{ $r->voucher_no }}</td>
                        <td class="px-4 py-3 text-xs text-slate-500">{{ $r->return_date->format('d M Y') }}</td>
                        <td class="px-4 py-3 text-sm font-medium">{{ $r->party->name ?? '—' }}</td>
                        <td class="px-4 py-3 text-xs text-slate-600">{{ ucfirst($r->reason ?? '—') }}</td>
                        <td class="px-4 py-3 text-right font-bold text-amber-600 counter-num">৳{{ number_format($r->grand_total) }}</td>
                        <td class="px-4 py-3 text-center">
                            <div class="flex items-center justify-center gap-1">
                                <a href="{{ route('purchase-return.show', $r->id) }}" class="w-8 h-8 flex items-center justify-center rounded-lg hover:bg-slate-100"><i data-lucide="eye" class="w-4 h-4"></i></a>
                                <a href="{{ route('purchase-return.edit', $r->id) }}" class="w-8 h-8 flex items-center justify-center rounded-lg hover:bg-slate-100"><i data-lucide="edit-2" class="w-4 h-4"></i></a>
                                <form action="{{ route('purchase-return.destroy', $r->id) }}" method="POST" onsubmit="return confirm('Delete?')" class="inline">
                                    @csrf @method('DELETE')
                                    <button class="w-8 h-8 flex items-center justify-center rounded-lg hover:bg-red-50 text-slate-500 hover:text-red-600"><i data-lucide="trash-2" class="w-4 h-4"></i></button>
                                </form>
                            </div>
                        </td>
                    </tr>
                    @empty
                    <tr><td colspan="6" class="text-center py-8 text-slate-500">No returns found.</td></tr>
                    @endforelse
                </tbody>
            </table>
        </div>
        @if($returns->hasPages())<div class="px-4 py-3 border-t border-slate-200">{{ $returns->withQueryString()->links() }}</div>@endif
    </x-card>
</div>
@endsection
