@extends('layouts.admin')

@section('title', 'Create Stock Audit')

@section('content')
<x-admin.form-page
    title="Create Stock Audit"
    :crumbs="[['label' => 'Stock Audits', 'url' => route('admin.stock-audit.index')], 'Create']"
    :back-url="route('admin.stock-audit.index')"
    :action="route('admin.stock-audit.store')"
    form-id="stockAuditForm"
    submit-label="Create & Load Products"
>
    <x-slot:summary>
        <p class="pp-hint mb-3">Start a new audit for a store location. System qty uses that location's on-hand balance.</p>
    </x-slot:summary>

    <section class="pp-card">
        <div class="pp-card__head">
            <span class="pp-card__icon"><i class="bi bi-clipboard-check"></i></span>
            <div>
                <h2 class="pp-card__title">New Audit</h2>
                <p class="pp-card__sub">Name, date and location</p>
            </div>
        </div>
        <div class="pp-card__body">
            <div class="pp-grid pp-grid--2">
                <div class="pp-field">
                    <label for="audit_name">Audit Name <span class="pp-req">*</span></label>
                    <input type="text" name="audit_name" id="audit_name"
                           class="form-control @error('audit_name') is-invalid @enderror"
                           value="{{ old('audit_name') }}" required maxlength="255"
                           placeholder="e.g. Monthly count Jan 2026">
                    @error('audit_name')
                        <div class="invalid-feedback d-block">{{ $message }}</div>
                    @enderror
                </div>

                <div class="pp-field">
                    <label for="audit_date">Audit Date <span class="pp-req">*</span></label>
                    <input type="date" name="audit_date" id="audit_date"
                           class="form-control @error('audit_date') is-invalid @enderror"
                           value="{{ old('audit_date', now()->format('Y-m-d')) }}" required>
                    @error('audit_date')
                        <div class="invalid-feedback d-block">{{ $message }}</div>
                    @enderror
                </div>

                <div class="pp-field">
                    <label for="location_id">Location / Store <span class="pp-req">*</span></label>
                    <select name="location_id" id="location_id"
                            class="form-select @error('location_id') is-invalid @enderror" required>
                        <option value="">Select location</option>
                        @foreach(($locations ?? []) as $loc)
                            <option value="{{ $loc->id }}" @selected(old('location_id') == $loc->id)>
                                {{ $loc->name }} ({{ $loc->type }})
                            </option>
                        @endforeach
                    </select>
                    @error('location_id')
                        <div class="invalid-feedback d-block">{{ $message }}</div>
                    @enderror
                    <span class="pp-hint">System qty will use this location's on-hand balance.</span>
                </div>
            </div>
        </div>
    </section>
</x-admin.form-page>
@endsection
