@extends('layouts.app')

@section('title', 'Add Location')
@section('heading', 'Add Location')

@section('content')
    <x-card>
        <form action="{{ route('locations.store') }}" method="POST" class="space-y-6" novalidate data-location-form="create">
            @csrf
            <div class="grid gap-6 sm:grid-cols-2">
                <div>
                    <label class="block text-sm font-medium text-slate-700">Name <span class="text-red-500">*</span></label>
                    <input type="text" name="name" value="{{ old('name') }}" class="mt-1 block w-full rounded-lg border border-slate-300 px-3 py-2">
                    @error('name')<p class="mt-1 text-sm text-red-600">{{ $message }}</p>@enderror
                    <p data-js-error="name" class="mt-1 text-sm text-red-600 hidden"></p>
                </div>
                <div>
                    <label class="block text-sm font-medium text-slate-700">Code <span class="text-red-500">*</span></label>
                    <input type="text" name="code" value="{{ old('code') }}" class="mt-1 block w-full rounded-lg border border-slate-300 px-3 py-2">
                    @error('code')<p class="mt-1 text-sm text-red-600">{{ $message }}</p>@enderror
                    <p data-js-error="code" class="mt-1 text-sm text-red-600 hidden"></p>
                </div>
                <div class="sm:col-span-2">
                    <label class="block text-sm font-medium text-slate-700">Address</label>
                    <textarea name="address" rows="3" class="mt-1 block w-full rounded-lg border border-slate-300 px-3 py-2">{{ old('address') }}</textarea>
                    @error('address')<p class="mt-1 text-sm text-red-600">{{ $message }}</p>@enderror
                    <p data-js-error="address" class="mt-1 text-sm text-red-600 hidden"></p>
                </div>
                @include('locations.partials.geofence-fields', ['location' => null, 'defaultRadius' => $defaultRadius ?? 250])
            </div>
            <div class="flex gap-2">
                <x-button type="submit" variant="primary">Save</x-button>
                <a href="{{ route('locations.index') }}" class="inline-flex items-center rounded-lg bg-slate-100 px-4 py-2 text-sm font-medium text-slate-700 hover:bg-slate-200">Cancel</a>
            </div>
        </form>
    </x-card>
@endsection

@push('scripts')
<script src="{{ asset('js/form-validation.js') }}"></script>
<script src="{{ asset('js/form-text-rules.js') }}"></script>
<script src="{{ asset('js/location-form-validation.js') }}"></script>
@endpush
