﻿@extends('layouts.app')

@section('title', \App\Helpers\TranslationHelper::transFromDatabase('Branches.EditTitle', __('تعديل الفرع')) . ': ' . $branch->name)

@section('content')
<div class="container m-auto p-4 py-6">
    <div class="flex items-center justify-between mb-6">
        <h2 class="text-2l font-bold text-gray-800">{{ \App\Helpers\TranslationHelper::transFromDatabase('Branches.EditTitle', __('تعديل الفرع')) }}: {{ $branch->name }}</h2>
        <div class="flex space-y-2 space-y-reverse">
            <a href="{{ route('branches.index') }}" class="bg-gray-200 hover:bg-gray-300 text-gray-700 font-bold py-2 p-4 rounded-md flex items-center">
                <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 ml-1" viewBox="0 0 20 20" fill="currentColor">
                    <path fill-rule="evenodd" d="M9.707 16.707a1 1 0 01-1.414 0l-6-6a1 1 0 010-1.414l6-6a1 1 0 011.414 1.414L5.414 9H17a1 1 0 110 2H5.414l4.293 4.293a1 1 0 010 1.414z" clip-rule="evenodd" />
                </svg>
                {{ \App\Helpers\TranslationHelper::transFromDatabase('CommonButtons.Back', __('العودة للقائمة')) }}
            </a>
            <a href="{{ route('branches.show', $branch) }}" class="bg-primary-500 hover:bg-primary-600 text-white font-bold py-2 p-4 rounded-md flex items-center">
                <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 ml-1" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" />
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z" />
                </svg>
                {{ \App\Helpers\TranslationHelper::transFromDatabase('CommonButtons.View', __('عرض التفاصيل')) }}
            </a>
        </div>
    </div>

    <div class="bg-white rounded-lg shadow-md p-6">
        <form action="{{ route('branches.update', $branch) }}" method="POST">
            @csrf
            @method('PUT')
            
            <div class="mb-4">
                <label for="name" class="block text-gray-700 text-sm font-bold mb-2">{{ \App\Helpers\TranslationHelper::transFromDatabase('Branches.Name', __('اسم الفرع')) }} <span class="text-red-600">*</span></label>
                <input type="text" name="name" id="name" value="{{ old('name', $branch->name) }}" class="shadow appearance-none border rounded w-full py-2 p-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline @error('name') border-red-500 @enderror" required>
                @error('name')
                <p class="text-red-500 text-s mt-1">{{ $message }}</p>
                @enderror
            </div>

            <div class="mb-4">
                <label for="address" class="block text-gray-700 text-sm font-bold mb-2">{{ \App\Helpers\TranslationHelper::transFromDatabase('Branches.Address', __('عنوان الفرع')) }}</label>
                <input type="text" name="address" id="address" value="{{ old('address', $branch->address) }}" class="shadow appearance-none border rounded w-full py-2 p-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline @error('address') border-red-500 @enderror">
                @error('address')
                <p class="text-red-500 text-s mt-1">{{ $message }}</p>
                @enderror
            </div>

            <div class="mb-4">
                <label for="phone" class="block text-gray-700 text-sm font-bold mb-2">{{ \App\Helpers\TranslationHelper::transFromDatabase('Branches.Phone', __('رقم الهاتف')) }}</label>
                <input type="text" name="phone" id="phone" value="{{ old('phone', $branch->phone) }}" class="shadow appearance-none border rounded w-full py-2 p-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline @error('phone') border-red-500 @enderror">
                @error('phone')
                <p class="text-red-500 text-s mt-1">{{ $message }}</p>
                @enderror
            </div>

            <div class="mb-4">
                <label for="email" class="block text-gray-700 text-sm font-bold mb-2">{{ \App\Helpers\TranslationHelper::transFromDatabase('Branches.Email', __('البريد الإلكتروني')) }}</label>
                <input type="email" name="email" id="email" value="{{ old('email', $branch->email) }}" class="shadow appearance-none border rounded w-full py-2 p-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline @error('email') border-red-500 @enderror">
                @error('email')
                <p class="text-red-500 text-s mt-1">{{ $message }}</p>
                @enderror
            </div>

            <div class="mb-4">
                <div class="flex items-center">
                    <input type="checkbox" name="is_main" id="is_main" value="1" {{ old('is_main', $branch->is_main) ? 'checked' : '' }} class="h-4 w-4 text-primary-600 focus:ring-primary-500 border-gray-300 rounded ml-2">
                    <label for="is_main" class="text-gray-700 text-sm font-bold">{{ \App\Helpers\TranslationHelper::transFromDatabase('Branches.MainBranch', __('فرع رئيسي')) }}</label>
                </div>
                <p class="text-gray-500 text-s mt-1">{{ \App\Helpers\TranslationHelper::transFromDatabase('Branches.MainBranchNote', __('ملاحظة: إذا تم تحديد هذا الفرع كفرع رئيسي، سيتم إلغاء تعيين الفرع الرئيسي السابق.')) }}</p>
            </div>

            <div class="mb-6">
                <div class="flex items-center">
                    <input type="checkbox" name="is_active" id="is_active" value="1" {{ old('is_active', $branch->is_active) ? 'checked' : '' }} class="h-4 w-4 text-primary-600 focus:ring-primary-500 border-gray-300 rounded ml-2">
                    <label for="is_active" class="text-gray-700 text-sm font-bold">{{ \App\Helpers\TranslationHelper::transFromDatabase('Common.Active', __('فرع نشط')) }}</label>
                </div>
            </div>

            <div class="flex items-center justify-between">
                <button type="submit" class="bg-primary-600 hover:bg-primary-700 text-white font-bold py-2 p-4 rounded focus:outline-none focus:shadow-outline">
                    {{ \App\Helpers\TranslationHelper::transFromDatabase('CommonButtons.Save', __('حفظ التغييرات')) }}
                </button>
            </div>
        </form>
    </div>
</div>
@endsection
