// Fill out your copyright notice in the Description page of Project Settings.


#include "Manager/CsdkUiSubsystem.h"

void UCsdkUiSubsystem::OpenMsgBoxWithOk(const FString& Content, const FString& OkStr,
                                            const FOnMsgBoxBtnClicked& OkCallback)
{
	GetMsgBox()->SetMidBtnInfo(Content,OkStr,OkCallback);
	PopMsgBox->AddToViewport(100);
}

void UCsdkUiSubsystem::OpenMsgBoxWithOkAndCancel(const FString& Content, const FString& OkStr,
                                                     const FOnMsgBoxBtnClicked& OkCallback, const FString& CancelStr, const FOnMsgBoxBtnClicked& CancelCallback)
{
	GetMsgBox()->SetLeftBtnAndRightBtnInfo(Content,OkStr,OkCallback,CancelStr,CancelCallback);
	PopMsgBox->AddToViewport(100);
}

void UCsdkUiSubsystem::ShowThrobber()
{
	if(!Throbber)
	{
		UClass* ThrobberClass =  LoadClass<UUserWidget>(nullptr,TEXT("/CsdkUI/UI/Common/Throbber/Throbber_WBP.Throbber_WBP_C"));
		Throbber = CreateWidget<UUserWidget>(GetGameInstance(),ThrobberClass);
	}
	Throbber->AddToViewport(100);
}

void UCsdkUiSubsystem::HideThrobber()
{
	checkf(Throbber,TEXT("Did you Show Throbber First"))
	Throbber->RemoveFromParent();
}

void UCsdkUiSubsystem::ToggleMask(bool bIsShow)
{
	if (OnMaskToggled.IsBound())
	{
		OnMaskToggled.Broadcast(bIsShow);
	}
}

UCsdkMsgBoxBase* UCsdkUiSubsystem::GetMsgBox()
{
	if(!PopMsgBox)
	{
		UClass* MsgBoxClass =  LoadClass<UUserWidget>(nullptr,TEXT("/CsdkUI/UI/Common/MsgBox/MsgBox_WBP.MsgBox_WBP_C"));
		PopMsgBox = CreateWidget<UCsdkMsgBoxBase>(GetGameInstance(),MsgBoxClass);
	}
	return PopMsgBox;
}
