@inherits ListBoxBaseComponent<CheckedListBoxControl>

<span style="@GetStyle">
    @for (int i = 0; i < Control.Items.Count; i++)
    {
        int index = i;
        <input checked="@(Control.CheckedIndices.Contains(index))"
               type="checkbox"
               disabled="@IsDisabled"
               @onchange="(e) => CheckChanged(index, e)"/>
        @Control.Items[index]
        <br/>
    }
</span>

@code {

    protected override string GetStyle
        => $"overflow-y:scroll;{GetControlPosition()}{GetControlFont()}{GetBackColor()}";

    protected override void OnParametersSet()
    {
        base.OnParametersSet();

        FillData();

        Control.FilterData();
    }

    private void CheckChanged(int i, ChangeEventArgs e)
    {
        CheckedListBoxChange(i, e.Value);

        Refresh();
    }

    private void CheckedListBoxChange(int index, object value)
    {
        if (index != -1 && value is bool newValue)
        {
            Control.CheckedListBox.SetItemChecked(index, newValue);
            ControlFilterRefresh();
            Control.OnSelectedIndexChanged(null);
        }
    }
}
