@php
    $drAmt = '';
    $crAmt = '';
    if (isset($line) && $line) {
        if ($line->dr_cr === 'dr') $drAmt = number_format((float)$line->line_total, 2, '.', '');
        else                        $crAmt = number_format((float)$line->line_total, 2, '.', '');
    }
@endphp
<tr class="voucher-line" data-index="{{ $i }}">

    {{-- # --}}
    <td class="line-num ps-3 text-muted" style="font-size:12px;vertical-align:middle">
        {{ is_int($i) ? $i + 1 : 1 }}
    </td>

    {{-- Account --}}
    @include('accounting.vouchers._account_cell', ['i' => $i, 'line' => $line ?? null])

    {{-- Debit --}}
    <td style="vertical-align:middle;width:130px">
        <input type="number"
               name="lines[{{ $i }}][debit]"
               class="form-control form-control-sm text-end debit-input"
               value="{{ $drAmt }}"
               step="0.01" min="0" placeholder="0.00">
    </td>

    {{-- Credit --}}
    <td style="vertical-align:middle;width:130px">
        <input type="number"
               name="lines[{{ $i }}][credit]"
               class="form-control form-control-sm text-end credit-input"
               value="{{ $crAmt }}"
               step="0.01" min="0" placeholder="0.00">
    </td>

    {{-- Description --}}
    <td class="d-none d-md-table-cell" style="vertical-align:middle">
        <input type="text"
               name="lines[{{ $i }}][description]"
               class="form-control form-control-sm"
               value="{{ $line->description ?? '' }}"
               placeholder="Optional narration">
    </td>

    {{-- Tax Code --}}
    @if(count($taxCodes) > 0)
    <td class="d-none d-xl-table-cell" style="vertical-align:middle;width:130px">
        <select name="lines[{{ $i }}][tax_code_id]" class="form-select form-select-sm">
            <option value="">No Tax</option>
            @foreach($taxCodes as $tax)
                <option value="{{ $tax->id }}"
                    {{ isset($line) && $line->tax_code_id == $tax->id ? 'selected' : '' }}>
                    {{ $tax->code }} ({{ $tax->rate }}%)
                </option>
            @endforeach
        </select>
    </td>
    @endif

    @foreach(($dimensions ?? collect()) as $dimension)
        @include('accounting.vouchers._dimension_cell', [
            'dimension' => $dimension,
            'i' => $i,
            'line' => $line ?? null,
        ])
    @endforeach

    @include('accounting.vouchers._party_cell', ['i' => $i, 'line' => $line ?? null])

    {{-- Remove --}}
    <td style="vertical-align:middle;width:36px">
        <button type="button" class="btn btn-link text-danger p-1 remove-line" title="Remove line">
            <i class="bi bi-x-circle-fill" style="font-size:16px"></i>
        </button>
    </td>
</tr>
