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

    <div class="card shadow-sm">
        <div class="card-body">
            <form action="{{ route('customer-ledgers.store') }}" method="POST">
                @csrf

                <div class="row g-3">
                    <div class="col-md-6">
                        <label class="form-label" for="customer_id">{{ __('Customer') }}</label>
                        <select id="customer_id" name="customer_id" class="form-select" required>
                            <option value="">-- {{ __('Select Customer') }} --</option>
                            @foreach($customers as $c)
                                <option value="{{ $c->id }}" {{ old('customer_id') == $c->id ? 'selected' : '' }}>
                                    {{ $c->name }}
                                </option>
                            @endforeach
                        </select>
                    </div>
                    <div class="col-md-6">
                        <label class="form-label" for="transaction_date">{{ __('Date') }}</label>
                        <input id="transaction_date" type="date" name="transaction_date" class="form-control"
                               value="{{ old('transaction_date', now()->format('Y-m-d')) }}" required>
                    </div>
                </div>

                <div class="row g-3 mt-1">
                    <div class="col-md-6">
                        <label class="form-label" for="type">{{ __('Type') }}</label>
                        <select id="type" name="type" class="form-select" required>
                            <option value="credit" {{ old('type') == 'credit' ? 'selected' : '' }}>{{ __('Credit (Sale / Due)') }}</option>
                            <option value="payment" {{ old('type') == 'payment' ? 'selected' : '' }}>{{ __('Payment (Received)') }}</option>
                            <option value="adjustment" {{ old('type') == 'adjustment' ? 'selected' : '' }}>{{ __('Adjustment') }}</option>
                        </select>
                    </div>
                    <div class="col-md-6">
                        <label class="form-label" for="amount">{{ __('Amount') }}</label>
                        <input id="amount" type="number" step="0.01" min="0" name="amount"
                               class="form-control" value="{{ old('amount') }}" required>
                    </div>
                </div>

                <div class="mt-3">
                    <label class="form-label" for="description">{{ __('Description') }}</label>
                    <textarea id="description" name="description" class="form-control" rows="3">{{ old('description') }}</textarea>
                </div>

                <div class="mt-3">
                    <button type="submit" class="btn btn-primary">{{ __('Save Entry') }}</button>
                    <a href="{{ route('customer-ledgers.index') }}" class="btn btn-secondary">{{ __('Cancel') }}</a>
                </div>
            </form>
        </div>
    </div>
</x-app-layout>
