
<div class="toggle-container">
    <label class="switch">
        <input type="checkbox" class="switch" @bind=ToggleState />
        <span class="slider round"></span>
    </label>
    @if (!string.IsNullOrEmpty(Caption))
    {
        <span class="toggle-label">@Caption</span>
    }
    <label style="margin:10px;">
        @ChildContent
    </label>
</div>
@code {
    [Parameter]
    public RenderFragment? ChildContent { get; set; }
    [Parameter]
    public EventCallback<bool> ToggleStateChanged { get; set; }
    [Parameter]
    public string Caption { get; set; } = string.Empty;

    private bool _value;

    [Parameter]
    public bool ToggleState
    {
        get { return _value; }
        set
        {
            if (_value != value)
            {
                _value = value;
                ToggleStateChanged.InvokeAsync(_value);
            }
        }
    }
}
