<x-app-layout>
    <x-slot name="header">{{ __('Add Sale') }}</x-slot>

    <div class="card shadow-sm">
        <div class="card-body">
            <form action="{{ route('sales.store') }}" method="POST">
                @csrf
                <div class="row g-3 mb-3">
                    <div class="col-md-4">
                        <label class="form-label fw-semibold">{{ __('Invoice No') }}</label>
                        <input type="text" name="invoice_no" class="form-control" value="{{ old('invoice_no', $nextInvoice) }}">
                    </div>
                </div>
                <div class="mb-3">
                    <label for="customer_id" class="form-label">{{ __('Customer') }}</label>
                    <select id="customer_id" name="customer_id" class="form-select">
                        <option value="">{{ __('Select a customer') }}</option>
                        @foreach($customers as $customer)
                            <option value="{{ $customer->id }}">{{ $customer->name }}</option>
                        @endforeach
                    </select>
                </div>
                <div class="row g-3">
                    <div class="col-md-4">
                        <label for="sale_date" class="form-label">{{ __('Date') }}</label>
                        <input id="sale_date" type="date" name="sale_date" class="form-control" value="{{ old('sale_date', now()->format('Y-m-d')) }}" required>
                    </div>
                    <div class="col-md-4">
                        <label for="payment_method" class="form-label">{{ __('Payment Method') }}</label>
                        <select id="payment_method" name="payment_method" class="form-select" required>
                            <option value="cash">{{ __('Cash') }}</option>
                            <option value="card">{{ __('Card') }}</option>
                            <option value="other">{{ __('Other') }}</option>
                        </select>
                    </div>
                    <div class="col-md-4">
                        <label for="sale_source_id" class="form-label">{{ __('Source') }}</label>
                        <select id="sale_source_id" name="sale_source_id" class="form-select">
                            <option value="">{{ __('-- Select Source --') }}</option>
                            @foreach($saleSources as $src)
                                <option value="{{ $src->id }}" {{ old('sale_source_id') == $src->id ? 'selected' : '' }}>{{ $src->name }}</option>
                            @endforeach
                        </select>
                    </div>
                </div>
                <div class="mb-3 mt-3">
                    <label for="amount" class="form-label">{{ __('Amount') }}</label>
                    <input id="amount" type="number" step="0.01" name="amount" class="form-control" value="{{ old('amount') }}" required>
                </div>
                <div class="mb-3">
                    <label for="reference" class="form-label">{{ __('Reference') }}</label>
                    <input id="reference" type="text" name="reference" class="form-control" value="{{ old('reference') }}">
                </div>
                <div class="mb-3">
                    <label for="notes" class="form-label">{{ __('Notes') }}</label>
                    <textarea id="notes" name="notes" class="form-control" rows="3">{{ old('notes') }}</textarea>
                </div>
                <button type="submit" class="btn btn-primary">{{ __('Save Sale') }}</button>
                <a href="{{ route('sales.index') }}" class="btn btn-secondary">{{ __('Cancel') }}</a>
            </form>
        </div>
    </div>
</x-app-layout>
