@extends('admin.layouts.app')

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

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

<div class="page-shell">
    <div class="page-head">
        <div>
            <h1 class="page-title">Customer Return</h1>
            <div class="page-subtitle">Create a return entry for sold items and adjust stock safely.</div>
        </div>
        <a href="{{ route('admin.sale-returns.index') }}" class="btn btn-light">Back to List</a>
    </div>

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

        <div class="grid-3">
            <div class="card">
                <label for="sale_id">Sale Invoice</label>
                <select id="sale_id" name="sale_id">
                    <option value="">Select Sale</option>
                    @foreach($sales as $sale)
                        <option value="{{ $sale->id }}" @selected(old('sale_id') == $sale->id)>{{ $sale->invoice_no }} - {{ $sale->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="refund_amount">Refund Amount</label>
                <input type="number" step="0.01" id="refund_amount" name="refund_amount" value="{{ old('refund_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 Return</button>
                    <a href="{{ route('admin.sale-returns.index') }}" class="btn btn-light">Cancel</a>
                </div>
            </div>
        </div>
    </form>
</div>
@endsection