@props([
    'name',
    'label' => null,
    'checked' => false,
    'value' => 1,
    'id' => null,
])

@php
    $id = $id ?? $name;
    $submitted = old($name);
    $isChecked = $submitted !== null ? (bool) $submitted : (bool) $checked;
    $errorBag = $errors ?? new \Illuminate\Support\ViewErrorBag();
    $errorMessage = $errorBag->first($name);
@endphp

<div class="form-check">
    <input type="hidden" name="{{ $name }}" value="0">
    <input
        id="{{ $id }}"
        name="{{ $name }}"
        type="checkbox"
        value="{{ $value }}"
        @checked($isChecked)
        {{ $attributes->class(['form-check-input', 'is-invalid' => $errorMessage]) }}
    >
    @if ($label)
        <label for="{{ $id }}" class="form-check-label">{{ $label }}</label>
    @endif
    @if ($errorMessage)
        <div class="invalid-feedback d-block">{{ $errorMessage }}</div>
    @endif
</div>
