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

#pragma once

#include "CoreMinimal.h"
#include "CommonActivatableWidget.h"
#include "PhoneScreenWidget.generated.h"

class UButton;
class UCommonActivatableWidgetStack;
class UPhoneAppWidget;
class UPhoneHomeScreenWidget;

// The phone shell — one activatable pushed onto the GameLayout WidgetStack. It owns an inner app stack:
// the home screen sits at the base, apps push on top. CommonUI back navigation pops the active app to
// home, then closes the phone at home; the physical Home button (GoHome) is the explicit equivalent.
// Battery / BlockPhoneUse gating and the real apps land with the Phase 8 phone systems (GDD §9).
UCLASS(Abstract)
class NAKEDDESIRE_API UPhoneScreenWidget : public UCommonActivatableWidget
{
	GENERATED_BODY()

public:
	// Push an app onto the stack, on top of the home screen.
	void OpenApp(TSubclassOf<UPhoneAppWidget> AppClass);

protected:
	virtual void NativeOnActivated() override;
	virtual UWidget* NativeGetDesiredFocusTarget() const override;

private:
	UPROPERTY(meta = (BindWidget))
	TObjectPtr<UCommonActivatableWidgetStack> AppStack;

	// The phone's physical home button — clears the app stack back to the home screen.
	UPROPERTY(meta = (BindWidget))
	TObjectPtr<UButton> HomeButton;

	UPROPERTY(EditDefaultsOnly, Category = "Phone")
	TSubclassOf<UPhoneHomeScreenWidget> HomeScreenClass;

	// The live home screen at the base of the stack, tracked so GoHome can skip work when it's already on top.
	UPROPERTY(Transient)
	TObjectPtr<UPhoneHomeScreenWidget> HomeScreen;

	UPhoneHomeScreenWidget* PushHomeScreen();

	UFUNCTION()
	void GoHome();
};