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

    <div class="p-6">
        <div class="max-w-xl">
            <div class="bg-white border border-gray-200 rounded-xl shadow-sm p-6 space-y-6">
                <div>
                    <h1 class="text-xl font-semibold text-gray-900">Create Branch</h1>
                    <p class="mt-1 text-sm text-gray-600">
                        Create a new branch for the current dealer.
                    </p>
                </div>

                <form method="POST" action="{{ route('settings.branches.store') }}" class="space-y-4">
                    @csrf

                    <div>
                        <label for="name" class="block text-sm font-medium text-gray-700">Branch Name</label>
                        <input
                            id="name"
                            name="name"
                            type="text"
                            value="{{ old('name') }}"
                            required
                            class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-red-500 focus:ring-red-500 text-sm"
                        >
                        @error('name')
                            <p class="mt-1 text-xs text-red-600">{{ $message }}</p>
                        @enderror
                    </div>

                    <div>
                        <label for="address" class="block text-sm font-medium text-gray-700">Address</label>
                        <textarea
                            id="address"
                            name="address"
                            rows="3"
                            required
                            class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-red-500 focus:ring-red-500 text-sm"
                        >{{ old('address') }}</textarea>
                        @error('address')
                            <p class="mt-1 text-xs text-red-600">{{ $message }}</p>
                        @enderror
                    </div>

                    <div class="space-y-2">
                        <label class="flex items-center gap-2">
                            <input
                                type="checkbox"
                                name="is_default"
                                value="1"
                                @checked(old('is_default'))
                                class="h-4 w-4 rounded border-gray-300 text-red-600 focus:ring-red-500"
                            >
                            <span class="text-sm text-gray-700">Default Branch</span>
                        </label>
                        <p class="text-xs text-gray-500">
                            If this is the first branch for the dealer, it will automatically be set as the default.
                        </p>
                    </div>

                    <p class="text-xs text-gray-500">
                        Branch codes are generated automatically based on the dealer and cannot be edited.
                    </p>

                    <div>
                        <label class="flex items-center gap-2">
                            <input
                                type="checkbox"
                                name="is_active"
                                value="1"
                                @checked(old('is_active', true))
                                class="h-4 w-4 rounded border-gray-300 text-red-600 focus:ring-red-500"
                            >
                            <span class="text-sm text-gray-700">Active</span>
                        </label>
                        @error('is_active')
                            <p class="mt-1 text-xs text-red-600">{{ $message }}</p>
                        @enderror
                    </div>

                    <div class="flex items-center justify-end gap-3 pt-4">
                        <a
                            href="{{ route('settings.branches.index') }}"
                            class="inline-flex items-center rounded-md border border-gray-200 px-4 py-2 text-sm text-gray-700 hover:bg-gray-50"
                        >
                            Cancel
                        </a>
                        <button
                            type="submit"
                            class="inline-flex items-center rounded-md bg-red-600 px-4 py-2 text-sm font-semibold text-white shadow-sm hover:bg-red-700"
                        >
                            Create Branch
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</x-app-layout>

