@extends('admin.layouts.app')

@section('title', 'Supplier Return')
@section('page_title', 'Supplier Return')

@section('content')
@php
    $purchases = $purchases ?? collect();
@endphp

<div class="page-shell">
    <div class="page-head">
        <div>
            <h1 class="page-title">Supplier Return</h1>
            <div class="page-subtitle">Return purchased items back to supplier and adjust stock correctly.</div>
        </div>
        <a href="{{ route('admin.supplier-returns.index') }}" class="btn btn-light">Back to List</a>
    </div>

    <form method="POST" action="{{ route('admin.supplier-returns.store') }}">
        @csrf

        <div class="grid-3">
            <div class="card">
                <label for="purchase_id">Purchase Invoice</label>
                <select id="purchase_id" name="purchase_id">
                    <option value="">Select Purchase</option>
                    @foreach($purchases as $purchase)
                        <option value="{{ $purchase->id }}" @selected(old('purchase_id') == $purchase->id)>{{ $purchase->invoice_no }} - {{ $purchase->product_name }}</option>
                    @endforeach
                </select>
            </div>

            <div class="card">
                <label for="return_date">Return Date</label>
                <input type="date" id="return_date" name="return_date" value="{{ old('return_date', now()->toDateString()) }}">
            </div>

            <div class="card">
                <label for="quantity">Return Quantity</label>
                <input type="number" id="quantity" name="quantity" value="{{ old('quantity', 1) }}" min="1">
            </div>

            <div class="card">
                <label for="amount">Return Amount</label>
                <input type="number" step="0.01" id="amount" name="amount" value="{{ old('amount', 0) }}">
            </div>
        </div>

        <div class="grid-2" style="margin-top:12px;">
            <div class="card">
                <label for="reason">Reason</label>
                <textarea id="reason" name="reason" rows="5">{{ old('reason') }}</textarea>
            </div>

            <div class="card">
                <div class="form-actions">
                    <button type="submit" class="btn primary">Save Supplier Return</button>
                    <a href="{{ route('admin.supplier-returns.index') }}" class="btn btn-light">Cancel</a>
                </div>
            </div>
        </div>
    </form>
</div>
@endsection