/*
 * BUILD SETTINGS SETUP INSTRUCTIONS
 * =================================
 * 
 * If your title screen buttons aren't loading scenes, the most likely issue
 * is that the scenes aren't properly added to Build Settings.
 * 
 * REQUIRED SCENES IN BUILD SETTINGS:
 * =================================
 * 
 * Go to File > Build Settings and ensure these scenes are added IN THIS ORDER:
 * 
 * Index 0: TitleScreenScene (or TitleScreen)
 * Index 1: MainTeamSelectScene  
 * Index 2: BattleSetupMenu
 * Index 3: BattleScene
 * 
 * HOW TO ADD SCENES:
 * ==================
 * 
 * 1. Open File > Build Settings
 * 2. Click "Add Open Scenes" if the current scene isn't listed
 * 3. OR drag scene files from Project window into the "Scenes In Build" area
 * 4. Make sure the scenes are in the correct order (drag to reorder)
 * 5. Make sure all scenes have checkmarks (enabled)
 * 
 * SCENE NAMES MUST MATCH EXACTLY:
 * ===============================
 * 
 * The script looks for these exact names:
 * - "MainTeamSelectScene" (not "MainTeamSelect" or "TeamSelect")
 * - "BattleSetupMenu" (not "BattleSetup")
 * - "BattleScene" (not "Battle")
 * 
 * If your scene names are different, either:
 * A) Rename your scene files to match, OR
 * B) Update the TitleScreenManager script to use your scene names
 * 
 * DEBUGGING SCENE ISSUES:
 * ======================
 * 
 * 1. Select the TitleScreenManager GameObject in your scene
 * 2. In the Inspector, right-click the component and choose "Check Build Settings"
 * 3. Look at the Console for a list of scenes in Build Settings
 * 4. Verify "MainTeamSelectScene" appears in the list
 * 
 * LOAD GAME BUTTON ISSUES:
 * ========================
 * 
 * The Load Game button will be disabled (grayed out) if:
 * - No character data is saved
 * - This is the first time running the game
 * - Save data was cleared
 * 
 * To test Load Game functionality:
 * 1. Click "New Game" first
 * 2. Create at least one character in the team select screen
 * 3. Return to title screen
 * 4. The "Load Game" button should now be enabled
 * 
 * COMMON ISSUES:
 * =============
 * 
 * ❌ "Scene 'MainTeamSelectScene' couldn't be loaded"
 *    → Scene not in Build Settings
 * 
 * ❌ Buttons don't respond to clicks
 *    → Check Console for "Button not found" warnings
 *    → Verify UXML button names match script expectations
 * 
 * ❌ Load Game button always disabled
 *    → No character data saved yet
 *    → Create characters first with New Game
 * 
 * ❌ Styling issues
 *    → Ensure USS file is assigned to UIDocument
 *    → Check for USS syntax errors in Console
 * 
 */

using UnityEngine;

public class BuildSettingsHelper : MonoBehaviour
{
    [Header("Build Settings Checker")]
    [TextArea(5, 8)]
    public string instructions = @"1. Go to File > Build Settings
2. Add scenes in this order:
   - TitleScreenScene (index 0)
   - MainTeamSelectScene (index 1)
   - BattleSetupMenu (index 2)  
   - BattleScene (index 3)
3. Ensure all scenes are enabled (checked)
4. Use context menu to verify setup";

    [ContextMenu("Check Required Scenes")]
    public void CheckRequiredScenes()
    {
        string[] requiredScenes = { "TitleScreenScene", "MainTeamSelectScene", "BattleSetupMenu", "BattleScene" };

        Debug.Log("=== CHECKING REQUIRED SCENES ===");

        for (int i = 0; i < requiredScenes.Length; i++)
        {
            bool found = false;

            for (int j = 0; j < UnityEngine.SceneManagement.SceneManager.sceneCountInBuildSettings; j++)
            {
                string scenePath = UnityEngine.SceneManagement.SceneUtility.GetScenePathByBuildIndex(j);
                string sceneName = System.IO.Path.GetFileNameWithoutExtension(scenePath);

                if (sceneName.Equals(requiredScenes[i], System.StringComparison.OrdinalIgnoreCase))
                {
                    Debug.Log($"✓ {requiredScenes[i]} found at index {j}");
                    found = true;
                    break;
                }
            }

            if (!found)
            {
                Debug.LogError($"❌ {requiredScenes[i]} NOT FOUND in Build Settings!");
            }
        }

        Debug.Log("=== CHECK COMPLETE ===");
    }

    [ContextMenu("List All Build Settings")]
    public void ListAllBuildSettings()
    {
        Debug.Log("=== ALL SCENES IN BUILD SETTINGS ===");

        for (int i = 0; i < UnityEngine.SceneManagement.SceneManager.sceneCountInBuildSettings; i++)
        {
            string scenePath = UnityEngine.SceneManagement.SceneUtility.GetScenePathByBuildIndex(i);
            string sceneName = System.IO.Path.GetFileNameWithoutExtension(scenePath);
            Debug.Log($"Index {i}: {sceneName}");
        }
    }
}
