@php
    $group = $group ?? null;
    $memberIds = $memberIds ?? [''];
    if ($memberIds === []) {
        $memberIds = [''];
    }
@endphp

<div class="row g-3 billing-tax-form">
    <div class="col-md-6">
        <label class="form-label" for="group_name">Group name</label>
        <input type="text" name="name" id="group_name" class="form-control @error('name') is-invalid @enderror" value="{{ old('name', $group?->name) }}" required>
        @error('name')<div class="invalid-feedback">{{ $message }}</div>@enderror
    </div>
</div>

<div class="billing-tax-group-rows mt-3" id="tax-group-rows">
    @foreach($memberIds as $index => $memberId)
        @include('admin.preferences.taxes.partials._group-member-row', [
            'index' => $index,
            'memberId' => $memberId,
            'individualTaxes' => $individualTaxes,
            'canRemove' => $index > 0,
        ])
    @endforeach
</div>

@error('member_ids')<div class="text-danger small mt-2">{{ $message }}</div>@enderror

<button type="button" class="btn btn-light btn-sm border mt-2" id="btn-add-tax-row">
    <i class="ri-add-line me-1"></i> Add tax
</button>

<div class="form-check mt-4">
    <input type="hidden" name="is_selectable" value="0">
    <input class="form-check-input billing-pref-switch" type="checkbox" name="is_selectable" value="1" id="group_is_selectable" @checked(old('is_selectable', $group?->is_selectable ?? true))>
    <label class="form-check-label" for="group_is_selectable">Can be selected in Invoices &amp; Items</label>
</div>

<template id="tax-group-row-template">
    @include('admin.preferences.taxes.partials._group-member-row', [
        'index' => '__INDEX__',
        'memberId' => '',
        'individualTaxes' => $individualTaxes,
        'canRemove' => true,
    ])
</template>

@push('scripts')
<script src="{{ asset('js/tax-group-form.js') }}"></script>
@endpush
