#if UNITY_EDITOR && UNITY_6000_0_OR_NEWER
using UnityEditor;
using UnityEditor.Build;
using UnityEditor.Build.Reporting;
using UnityEngine;

namespace JamRoulette
{
    /// <summary>
    /// Turns off the Unity splash screen for WebGL builds. The wrapper has its own
    /// loading screen and splash, and the game boots hidden anyway, so Unity's splash
    /// only delays the moment it can register. Unity 6 lets every plan disable it.
    /// </summary>
    [InitializeOnLoad]
    internal class MicrogameBuildSettings : IPreprocessBuildWithReport
    {
        public int callbackOrder => 0;

        // Also on editor load, so Player Settings shows the real value before anyone builds.
        static MicrogameBuildSettings()
        {
            if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.WebGL)
                DisableSplash();
        }

        public void OnPreprocessBuild(BuildReport report)
        {
            if (report.summary.platform == BuildTarget.WebGL)
                DisableSplash();
        }

        private static void DisableSplash()
        {
            if (!PlayerSettings.SplashScreen.show) return;
            PlayerSettings.SplashScreen.show = false;
            Debug.Log("[Microgame] Disabled the Unity splash screen — the Jam Roulette wrapper shows its own.");
        }
    }
}
#endif
