@extends('layouts.admin')

@section('title', 'Chart of Accounts')

@section('page-title', 'Chart of Accounts')

@section('header-actions')
    <a href="{{ route('admin.chart-of-accounts.create') }}" class="px-4 py-2 bg-primary text-white rounded-lg hover:bg-blue-600 transition-colors flex items-center gap-2">
        <span class="material-symbols-outlined text-lg">add</span>
        <span>New Account</span>
    </a>
@endsection

@section('content')
<div class="max-w-7xl mx-auto">
    <div class="bg-white rounded-xl shadow-sm border border-[#e5e7eb] overflow-hidden">
        <div class="overflow-x-auto">
            <table class="w-full text-left">
                <thead class="bg-background-light border-b border-[#e5e7eb]">
                    <tr>
                        <th class="py-3 px-4 text-xs font-semibold text-[#617589] uppercase tracking-wider">Code</th>
                        <th class="py-3 px-4 text-xs font-semibold text-[#617589] uppercase tracking-wider">Name</th>
                        <th class="py-3 px-4 text-xs font-semibold text-[#617589] uppercase tracking-wider">Type</th>
                        <th class="py-3 px-4 text-xs font-semibold text-[#617589] uppercase tracking-wider">Category</th>
                        <th class="py-3 px-4 text-xs font-semibold text-[#617589] uppercase tracking-wider text-right">Balance</th>
                        <th class="py-3 px-4 text-xs font-semibold text-[#617589] uppercase tracking-wider">Status</th>
                        <th class="py-3 px-4 text-xs font-semibold text-[#617589] uppercase tracking-wider text-right">Actions</th>
                    </tr>
                </thead>
                <tbody class="divide-y divide-[#e5e7eb]">
                    @forelse($accounts as $account)
                        <tr class="hover:bg-background-light/50 transition-colors">
                            <td class="py-4 px-4 font-mono text-sm text-[#111418] text-gray-900">{{ $account->code }}</td>
                            <td class="py-4 px-4 text-sm text-[#111418] text-gray-900">{{ $account->name }}</td>
                            <td class="py-4 px-4">
                                <span class="px-2 py-1 rounded text-xs font-medium bg-blue-100 text-blue-800">
                                    {{ ucfirst($account->type) }}
                                </span>
                            </td>
                            <td class="py-4 px-4 text-sm text-[#617589]">{{ $account->category ?? '-' }}</td>
                            <td class="py-4 px-4 text-sm font-medium text-[#111418] text-gray-900 text-right">
                                {{ number_format($account->current_balance, 2) }}
                            </td>
                            <td class="py-4 px-4">
                                <span class="px-2 py-1 rounded text-xs font-medium {{ $account->is_active ? 'bg-green-100 text-green-800' : 'bg-gray-100 text-gray-800' }}">
                                    {{ $account->is_active ? 'Active' : 'Inactive' }}
                                </span>
                            </td>
                            <td class="py-4 px-4 text-right">
                                <div class="flex items-center justify-end gap-2">
                                    <a href="{{ route('admin.chart-of-accounts.edit', $account) }}" class="p-2 text-[#617589] hover:text-primary hover:bg-primary/10 rounded transition-colors" title="Edit">
                                        <span class="material-symbols-outlined text-lg">edit</span>
                                    </a>
                                    @if(!$account->is_system)
                                        <form method="POST" action="{{ route('admin.chart-of-accounts.destroy', $account) }}" onsubmit="return confirm('Are you sure?')" class="inline">
                                            @csrf
                                            @method('DELETE')
                                            <button type="submit" class="p-2 text-[#617589] hover:text-red-600 hover:bg-red-50 rounded transition-colors" title="Delete">
                                                <span class="material-symbols-outlined text-lg">delete</span>
                                            </button>
                                        </form>
                                    @endif
                                </div>
                            </td>
                        </tr>
                    @empty
                        <tr>
                            <td colspan="7" class="py-12 px-4 text-center text-[#617589]">
                                <span class="material-symbols-outlined text-4xl mb-2 block">account_tree</span>
                                <p>No accounts found</p>
                            </td>
                        </tr>
                    @endforelse
                </tbody>
            </table>
        </div>

        @if($accounts->hasPages())
            <div class="px-4 py-4 border-t border-[#e5e7eb]">
                {{ $accounts->links() }}
            </div>
        @endif
    </div>
</div>
@endsection



