﻿<x-app-layout>
    <x-slot name="header">
        <div class="flex justify-between">
            <h2 class="font-semibold text-l text-gray-800 leading-tight">
                {{ __('تفاصيل الإيداع البنكي') }} #{{ $deposit->id }}
            </h2>
            <div class="flex space-y-2 space-y-reverse">
                @permission('update', $deposit)
                    <a href="{{ route('banking.deposits.edit', $deposit) }}" class="inline-flex items-center p-4 py-2 bg-gray-800 border border-transparent rounded-md font-semibold text-s text-white uppercase tracking-widest hover:bg-gray-700 active:bg-gray-900 focus:outline-none focus:border-gray-900 focus:ring ring-gray-300 disabled:opacity-25 transition ease-in-out duration-150">
                        {{ __('تعديل') }}
                    </a>
                @endpermission
                <a href="{{ route('banking.deposits.index') }}" class="inline-flex items-center p-4 py-2 bg-gray-300 border border-transparent rounded-md font-semibold text-s text-gray-800 uppercase tracking-widest hover:bg-gray-400 active:bg-gray-500 focus:outline-none focus:border-gray-500 focus:ring ring-gray-300 disabled:opacity-25 transition ease-in-out duration-150">
                    {{ __('العودة للقائمة') }}
                </a>
            </div>
        </div>
    </x-slot>

    <div class="py-12">
        <div class="max-w-7l m-auto sm:p-6 lg:p-8">
            <div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
                <div class="p-6 bg-white border-b border-gray-200">
                    <div class="mb-6">
                        <div class="flex justify-between items-center mb-4">
                            <h3 class="text-lg font-semibold text-gray-800">{{ __('معلومات الإيداع') }}</h3>
                            <div>
                                <span class="p-3 py-1 rounded-full text-sm font-semibold
                                    @if($deposit->status == 'pending') bg-yellow-100 text-yellow-800
                                    @elseif($deposit->status == 'approved') bg-green-100 text-green-800
                                    @elseif($deposit->status == 'rejected') bg-red-100 text-red-800
                                    @endif">
                                    @if($deposit->status == 'pending') {{ __('قيد الانتظار') }}
                                    @elseif($deposit->status == 'approved') {{ __('معتمد') }}
                                    @elseif($deposit->status == 'rejected') {{ __('مرفوض') }}
                                    @endif
                                </span>
                            </div>
                        </div>

                        <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                            <div>
                                <p class="text-sm text-gray-600">{{ __('الحساب البنكي') }}</p>
                                <p class="font-medium">{{ $deposit->bankAccount->account_number }} - {{ $deposit->bankAccount->bank->name }}</p>
                            </div>

                            <div>
                                <p class="text-sm text-gray-600">{{ __('تاريخ الإيداع') }}</p>
                                <p class="font-medium">{{ $deposit->deposit_date->format('Y-m-d') }}</p>
                            </div>

                            <div>
                                <p class="text-sm text-gray-600">{{ __('المبلغ') }}</p>
                                <p class="font-medium">{{ number_format($deposit->amount, 2) }}</p>
                            </div>

                            <div>
                                <p class="text-sm text-gray-600">{{ __('رقم المرجع') }}</p>
                                <p class="font-medium">{{ $deposit->reference_number ?: '-' }}</p>
                            </div>

                            <div>
                                <p class="text-sm text-gray-600">{{ __('طريقة الإيداع') }}</p>
                                <p class="font-medium">
                                    @if($deposit->deposit_method == 'cash') {{ __('نقدي') }}
                                    @elseif($deposit->deposit_method == 'check') {{ __('شيك') }}
                                    @elseif($deposit->deposit_method == 'transfer') {{ __('تحويل بنكي') }}
                                    @elseif($deposit->deposit_method == 'other') {{ __('أخرى') }}
                                    @endif
                                </p>
                            </div>

                            <div>
                                <p class="text-sm text-gray-600">{{ __('الحساب المصدر') }}</p>
                                <p class="font-medium">{{ $deposit->chartOfAccount ? $deposit->chartOfAccount->name . ' - ' . $deposit->chartOfAccount->code : '-' }}</p>
                            </div>

                            <div>
                                <p class="text-sm text-gray-600">{{ __('مركز التكلفة') }}</p>
                                <p class="font-medium">{{ $deposit->costCenter ? $deposit->costCenter->name . ' (' . $deposit->costCenter->code . ')' : '-' }}</p>
                            </div>

                            <div class="md:col-span-2">
                                <p class="text-sm text-gray-600">{{ __('الوصف') }}</p>
                                <p class="font-medium">{{ $deposit->description ?: '-' }}</p>
                            </div>

                            <div>
                                <p class="text-sm text-gray-600">{{ __('تاريخ الإنشاء') }}</p>
                                <p class="font-medium">{{ $deposit->created_at->format('Y-m-d H:i') }}</p>
                            </div>

                            <div>
                                <p class="text-sm text-gray-600">{{ __('بواسطة') }}</p>
                                <p class="font-medium">{{ $deposit->creator ? $deposit->creator->name : '-' }}</p>
                            </div>

                            @if($deposit->status != 'pending')
                                <div>
                                    <p class="text-sm text-gray-600">{{ __('تاريخ الاعتماد') }}</p>
                                    <p class="font-medium">{{ $deposit->approved_at ? $deposit->approved_at->format('Y-m-d H:i') : '-' }}</p>
                                </div>

                                <div>
                                    <p class="text-sm text-gray-600">{{ __('معتمد بواسطة') }}</p>
                                    <p class="font-medium">{{ $deposit->approver ? $deposit->approver->name : '-' }}</p>
                                </div>

                                @if($deposit->journal_entry_id)
                                    <div class="md:col-span-2">
                                        <p class="text-sm text-gray-600">{{ __('قيد اليومية') }}</p>
                                        <p class="font-medium">
                                            <a href="{{ route('accounting.journal-entries.show', $deposit->journal_entry_id) }}" class="text-blue-600 hover:text-blue-800">
                                                {{ __('عرض القيد') }} #{{ $deposit->journal_entry_id }}
                                            </a>
                                        </p>
                                    </div>
                                @endif
                            @endif
                        </div>
                    </div>

                    @if($deposit->status == 'pending' && (auth()->user()->can('approve', $deposit) || auth()->user()->can('reject', $deposit)))
                        <div class="border-t pt-4 mt-6">
                            <h3 class="text-lg font-semibold text-gray-800 mb-4">{{ __('الإجراءات') }}</h3>
                            <div class="flex space-y-4 space-y-reverse">
                                @permission('approve', $deposit)
                                    <form method="POST" action="{{ route('banking.deposits.approve', $deposit) }}">
                                        @csrf
                                        <x-primary-button class="bg-green-600 hover:bg-green-700">
                                            {{ __('اعتماد الإيداع') }}
                                        </x-primary-button>
                                    </form>
                                @endpermission

                                @permission('reject', $deposit)
                                    <form method="POST" action="{{ route('banking.deposits.reject', $deposit) }}">
                                        @csrf
                                        <x-primary-button class="bg-red-600 hover:bg-red-700">
                                            {{ __('رفض الإيداع') }}
                                        </x-primary-button>
                                    </form>
                                @endpermission
                            </div>
                        </div>
                    @endif

                    @if($deposit->attachments && count($deposit->attachments) > 0)
                        <div class="border-t pt-4 mt-6">
                            <h3 class="text-lg font-semibold text-gray-800 mb-4">{{ __('المرفقات') }}</h3>
                            <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
                                @foreach($deposit->attachments as $attachment)
                                    <div class="border rounded-lg p-3">
                                        <div class="flex items-center justify-between">
                                            <span class="text-sm font-medium truncate">{{ $attachment->original_name }}</span>
                                            <a href="{{ route('attachments.download', $attachment) }}" class="text-blue-600 hover:text-blue-800">
                                                <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
                                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4"></path>
                                                </svg>
                                            </a>
                                        </div>
                                    </div>
                                @endforeach
                            </div>
                        </div>
                    @endif
                </div>
            </div>
        </div>
    </div>
</x-app-layout>
