@extends('layouts.app')

@section('title', TranslationHelper::transFromDatabase('Warehouses.ShowTitle', __('عرض المخزن')))

@section('content')
<div class="container m-auto p-4 py-8">
    <div class="flex justify-between items-center mb-6">
        <h1 class="text-2l font-semibold text-gray-900">{{ $warehouse->name }}</h1>
        <div class="space-x-2">
            @can('inventory.warehouses.edit')
            <a href="{{ route('inventory.warehouses.edit', $warehouse) }}" class="bg-amber-600 hover:bg-amber-700 text-white font-bold py-2 p-4 rounded inline-flex items-center">
                <i class="fas fa-edit ml-2"></i>
                <span>{{ TranslationHelper::transFromDatabase('General.Edit', __('تعديل')) }}</span>
            </a>
            @endcan
            <a href="{{ route('inventory.warehouses.index') }}" class="bg-gray-200 hover:bg-gray-300 text-gray-800 font-bold py-2 p-4 rounded inline-flex items-center">
                <span>{{ TranslationHelper::transFromDatabase('General.Back', __('العودة')) }}</span>
            </a>
        </div>
    </div>

    <div class="grid grid-cols-1 md:grid-cols-3 gap-6">
        <div class="md:col-span-2">
            <div class="bg-white rounded-lg shadow-md p-6 mb-6">
                <h2 class="text-xl font-bold text-gray-900 mb-4">{{ TranslationHelper::transFromDatabase('Warehouses.BasicInfo', __('المعلومات الأساسية')) }}</h2>
                
                <div class="grid grid-cols-2 gap-4">
                    <div>
                        <label class="text-gray-600 font-semibold">{{ TranslationHelper::transFromDatabase('Warehouses.Name', __('اسم المخزن')) }}</label>
                        <p class="text-gray-900 mt-1">{{ $warehouse->name }}</p>
                    </div>
                    <div>
                        <label class="text-gray-600 font-semibold">{{ TranslationHelper::transFromDatabase('Warehouses.Code', __('كود المخزن')) }}</label>
                        <p class="text-gray-900 mt-1">{{ $warehouse->code ?? '-' }}</p>
                    </div>
                    <div>
                        <label class="text-gray-600 font-semibold">{{ TranslationHelper::transFromDatabase('Warehouses.Phone', __('رقم الهاتف')) }}</label>
                        <p class="text-gray-900 mt-1">{{ $warehouse->phone ?? '-' }}</p>
                    </div>
                    <div>
                        <label class="text-gray-600 font-semibold">{{ TranslationHelper::transFromDatabase('Warehouses.Status', __('الحالة')) }}</label>
                        <p class="text-gray-900 mt-1">
                            @if($warehouse->is_active)
                                <span class="inline-flex items-center px-3 py-1 rounded-full text-sm font-medium bg-green-100 text-green-700">
                                    <span class="w-2 h-2 bg-green-500 rounded-full ml-2"></span>
                                    {{ TranslationHelper::transFromDatabase('Status.Active', __('نشط')) }}
                                </span>
                            @else
                                <span class="inline-flex items-center px-3 py-1 rounded-full text-sm font-medium bg-red-100 text-red-700">
                                    <span class="w-2 h-2 bg-red-500 rounded-full ml-2"></span>
                                    {{ TranslationHelper::transFromDatabase('Status.Inactive', __('غير نشط')) }}
                                </span>
                            @endif
                        </p>
                    </div>
                </div>

                <div class="mt-4 pt-4 border-t">
                    <label class="text-gray-600 font-semibold">{{ TranslationHelper::transFromDatabase('Warehouses.Address', __('العنوان')) }}</label>
                    <p class="text-gray-900 mt-1">{{ $warehouse->address ?? '-' }}</p>
                </div>

                <div class="mt-4 pt-4 border-t">
                    <label class="text-gray-600 font-semibold">{{ TranslationHelper::transFromDatabase('Warehouses.AdditionalManagerInfo', __('معلومات إضافية عن المدير')) }}</label>
                    <p class="text-gray-900 mt-1">{{ $warehouse->manager ?? '-' }}</p>
                </div>

                <div class="mt-4 pt-4 border-t">
                    <label class="text-gray-600 font-semibold">{{ TranslationHelper::transFromDatabase('Warehouses.Notes', __('ملاحظات')) }}</label>
                    <p class="text-gray-900 mt-1">{{ $warehouse->notes ?? '-' }}</p>
                </div>
            </div>
        </div>

        <div>
            <div class="bg-white rounded-lg shadow-md p-6">
                <h2 class="text-xl font-bold text-gray-900 mb-4">{{ TranslationHelper::transFromDatabase('Warehouses.Managers', __('مديرو المخزن')) }}</h2>
                
                @if($warehouse->managers->count() > 0)
                    <div class="space-y-3">
                        @foreach($warehouse->managers as $manager)
                            <div class="flex items-center justify-between p-3 bg-gray-50 rounded-lg border-l-4" 
                                style="border-color: {{ $manager->pivot->is_primary ? '#1e40af' : '#9ca3af' }}">
                                <div>
                                    <p class="font-semibold text-gray-900">{{ $manager->name }}</p>
                                    <p class="text-sm text-gray-600">{{ $manager->email }}</p>
                                </div>
                                @if($manager->pivot->is_primary)
                                    <span class="px-2 py-1 text-xs font-bold bg-blue-100 text-blue-700 rounded">
                                        <i class="fas fa-star ml-1"></i>
                                        {{ TranslationHelper::transFromDatabase('General.Primary', __('رئيسي')) }}
                                    </span>
                                @endif
                            </div>
                        @endforeach
                    </div>
                @else
                    <div class="text-center py-8 text-gray-500">
                        <i class="fas fa-inbox text-4xl mb-2"></i>
                        <p>{{ TranslationHelper::transFromDatabase('Warehouses.NoManagers', __('لم يتم تعيين مديرين بعد')) }}</p>
                    </div>
                @endif
            </div>

            <div class="bg-white rounded-lg shadow-md p-6 mt-6">
                <h2 class="text-xl font-bold text-gray-900 mb-4">{{ TranslationHelper::transFromDatabase('Warehouses.AdditionalInfo', __('معلومات إضافية')) }}</h2>
                
                <div class="space-y-3">
                    <div>
                        <label class="text-gray-600 font-semibold text-sm">{{ TranslationHelper::transFromDatabase('Warehouses.Company', __('الشركة')) }}</label>
                        <p class="text-gray-900">{{ $warehouse->company->name ?? '-' }}</p>
                    </div>
                    <div>
                        <label class="text-gray-600 font-semibold text-sm">{{ TranslationHelper::transFromDatabase('Warehouses.COAAccount', __('حساب دليل الحسابات')) }}</label>
                        <p class="text-gray-900">{{ $warehouse->chartOfAccount->code ?? '-' }} - {{ $warehouse->chartOfAccount->name ?? '-' }}</p>
                    </div>
                    <div class="pt-3 border-t">
                        <label class="text-gray-600 font-semibold text-sm">{{ TranslationHelper::transFromDatabase('Warehouses.CreatedAt', __('تاريخ الإنشاء')) }}</label>
                        <p class="text-gray-900">{{ $warehouse->created_at->format('Y-m-d H:i') }}</p>
                    </div>
                    <div>
                        <label class="text-gray-600 font-semibold text-sm">{{ TranslationHelper::transFromDatabase('Warehouses.UpdatedAt', __('آخر تحديث')) }}</label>
                        <p class="text-gray-900">{{ $warehouse->updated_at->format('Y-m-d H:i') }}</p>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection
