// Copyright © Selmo Technology GmbH. All Rights Reserved

using Microsoft.AspNetCore.Components;
using SelmoStudio.Hmi.Server.SelmoHmi.Shared.Component;
using SelmoStudio.Hmi.Server.SelmoHmi.Shared.Component.Types;

namespace SelmoStudio.Hmi.Server.Shared.Components.BaseComponents
{
    public partial class CheckboxComponent
    {
        private const string defaultValueText = "";

        [Parameter]
        public bool Value { get; set; }

        [Parameter]
        public string? CheckedText { get; set; }

        [Parameter]
        public string? UncheckedText { get; set; }

        [Parameter]
        public EventCallback<(ComponentEventInfo EventArgs, bool Value)> CheckedChanged { get; set; }

        private async Task OnValueChanged(bool value)
        {
            ComponentEventInfo eventInfo = new()
            {
                ComponentId = ComponentId,
                Type = EventType.SwitchChange,
                ButtonType = HmiElementType.Switch
            };

            await CheckedChanged.InvokeAsync((eventInfo, value));
        }

        private string GetSateText()
        {
            return Value ? CheckedText ?? defaultValueText : UncheckedText ?? defaultValueText;
        }
    }
}