@php
    $indent = $level * 30;
    $hasChildren = $account->children->count() > 0;
@endphp

<tr class="account-row">
    <td style="padding-left: {{ $indent }}px;">
        <strong>{{ $account->code }}</strong>
        @if($account->is_system)
            <span class="badge bg-secondary badge-type">সিস্টেম</span>
        @endif
    </td>
    <td>
        @if($hasChildren)
            <i class="fas fa-folder text-warning"></i>
        @endif
        {{ $account->name }}
        @if($account->description)
            <br><small class="text-muted">{{ Str::limit($account->description, 50) }}</small>
        @endif
    </td>
    <td class="text-end">
        @if(!$hasChildren)
            <span class="{{ $account->current_balance >= 0 ? 'text-success' : 'text-danger' }}">
                {{ number_format($account->current_balance, 2) }}
            </span>
            <br>
            <small class="text-muted">{{ $account->normal_balance }}</small>
        @else
            <span class="text-primary">
                {{ number_format($account->children->sum('current_balance'), 2) }}
            </span>
        @endif
    </td>
    <td>
        <div class="btn-group btn-group-sm">
            <a href="{{ route('accounts.show', $account->id) }}" class="btn btn-info" title="দেখুন">
                <i class="fas fa-eye"></i>
            </a>
            @if(!$account->is_system && (auth()->user()->user_type == 'admin' || auth()->user()->user_type == 'committee'))
            <a href="{{ route('accounts.edit', $account->id) }}" class="btn btn-primary" title="সম্পাদনা">
                <i class="fas fa-edit"></i>
            </a>
            @endif
            @if(!$hasChildren && !$account->is_system && (auth()->user()->user_type == 'admin' || auth()->user()->user_type == 'committee'))
            <form action="{{ route('accounts.destroy', $account->id) }}" method="POST" class="d-inline">
                @csrf
                @method('DELETE')
                <button type="submit" class="btn btn-danger" title="ডিলিট" 
                        onclick="return confirm('আপনি কি এই অ্যাকাউন্ট ডিলিট করতে চান?')">
                    <i class="fas fa-trash"></i>
                </button>
            </form>
            @endif
        </div>
    </td>
</tr>

@if($hasChildren)
    @foreach($account->children as $child)
        @include('accounts.partials.account-row', ['account' => $child, 'level' => $level + 1])
    @endforeach
@endif