<div class="p-6">
    <!-- Header -->
    <div class="flex flex-col lg:flex-row lg:items-center justify-between space-y-4 lg:space-y-0 mb-6">
        <div>
            <h1 class="text-2xl font-semibold text-zinc-900 dark:text-white">Edit Branch: {{ $branch->name }}</h1>
            <p class="text-zinc-600 dark:text-zinc-400">Modify branch location and settings</p>
        </div>
        <div class="flex items-center space-x-3">
            <a href="{{ route('branches.index') }}" 
               class="inline-flex items-center px-4 py-2 bg-zinc-100 hover:bg-zinc-200 dark:bg-zinc-700 dark:hover:bg-zinc-600 text-zinc-700 dark:text-zinc-300 text-sm font-medium rounded-md transition-colors" 
               wire:navigate>
                <svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 19l-7-7m0 0l7-7m-7 7h18"></path>
                </svg>
                Back to Branches
            </a>
        </div>
    </div>

    <!-- Stats Card -->
    <div class="grid grid-cols-1 md:grid-cols-3 gap-4 mb-6">
        <div class="bg-white dark:bg-zinc-800 border border-zinc-200 dark:border-zinc-700 rounded-lg p-4">
            <div class="text-sm font-medium text-zinc-600 dark:text-zinc-400">Assigned Users</div>
            <div class="text-2xl font-bold text-zinc-900 dark:text-white">{{ $branch->users()->count() }}</div>
        </div>
        <div class="bg-white dark:bg-zinc-800 border border-zinc-200 dark:border-zinc-700 rounded-lg p-4">
            <div class="text-sm font-medium text-zinc-600 dark:text-zinc-400">Job Cards</div>
            <div class="text-2xl font-bold text-zinc-900 dark:text-white">{{ \App\Models\JobCard::where('branch_code', $branch->code)->count() }}</div>
        </div>
        <div class="bg-white dark:bg-zinc-800 border border-zinc-200 dark:border-zinc-700 rounded-lg p-4">
            <div class="text-sm font-medium text-zinc-600 dark:text-zinc-400">Created</div>
            <div class="text-2xl font-bold text-zinc-900 dark:text-white">{{ $branch->created_at->format('M d, Y') }}</div>
        </div>
    </div>

    <!-- Flash Messages -->
    @if(session()->has('error'))
        <div class="bg-red-50 dark:bg-red-900/50 border border-red-200 dark:border-red-700 rounded-lg p-4 mb-6">
            <div class="text-sm text-red-800 dark:text-red-200">
                {{ session('error') }}
            </div>
        </div>
    @endif

    <!-- Edit Form -->
    <div class="bg-white dark:bg-zinc-800 border border-zinc-200 dark:border-zinc-700 rounded-lg shadow-sm">
        <div class="p-6">
            <form wire:submit="save">
                <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                    <!-- Branch Code -->
                    <div>
                        <label for="code" class="block text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-2">
                            Branch Code <span class="text-red-500">*</span>
                        </label>
                        <input type="text" 
                               wire:model="code"
                               id="code"
                               class="w-full rounded-md border-zinc-300 dark:border-zinc-600 dark:bg-zinc-700 dark:text-white shadow-sm focus:border-blue-500 focus:ring-blue-500 @error('code') border-red-500 @enderror"
                               placeholder="e.g., MAIN, NORTH"
                               maxlength="10"
                               style="text-transform: uppercase;">
                        @error('code')
                            <p class="mt-1 text-sm text-red-600 dark:text-red-400">{{ $message }}</p>
                        @enderror
                        <p class="mt-1 text-xs text-zinc-500 dark:text-zinc-400">⚠️ Changing the code will affect job card numbering and user assignments</p>
                    </div>

                    <!-- Branch Name -->
                    <div>
                        <label for="name" class="block text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-2">
                            Branch Name <span class="text-red-500">*</span>
                        </label>
                        <input type="text" 
                               wire:model="name"
                               id="name"
                               class="w-full rounded-md border-zinc-300 dark:border-zinc-600 dark:bg-zinc-700 dark:text-white shadow-sm focus:border-blue-500 focus:ring-blue-500 @error('name') border-red-500 @enderror"
                               placeholder="e.g., Main Branch">
                        @error('name')
                            <p class="mt-1 text-sm text-red-600 dark:text-red-400">{{ $message }}</p>
                        @enderror
                    </div>

                    <!-- Manager Name -->
                    <div>
                        <label for="manager_name" class="block text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-2">
                            Manager Name
                        </label>
                        <input type="text" 
                               wire:model="manager_name"
                               id="manager_name"
                               class="w-full rounded-md border-zinc-300 dark:border-zinc-600 dark:bg-zinc-700 dark:text-white shadow-sm focus:border-blue-500 focus:ring-blue-500 @error('manager_name') border-red-500 @enderror"
                               placeholder="Branch Manager Name">
                        @error('manager_name')
                            <p class="mt-1 text-sm text-red-600 dark:text-red-400">{{ $message }}</p>
                        @enderror
                    </div>

                    <!-- Phone -->
                    <div>
                        <label for="phone" class="block text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-2">
                            Phone Number
                        </label>
                        <input type="tel" 
                               wire:model="phone"
                               id="phone"
                               class="w-full rounded-md border-zinc-300 dark:border-zinc-600 dark:bg-zinc-700 dark:text-white shadow-sm focus:border-blue-500 focus:ring-blue-500 @error('phone') border-red-500 @enderror"
                               placeholder="e.g., +1-555-0100">
                        @error('phone')
                            <p class="mt-1 text-sm text-red-600 dark:text-red-400">{{ $message }}</p>
                        @enderror
                    </div>

                    <!-- Email -->
                    <div>
                        <label for="email" class="block text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-2">
                            Email Address
                        </label>
                        <input type="email" 
                               wire:model="email"
                               id="email"
                               class="w-full rounded-md border-zinc-300 dark:border-zinc-600 dark:bg-zinc-700 dark:text-white shadow-sm focus:border-blue-500 focus:ring-blue-500 @error('email') border-red-500 @enderror"
                               placeholder="branch@company.com">
                        @error('email')
                            <p class="mt-1 text-sm text-red-600 dark:text-red-400">{{ $message }}</p>
                        @enderror
                    </div>

                    <!-- Status -->
                    <div>
                        <label class="block text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-2">
                            Status
                        </label>
                        <label class="inline-flex items-center">
                            <input type="checkbox" 
                                   wire:model="is_active"
                                   class="rounded border-zinc-300 dark:border-zinc-600 text-blue-600 shadow-sm focus:border-blue-500 focus:ring-blue-500">
                            <span class="ml-2 text-sm text-zinc-700 dark:text-zinc-300">Branch is active</span>
                        </label>
                        <p class="mt-1 text-xs text-zinc-500 dark:text-zinc-400">Inactive branches cannot receive new job cards</p>
                    </div>
                </div>

                <!-- Address Section -->
                <div class="mt-8">
                    <h3 class="text-lg font-medium text-zinc-900 dark:text-white mb-4">Address Information</h3>
                    
                    <div class="grid grid-cols-1 gap-6">
                        <!-- Address -->
                        <div>
                            <label for="address" class="block text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-2">
                                Street Address
                            </label>
                            <textarea wire:model="address"
                                      id="address"
                                      rows="2"
                                      class="w-full rounded-md border-zinc-300 dark:border-zinc-600 dark:bg-zinc-700 dark:text-white shadow-sm focus:border-blue-500 focus:ring-blue-500 @error('address') border-red-500 @enderror"
                                      placeholder="Enter street address"></textarea>
                            @error('address')
                                <p class="mt-1 text-sm text-red-600 dark:text-red-400">{{ $message }}</p>
                            @enderror
                        </div>

                        <div class="grid grid-cols-1 md:grid-cols-3 gap-4">
                            <!-- City -->
                            <div>
                                <label for="city" class="block text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-2">
                                    City
                                </label>
                                <input type="text" 
                                       wire:model="city"
                                       id="city"
                                       class="w-full rounded-md border-zinc-300 dark:border-zinc-600 dark:bg-zinc-700 dark:text-white shadow-sm focus:border-blue-500 focus:ring-blue-500 @error('city') border-red-500 @enderror"
                                       placeholder="City">
                                @error('city')
                                    <p class="mt-1 text-sm text-red-600 dark:text-red-400">{{ $message }}</p>
                                @enderror
                            </div>

                            <!-- State -->
                            <div>
                                <label for="state" class="block text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-2">
                                    State/Province
                                </label>
                                <input type="text" 
                                       wire:model="state"
                                       id="state"
                                       class="w-full rounded-md border-zinc-300 dark:border-zinc-600 dark:bg-zinc-700 dark:text-white shadow-sm focus:border-blue-500 focus:ring-blue-500 @error('state') border-red-500 @enderror"
                                       placeholder="State">
                                @error('state')
                                    <p class="mt-1 text-sm text-red-600 dark:text-red-400">{{ $message }}</p>
                                @enderror
                            </div>

                            <!-- Postal Code -->
                            <div>
                                <label for="postal_code" class="block text-sm font-medium text-zinc-700 dark:text-zinc-300 mb-2">
                                    Postal Code
                                </label>
                                <input type="text" 
                                       wire:model="postal_code"
                                       id="postal_code"
                                       class="w-full rounded-md border-zinc-300 dark:border-zinc-600 dark:bg-zinc-700 dark:text-white shadow-sm focus:border-blue-500 focus:ring-blue-500 @error('postal_code') border-red-500 @enderror"
                                       placeholder="12345">
                                @error('postal_code')
                                    <p class="mt-1 text-sm text-red-600 dark:text-red-400">{{ $message }}</p>
                                @enderror
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Form Actions -->
                <div class="mt-8 flex items-center justify-end space-x-4 pt-6 border-t border-zinc-200 dark:border-zinc-700">
                    <a href="{{ route('branches.index') }}" 
                       class="inline-flex items-center px-4 py-2 bg-zinc-100 hover:bg-zinc-200 dark:bg-zinc-700 dark:hover:bg-zinc-600 text-zinc-700 dark:text-zinc-300 text-sm font-medium rounded-md transition-colors" 
                       wire:navigate>
                        Cancel
                    </a>
                    <button type="submit" 
                            class="inline-flex items-center px-4 py-2 bg-blue-600 hover:bg-blue-700 text-white text-sm font-medium rounded-md transition-colors">
                        <svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"></path>
                        </svg>
                        Update Branch
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>
