// Copyright © Selmo Technology GmbH. All Rights Reserved

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

namespace SelmoStudio.Hmi.Server.Shared.Components.BaseComponents
{
    public partial class ComponentWithTextChangeBase
    {
        [Parameter]
        public string Text { get; set; }

        [Parameter]
        public string Placeholder { get; set; }

        [Parameter]
        public EventCallback<TextBoxEventArgs> OnTextChanged { get; set; }

        [Parameter]
        public EventCallback<string> TextChanged { get; set; }

        public ComponentId ComponentId { get; set; } = new(Guid.NewGuid());

        protected async Task OnChange(object value)
        {
            await TextChanged.InvokeAsync(value?.ToString());

            await OnTextChanged.InvokeAsync(new(ComponentId, EventType.TextFieldChange, value?.ToString(), HmiElementType.TextBox));
        }
    }
}