// Copyright (c) Microsoft Corporation. 
// Licensed under the MIT license.

#include "SAllowMorphTargetsWidget.h"
#include "SAllowMorphTargetsMeshView.h"
#include "SAllowMorphTargetsList.h"
#include "SAllowMorphTargetsPerLOD.h"

#include "EditorStyleSet.h"
#include "Widgets/Layout/SScrollBox.h"
#include "Widgets/Text/STextBlock.h"

void SAllowMorphTargetsWidget::Construct(const FArguments& Args, const TWeakObjectPtr<ULODRecipe> LODRecipe)
{
	LODRecipeWeak = LODRecipe;

	TSharedRef<SBorder> MainContent = SNew(SBorder)
	.BorderImage(FEditorStyle::GetBrush("ToolPanel.GroupBorder"))
	.BorderBackgroundColor(FColor(166, 166, 166))
	.Padding(5.0f)
	[
		SNew(SVerticalBox)
		+ SVerticalBox::Slot()
		.AutoHeight()
		.Padding(0.0f, 0.0f, 0.0f, 4.0f)
		[
			SNew(SBorder)
			.BorderImage(FEditorStyle::GetBrush("ToolPanel.GroupBorder"))
			.Padding(4.0f)
			[
				SAssignNew(AllowMorphTargetPerLODWidget, SAllowMorphTargetsPerLOD, SharedThis(this))
			]
			
		]
		+ SVerticalBox::Slot()
		[
			SNew(SSplitter)
			+ SSplitter::Slot()
			.Value(.3f)
			[
				SNew(SBorder)
				.Padding(4.0f)
				.BorderImage(FEditorStyle::GetBrush("ToolPanel.GroupBorder"))
				[
					SAssignNew(SkeletalMeshesWidget, SAllowMorphTargetsMeshView, SharedThis(this))
				]
			]
			+ SSplitter::Slot()
			[
				SNew(SBorder)
				.Padding(8.0f)
				.BorderImage(FEditorStyle::GetBrush("ToolPanel.GroupBorder"))
				[
					SNew(SScrollBox)
					+ SScrollBox::Slot()
					[
						SAssignNew(MorphTargetsWidget, SAllowMorphTargetsList, SharedThis(this))
					]
				]
			]
		]
	];
	
	ChildSlot.AttachWidget(MainContent);
}

TSharedPtr<FSkeletalMeshItem> SAllowMorphTargetsWidget::GetSelectedSkeletalMesh() const
{
	if(SkeletalMeshesWidget.IsValid())
		return SkeletalMeshesWidget->GetSelectedSkeletalMesh();

	return nullptr;
}

void SAllowMorphTargetsWidget::OnSkeletalMeshSelectionChanged()
{
	if (MorphTargetsWidget.IsValid())
	{
		MorphTargetsWidget->Refresh();
	}
}