// © 2025 Naked People Team. All Rights Reserved.

#pragma once

#include "CoreMinimal.h"
#include "CommonUserWidget.h"
#include "NakedDesire/Commissions/CommissionTypes.h"
#include "ForumCommissionsWidget.generated.h"

class UPanelWidget;
class UForumCommissionWidget;
class UMissionSubsystem;
class UCommission;

// The forum's Commissions tab (GDD §13). Reads the live board from UMissionSubsystem and lays the
// commissions out into four sections: offered dailies, offered weeklies, accepted (in-progress, both
// tiers), and completed-this-period. Rebuilds whenever the board changes, and routes row accept /
// abandon taps back to the subsystem. Section containers + the row class are authored in BP (§17.5).
UCLASS(Abstract)
class NAKEDDESIRE_API UForumCommissionsWidget : public UCommonUserWidget
{
	GENERATED_BODY()

protected:
	virtual void NativeConstruct() override;
	virtual void NativeDestruct() override;

private:
	// Offered commissions, split by tier.
	UPROPERTY(meta = (BindWidget))
	TObjectPtr<UPanelWidget> DailyContainer;

	UPROPERTY(meta = (BindWidget))
	TObjectPtr<UPanelWidget> WeeklyContainer;

	// Accepted commitments (both tiers) and completions for the current period.
	UPROPERTY(meta = (BindWidget))
	TObjectPtr<UPanelWidget> AcceptedContainer;

	UPROPERTY(meta = (BindWidget))
	TObjectPtr<UPanelWidget> CompletedContainer;

	UPROPERTY(EditDefaultsOnly, Category = "Forum")
	TSubclassOf<UForumCommissionWidget> CommissionEntryClass;

	// Bound to UMissionSubsystem::OnBoardChanged (a dynamic delegate, hence UFUNCTION).
	UFUNCTION()
	void Rebuild();

	void PopulateOffered(UPanelWidget* Container, ECommissionTier Tier);
	void PopulateContainer(UPanelWidget* Container, const TArray<UCommission*>& Commissions);
	UForumCommissionWidget* AddEntry(UPanelWidget* Container, UCommission* Commission);

	void HandleAcceptClicked(UCommission* Commission);
	void HandleAbandonClicked(UCommission* Commission);

	UMissionSubsystem* GetMissionSubsystem() const;
};