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


#include "SMainWindowHeader.h"

#include "Singleton/PortAudioAPI.h"
#include "SButton.h"
#include "SlateOptMacros.h"
#include "SProgressBar.h"
#include "WindowManager.h"
#include "ChannelRack/ChannelRack.h"
#include "PatternThumbnail/SPatternSelector.h"
#include "Widgets/SBoxPanel.h"

BEGIN_SLATE_FUNCTION_BUILD_OPTIMIZATION

TOptional<float> SMainWindowHeader::GetProgress() const
{
	return FPortAudioAPI::Get().GetBufferLoad();
}

void SMainWindowHeader::Construct(const FArguments& InArgs)
{
	OnChannelRackClicked = InArgs._OnChannelRackClicked;
	OnMixerClicked = InArgs._OnMixerClicked;
	
	ChildSlot
	[
		SNew(SHorizontalBox)
		+SHorizontalBox::Slot()
		.AutoWidth()
		[
			SNew(SButton)
			.Text(FText::FromString("ChannelRack"))
			.OnClicked_Raw(this, &SMainWindowHeader::ToggleChannelRack)
		]
		+SHorizontalBox::Slot()
		.AutoWidth()
		[
			SNew(SButton)
			.Text(FText::FromString("Mixer"))
			.OnClicked_Raw(this, &SMainWindowHeader::ToggleMixer)
		]
		+SHorizontalBox::Slot()
		.AutoWidth()
		[
			SNew(SProgressBar)
			.Percent(this, &SMainWindowHeader::GetProgress)
		]
		+SHorizontalBox::Slot()
		.AutoWidth()
		.VAlign(EVerticalAlignment::VAlign_Fill)
		[
			SNew(SBox)
			.WidthOverride(200)
			[
				SNew(SPatternSelector)
			]
		]
	];
}

FReply SMainWindowHeader::ToggleChannelRack()
{
	OnChannelRackClicked.ExecuteIfBound();
	return FReply::Handled();
}

FReply SMainWindowHeader::ToggleMixer()
{
	OnMixerClicked.ExecuteIfBound();
	return FReply::Handled();
}

END_SLATE_FUNCTION_BUILD_OPTIMIZATION