﻿@extends('layouts.app')

@section('title', \App\Helpers\TranslationHelper::transFromDatabase('Branches.ShowTitle', __('تفاصيل الفرع')) . ': ' . $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.ShowTitle', __('تفاصيل الفرع')) }}: {{ $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>
            @permission('branches.edit')
            <a href="{{ route('branches.edit', $branch) }}" class="bg-blue-500 hover:bg-blue-700 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="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z" />
                </svg>
                {{ \App\Helpers\TranslationHelper::transFromDatabase('CommonButtons.Edit', __('تعديل')) }}
            </a>
            @endpermission
        </div>
    </div>

    <div class="bg-white rounded-lg shadow-md overflow-hidden">
        <div class="p-6">
            <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                <div>
                    <h3 class="text-lg font-semibold text-gray-700 mb-2">{{ \App\Helpers\TranslationHelper::transFromDatabase('Branches.BasicInfo', __('معلومات الفرع')) }}</h3>
                    <div class="bg-gray-50 p-4 rounded-md">
                        <div class="mb-4">
                            <span class="block text-sm font-medium text-gray-500">{{ \App\Helpers\TranslationHelper::transFromDatabase('Branches.Name', __('اسم الفرع')) }}:</span>
                            <span class="block mt-1 text-base text-gray-900">{{ $branch->name }}</span>
                        </div>
                        <div class="mb-4">
                            <span class="block text-sm font-medium text-gray-500">{{ \App\Helpers\TranslationHelper::transFromDatabase('Branches.Address', __('العنوان')) }}:</span>
                            <span class="block mt-1 text-base text-gray-900">{{ $branch->address ?? \App\Helpers\TranslationHelper::transFromDatabase('CommonMessages.NotSpecified', __('غير محدد')) }}</span>
                        </div>
                        <div class="mb-4">
                            <span class="block text-sm font-medium text-gray-500">{{ \App\Helpers\TranslationHelper::transFromDatabase('Branches.Phone', __('رقم الهاتف')) }}:</span>
                            <span class="block mt-1 text-base text-gray-900">{{ $branch->phone ?? \App\Helpers\TranslationHelper::transFromDatabase('CommonMessages.NotSpecified', __('غير محدد')) }}</span>
                        </div>
                        <div class="mb-4">
                            <span class="block text-sm font-medium text-gray-500">{{ \App\Helpers\TranslationHelper::transFromDatabase('Branches.Email', __('البريد الإلكتروني')) }}:</span>
                            <span class="block mt-1 text-base text-gray-900">{{ $branch->email ?? \App\Helpers\TranslationHelper::transFromDatabase('CommonMessages.NotSpecified', __('غير محدد')) }}</span>
                        </div>
                    </div>
                </div>
                <div>
                    <h3 class="text-lg font-semibold text-gray-700 mb-2">{{ \App\Helpers\TranslationHelper::transFromDatabase('Branches.Status', __('حالة الفرع')) }}</h3>
                    <div class="bg-gray-50 p-4 rounded-md">
                        <div class="mb-4">
                            <span class="block text-sm font-medium text-gray-500">{{ \App\Helpers\TranslationHelper::transFromDatabase('Branches.MainBranch', __('الفرع الرئيسي')) }}:</span>
                            <span class="block mt-1">
                                @if($branch->is_main)
                                <span class="p-2 inline-flex text-s leading-5 font-semibold rounded-full bg-green-100 text-green-800">
                                    {{ \App\Helpers\TranslationHelper::transFromDatabase('Common.Yes', __('نعم')) }}
                                </span>
                                @else
                                <span class="p-2 inline-flex text-s leading-5 font-semibold rounded-full bg-gray-100 text-gray-800">
                                    {{ \App\Helpers\TranslationHelper::transFromDatabase('Common.No', __('لا')) }}
                                </span>
                                @endif
                            </span>
                        </div>
                        <div class="mb-4">
                            <span class="block text-sm font-medium text-gray-500">{{ \App\Helpers\TranslationHelper::transFromDatabase('Branches.Status', __('حالة الفرع')) }}:</span>
                            <span class="block mt-1">
                                @if($branch->is_active)
                                <span class="p-2 inline-flex text-s leading-5 font-semibold rounded-full bg-green-100 text-green-800">
                                    {{ \App\Helpers\TranslationHelper::transFromDatabase('Common.Active', __('نشط')) }}
                                </span>
                                @else
                                <span class="p-2 inline-flex text-s leading-5 font-semibold rounded-full bg-red-100 text-red-800">
                                    {{ \App\Helpers\TranslationHelper::transFromDatabase('Common.Inactive', __('غير نشط')) }}
                                </span>
                                @endif
                            </span>
                        </div>
                        <div class="mb-4">
                            <span class="block text-sm font-medium text-gray-500">{{ \App\Helpers\TranslationHelper::transFromDatabase('Branches.CreatedAt', __('تاريخ الإنشاء')) }}:</span>
                            <span class="block mt-1 text-base text-gray-900">{{ $branch->created_at->format('Y-m-d H:i') }}</span>
                        </div>
                        <div class="mb-4">
                            <span class="block text-sm font-medium text-gray-500">{{ \App\Helpers\TranslationHelper::transFromDatabase('Branches.UpdatedAt', __('آخر تحديث')) }}:</span>
                            <span class="block mt-1 text-base text-gray-900">{{ $branch->updated_at->format('Y-m-d H:i') }}</span>
                        </div>
                    </div>
                </div>
            </div>

            <div class="mt-8">
                <h3 class="text-lg font-semibold text-gray-700 mb-2">{{ \App\Helpers\TranslationHelper::transFromDatabase('Branches.Users', __('المستخدمون في هذا الفرع')) }}</h3>
                <div class="bg-gray-50 p-4 rounded-md">
                    @if($branch->users->count() > 0)
                    <div class="overflow--auto">
                        <table class="min-w-full divide-y divide-gray-200">
                            <thead class="bg-gray-100">
                                <tr>
                                    <th scope="col" class="p-6 py-3 text-right text-s font-medium text-gray-500 uppercase tracking-wider">
                                        {{ \App\Helpers\TranslationHelper::transFromDatabase('Companies.UserName', __('الاسم')) }}
                                    </th>
                                    <th scope="col" class="p-6 py-3 text-right text-s font-medium text-gray-500 uppercase tracking-wider">
                                        {{ \App\Helpers\TranslationHelper::transFromDatabase('Companies.UserEmail', __('البريد الإلكتروني')) }}
                                    </th>
                                    <th scope="col" class="p-6 py-3 text-right text-s font-medium text-gray-500 uppercase tracking-wider">
                                        {{ \App\Helpers\TranslationHelper::transFromDatabase('Companies.Roles', __('الأدوار')) }}
                                    </th>
                                </tr>
                            </thead>
                            <tbody class="bg-white divide-y divide-gray-200">
                                @foreach($branch->users as $user)
                                <tr>
                                    <td class="p-6 py-4 whitespace-nowrap">
                                        <div class="text-sm font-medium text-gray-900">{{ $user->name }}</div>
                                    </td>
                                    <td class="p-6 py-4 whitespace-nowrap">
                                        <div class="text-sm text-gray-500">{{ $user->email }}</div>
                                    </td>
                                    <td class="p-6 py-4 whitespace-nowrap">
                                        <div class="text-sm text-gray-500">
                                            @foreach($user->roles as $role)
                                            <span class="p-2 inline-flex text-s leading-5 font-semibold rounded-full bg-blue-100 text-blue-800 ml-1">
                                                {{ $role->name }}
                                            </span>
                                            @endforeach
                                        </div>
                                    </td>
                                </tr>
                                @endforeach
                            </tbody>
                        </table>
                    </div>
                    @else
                    <p class="text-gray-500">{{ \App\Helpers\TranslationHelper::transFromDatabase('Branches.NoUsers', __('لا يوجد مستخدمون مرتبطون بهذا الفرع حالياً.')) }}</p>
                    @endif
                </div>
            </div>
        </div>
    </div>
</div>
@endsection
