using AI.Platform.Core;
using AI.Platform.Core.Entity.Site;
using AI.Platform.Page.Pages.Site.Model;
using Microsoft.AspNetCore.Components;

namespace AI.Platform.Page.Pages.Site;

public partial class UpdateScreenDialog
{

    /// <summary>
    /// 信息回调
    /// </summary>
    [Parameter] public EventCallback<ScrrenDialogModel> ModelChanged { get; set; }

    /// <summary>
    /// 打开/关闭窗口回调
    /// </summary>
    [Parameter] public EventCallback<bool> IsVisibleChanged { get; set; }

    /// <summary>
    /// 信息回调
    /// </summary>
    [Parameter] public EventCallback<ScrrenDialogModel> onCallback { get; set; }

    /// <summary>
    /// 打开/关闭窗口回调
    /// </summary>
    [Parameter] public EventCallback<bool> onVisibleCallback { get; set; }

    /// <summary>
    /// 数据
    /// </summary>
    [Parameter] public ScrrenDialogModel Model { get; set; }

    /// <summary>
    /// 配置是否弹窗
    /// </summary>
    [Parameter] public bool IsVisible { get; set; }

    

    protected override void OnParametersSet()
    {
        
    }

    /// <summary>
    /// 关闭弹窗
    /// </summary>
    public async Task Close()
    {
        await OnlyClose();
    }
    /// <summary>
    /// 仅关闭弹窗
    /// </summary>
    /// <returns></returns>
    private async Task OnlyClose()
    {
        if (IsVisibleChanged.HasDelegate)
        {
            await IsVisibleChanged.InvokeAsync(false);
        }

        if (onVisibleCallback.HasDelegate)
        {
            await onVisibleCallback.InvokeAsync(false);
        }
    }

    /// <summary>
    /// 确定按钮事件
    /// </summary>
    /// <returns></returns>
    private async Task onSure()
    {
        if (ModelChanged.HasDelegate)
        {
            await ModelChanged.InvokeAsync(Model);
        }

        if (onCallback.HasDelegate)
        {
            await onCallback.InvokeAsync(Model);
        }
        await OnlyClose();
    }

    
}
