<x-app-layout>
    <x-slot name="header">
        <div class="flex justify-between items-center">
            <h2 class="font-semibold text-l text-gray-800 leading-tight">
                {{ \App\Helpers\TranslationHelper::transFromDatabase('Account Details', __('Account Details')) }}
            </h2>
            <div>
                <a href="{{ route('accounting.chart-of-accounts.index') }}" class="inline-flex items-center p-4 py-2 bg-gray-600 border border-transparent rounded-md font-semibold text-s text-white uppercase tracking-widest hover:bg-gray-700 focus:bg-gray-700 active:bg-gray-800 focus:outline-none focus:ring-2 focus:ring-gray-500 focus:ring-offset-2 transition ease-in-out duration-150">
                    <svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4 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('Back to Accounts List', __('Back to Accounts List')) }}
                </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">
                        <h3 class="text-lg font-medium text-gray-900">{{ $account->name }}</h3>
                        <p class="mt-1 text-sm text-gray-600">{{ $account->code }}</p>
                    </div>

                    <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                        <div>
                            <h4 class="text-md font-medium text-gray-900 mb-2">{{ \App\Helpers\TranslationHelper::transFromDatabase('Account Information', __('Account Information')) }}</h4>
                            <div class="bg-gray-50 p-4 rounded-lg">
                                <dl class="grid grid-cols-1 gap--4 gap-y-4 sm:grid-cols-2">
                                    <div class="sm:col-span-1">
                                        <dt class="text-sm font-medium text-gray-500">{{ \App\Helpers\TranslationHelper::transFromDatabase('Code', __('Code')) }}</dt>
                                        <dd class="mt-1 text-sm text-gray-900">{{ $account->code }}</dd>
                                    </div>
                                    <div class="sm:col-span-1">
                                        <dt class="text-sm font-medium text-gray-500">{{ \App\Helpers\TranslationHelper::transFromDatabase('Name', __('Name')) }}</dt>
                                        <dd class="mt-1 text-sm text-gray-900">{{ $account->name }}</dd>
                                    </div>
                                    <div class="sm:col-span-1">
                                        <dt class="text-sm font-medium text-gray-500">{{ \App\Helpers\TranslationHelper::transFromDatabase('Account Type', __('Account Type')) }}</dt>
                                        <dd class="mt-1 text-sm text-gray-900">
                                            @switch($account->account_type)
                                                @case('asset')
                                                    {{ \App\Helpers\TranslationHelper::transFromDatabase('Assets', __('Assets')) }}
                                                    @break
                                                @case('liability')
                                                    {{ \App\Helpers\TranslationHelper::transFromDatabase('Liabilities', __('Liabilities')) }}
                                                    @break
                                                @case('equity')
                                                    {{ \App\Helpers\TranslationHelper::transFromDatabase('Equity', __('Equity')) }}
                                                    @break
                                                @case('revenue')
                                                    {{ \App\Helpers\TranslationHelper::transFromDatabase('Revenue', __('Revenue')) }}
                                                    @break
                                                @case('expense')
                                                    {{ \App\Helpers\TranslationHelper::transFromDatabase('Expense', __('Expense')) }}
                                                    @break
                                                @default
                                                    {{ $account->account_type }}
                                            @endswitch
                                        </dd>
                                    </div>
                                    <div class="sm:col-span-1">
                                        <dt class="text-sm font-medium text-gray-500">{{ \App\Helpers\TranslationHelper::transFromDatabase('Balance Type', __('Balance Type')) }}</dt>
                                        <dd class="mt-1 text-sm text-gray-900">
                                            @if ($account->balance_type == 'debit')
                                                {{ \App\Helpers\TranslationHelper::transFromDatabase('Debit', __('Debit')) }}
                                            @else
                                                {{ \App\Helpers\TranslationHelper::transFromDatabase('Credit', __('Credit')) }}
                                            @endif
                                        </dd>
                                    </div>
                                    <div class="sm:col-span-1">
                                        <dt class="text-sm font-medium text-gray-500">{{ \App\Helpers\TranslationHelper::transFromDatabase('Category', __('Category')) }}</dt>
                                        <dd class="mt-1 text-sm text-gray-900">
                                            {{ $account->category ? $account->category->name : '-' }}
                                        </dd>
                                    </div>
                                    <div class="sm:col-span-1">
                                        <dt class="text-sm font-medium text-gray-500">{{ \App\Helpers\TranslationHelper::transFromDatabase('Parent Account', __('Parent Account')) }}</dt>
                                        <dd class="mt-1 text-sm text-gray-900">
                                            {{ $account->parent ? $account->parent->name . ' (' . $account->parent->code . ')' : '-' }}
                                        </dd>
                                    </div>
                                    <div class="sm:col-span-1">
                                        <dt class="text-sm font-medium text-gray-500">{{ \App\Helpers\TranslationHelper::transFromDatabase('Parent Account', __('Parent Account')) }}</dt>
                                        <dd class="mt-1 text-sm text-gray-900">
                                            @if ($account->is_parent)
                                                <span class="inline-flex items-center p-2.5 py-0.5 rounded-full text-s font-medium bg-green-100 text-green-800">
                                                    {{ \App\Helpers\TranslationHelper::transFromDatabase('Yes', __('Yes')) }}
                                                </span>
                                            @else
                                                <span class="inline-flex items-center p-2.5 py-0.5 rounded-full text-s font-medium bg-gray-100 text-gray-800">
                                                    {{ \App\Helpers\TranslationHelper::transFromDatabase('No', __('No')) }}
                                                </span>
                                            @endif
                                        </dd>
                                    </div>
                                    <div class="sm:col-span-1">
                                        <dt class="text-sm font-medium text-gray-500">{{ \App\Helpers\TranslationHelper::transFromDatabase('Status', __('Status')) }}</dt>
                                        <dd class="mt-1 text-sm text-gray-900">
                                            @if ($account->is_active)
                                                <span class="inline-flex items-center p-2.5 py-0.5 rounded-full text-s font-medium bg-green-100 text-green-800">
                                                    {{ \App\Helpers\TranslationHelper::transFromDatabase('Active', __('Active')) }}
                                                </span>
                                            @else
                                                <span class="inline-flex items-center p-2.5 py-0.5 rounded-full text-s font-medium bg-red-100 text-red-800">
                                                    {{ \App\Helpers\TranslationHelper::transFromDatabase('Inactive', __('Inactive')) }}
                                                </span>
                                            @endif
                                        </dd>
                                    </div>
                                    <div class="sm:col-span-1">
                                        <dt class="text-sm font-medium text-gray-500">{{ \App\Helpers\TranslationHelper::transFromDatabase('Cost Center', __('Cost Center')) }}</dt>
                                        <dd class="mt-1 text-sm text-gray-900">
                                            @if ($account->costCenter)
                                                {{ $account->costCenter->code }} - {{ $account->costCenter->name }}
                                            @else
                                                -
                                            @endif
                                        </dd>
                                    </div>

                                    <div class="sm:col-span-2">
                                        <dt class="text-sm font-medium text-gray-500">{{ \App\Helpers\TranslationHelper::transFromDatabase('Description', __('Description')) }}</dt>
                                        <dd class="mt-1 text-sm text-gray-900">
                                            {{ $account->description ?: '-' }}
                                        </dd>
                                    </div>
                                </dl>
                            </div>
                        </div>

                        <div>
                            <h4 class="text-md font-medium text-gray-900 mb-2">{{ \App\Helpers\TranslationHelper::transFromDatabase('Sub Accounts', __('Sub Accounts')) }}</h4>
                            <div class="bg-gray-50 p-4 rounded-lg">
                                @if ($account->children && $account->children->count() > 0)
                                    <ul class="divide-y divide-gray-200">
                                        @foreach ($account->children as $child)
                                            <li class="py-3">
                                                <div class="flex items-center space-y-4 space-y-reverse">
                                                    <div class="flex-1 min-w-0">
                                                        <p class="text-sm font-medium text-gray-900 truncate">
                                                            <a href="{{ route('accounting.chart-of-accounts.show', $child) }}" class="hover:underline">
                                                                {{ $child->code }} - {{ $child->name }}
                                                            </a>
                                                        </p>
                                                        <p class="text-sm text-gray-500 truncate">
                                                            @switch($child->account_type)
                                                                @case('asset')
                                                                    {{ \App\Helpers\TranslationHelper::transFromDatabase('Assets', __('Assets')) }}
                                                                    @break
                                                                @case('liability')
                                                                    {{ \App\Helpers\TranslationHelper::transFromDatabase('Liabilities', __('Liabilities')) }}
                                                                    @break
                                                                @case('equity')
                                                                    {{ \App\Helpers\TranslationHelper::transFromDatabase('Equity', __('Equity')) }}
                                                                    @break
                                                                @case('revenue')
                                                                    {{ \App\Helpers\TranslationHelper::transFromDatabase('Revenue', __('Revenue')) }}
                                                                    @break
                                                                @case('expense')
                                                                    {{ \App\Helpers\TranslationHelper::transFromDatabase('Expense', __('Expense')) }}
                                                                    @break
                                                                @default
                                                                    {{ $child->account_type }}
                                                            @endswitch
                                                        </p>
                                                    </div>
                                                    <div>
                                                        @if (!$child->is_active)
                                                            <span class="inline-flex items-center p-2.5 py-0.5 rounded-full text-s font-medium bg-red-100 text-red-800">
                                                                {{ \App\Helpers\TranslationHelper::transFromDatabase('Inactive', __('Inactive')) }}
                                                            </span>
                                                        @endif
                                                    </div>
                                                </div>
                                            </li>
                                        @endforeach
                                    </ul>
                                @else
                                    <p class="text-sm text-gray-500">{{ \App\Helpers\TranslationHelper::transFromDatabase('No Sub Accounts', __('No Sub Accounts')) }}</p>
                                @endif
                            </div>
                        </div>
                    </div>

                    <div class="mt-6 flex space-y-3 space-y-reverse">
                        <a href="{{ route('accounting.chart-of-accounts.edit', $account) }}" class="inline-flex items-center p-4 py-2 bg-yellow-600 border border-transparent rounded-md font-semibold text-s text-white uppercase tracking-widest hover:bg-yellow-700 focus:bg-yellow-700 active:bg-yellow-800 focus:outline-none focus:ring-2 focus:ring-yellow-500 focus:ring-offset-2 transition ease-in-out duration-150">
                            <svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4 ml-1" viewBox="0 0 20 20" fill="currentColor">
                                <path d="M13.586 3.586a2 2 0 112.828 2.828l-.793.793-2.828-2.828.793-.793zM11.379 5.793L3 14.172V17h2.828l8.38-8.379-2.83-2.828z" />
                            </svg>
                            {{ \App\Helpers\TranslationHelper::transFromDatabase('Edit Account', __('Edit Account')) }}
                        </a>
                        <form action="{{ route('accounting.chart-of-accounts.destroy', $account) }}" method="POST" class="inline-block">
                            @csrf
                            @method('DELETE')
                            <button type="submit" class="inline-flex items-center p-4 py-2 bg-red-600 border border-transparent rounded-md font-semibold text-s text-white uppercase tracking-widest hover:bg-red-700 focus:bg-red-700 active:bg-red-800 focus:outline-none focus:ring-2 focus:ring-red-500 focus:ring-offset-2 transition ease-in-out duration-150" onclick="return confirm('{{ \App\Helpers\TranslationHelper::transFromDatabase('Are you sure you want to delete this account?', __('Are you sure you want to delete this account?')) }}')">
                                <svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4 ml-1" viewBox="0 0 20 20" fill="currentColor">
                                    <path fill-rule="evenodd" d="M9 2a1 1 0 00-.894.553L7.382 4H4a1 1 0 000 2v10a2 2 0 002 2h8a2 2 0 002-2V6a1 1 0 100-2h-3.382l-.724-1.447A1 1 0 0011 2H9zM7 8a1 1 0 012 0v6a1 1 0 11-2 0V8zm5-1a1 1 0 00-1 1v6a1 1 0 102 0V8a1 1 0 00-1-1z" clip-rule="evenodd" />
                                </svg>
                                {{ \App\Helpers\TranslationHelper::transFromDatabase('Delete Account', __('Delete Account')) }}
                            </button>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</x-app-layout>
