using UnityEngine;

/// <summary>
/// This component provides instructions and utilities for setting up scenes properly
/// in the RPG RougeLiteBattler project.
/// </summary>
public class SceneSetupGuide : MonoBehaviour
{
    [Header("Scene Setup Instructions")]
    [TextArea(10, 20)]
    public string setupInstructions = @"SCENE SETUP GUIDE for RPG RougeLiteBattler

TITLE SCREEN SCENE:
1. Create an empty GameObject named 'TitleScreenManager'
2. Add UIDocument component and assign TitleScreen.uxml
3. Add TitleScreenManager script
4. Ensure TitleScreen.uxml has buttons with names:
   - NewGameButton
   - LoadGameButton 
   - QuitButton

MAIN TEAM SELECT SCENE:
1. Should already have MainTeamSelectScript on an object with UIDocument
2. Add navigation buttons to the UI Document:
   - BackToTitleButton (to return to title)
   - ProceedToBattleButton (to go to battle setup)

BATTLE SETUP SCENE:
1. Should already have BattleSetupMenu script
2. Add a 'Back to Team Select' button
3. Assign the button to backToTeamSelectButton field in BattleSetupMenu

BUILD SETTINGS:
The scenes should be added to Build Settings in this order:
0. TitleScreen
1. MainTeamSelectScene
2. BattleSetupMenu
3. BattleScene
4. MapMaker (optional)

TESTING:
- Start the game from TitleScreen scene
- Test navigation: Title -> Team Select -> Battle Setup -> Battle
- Test back buttons work correctly
- Test save/load functionality";

    [Header("Current Scene Info")]
    public string currentSceneName;
    public bool hasRequiredComponents;

    private void Start()
    {
        currentSceneName = UnityEngine.SceneManagement.SceneManager.GetActiveScene().name;
        CheckSceneSetup();
    }

    private void CheckSceneSetup()
    {
        switch (currentSceneName)
        {
            case "TitleScreen":
                CheckTitleScreenSetup();
                break;
            case "MainTeamSelectScene":
                CheckTeamSelectSetup();
                break;
            case "BattleSetupMenu":
                CheckBattleSetupSetup();
                break;
            default:
                Debug.Log($"Scene setup guide not configured for scene: {currentSceneName}");
                break;
        }
    }

    private void CheckTitleScreenSetup()
    {
        TitleScreenManager manager = FindFirstObjectByType<TitleScreenManager>();
        if (manager == null)
        {
            Debug.LogWarning("TitleScreenManager not found in scene! Please add it.");
            hasRequiredComponents = false;
        }
        else
        {
            Debug.Log("✓ TitleScreenManager found");
            hasRequiredComponents = true;
        }
    }

    private void CheckTeamSelectSetup()
    {
        MainTeamSelectScript manager = FindFirstObjectByType<MainTeamSelectScript>();
        if (manager == null)
        {
            Debug.LogWarning("MainTeamSelectScript not found in scene!");
            hasRequiredComponents = false;
        }
        else
        {
            Debug.Log("✓ MainTeamSelectScript found");
            hasRequiredComponents = true;
        }
    }

    private void CheckBattleSetupSetup()
    {
        BattleSetupMenu manager = FindFirstObjectByType<BattleSetupMenu>();
        if (manager == null)
        {
            Debug.LogWarning("BattleSetupMenu not found in scene!");
            hasRequiredComponents = false;
        }
        else
        {
            Debug.Log("✓ BattleSetupMenu found");
            hasRequiredComponents = true;
        }
    }

    [ContextMenu("Log Scene Setup Status")]
    public void LogSceneSetupStatus()
    {
        Debug.Log($"Current Scene: {currentSceneName}");
        Debug.Log($"Required Components Present: {hasRequiredComponents}");
        Debug.Log("Setup Instructions:\n" + setupInstructions);
    }
}
