using DoomDeathmatch.Component.UI;
using DoomDeathmatch.Scene.Main;
using Engine.Asset.Font;
using Engine.Input;
using Engine.Scene;
using Engine.Scene.Component.BuiltIn.Renderer;
using OpenTK.Mathematics;

namespace DoomDeathmatch.Scene.Rules;

public static class RulesScene
{
  public static Engine.Scene.Scene Create(Engine.Engine parEngine)
  {
    var scene = new Engine.Scene.Scene();

    var (cameraObject, camera) = UiUtil.CreateOrthographicCamera(scene);

    var (uiContainerObject, uiContainer) = UiUtil.CreateBackgroundUi(scene, camera);

    var (logoObject, logoUi) = UiUtil.CreateLogoUi(parEngine, scene, uiContainer);

    var (backUiObject, backUi) = UiUtil.CreateTextUi(scene, uiContainer,
      parEngine.AssetResourceManager.Load<Font>("font/test"), "Назад");
    backUi.OnClick += _ => parEngine.SceneManager.TransitionTo(MainScene.Create(parEngine));

    var (rulesObject, rulesUi) = UiUtil.CreateTextUi(scene, uiContainer,
      parEngine.AssetResourceManager.Load<Font>("font/test"), "Правила");

    var (stackObject, stack) = UiUtil.CreateStackUi(scene, uiContainer,
      [rulesUi, backUi]);
    stack.Offset = new Vector2(0, -1f);
    stackObject.Transform.Size = new Vector3(1f, 6f, 1f);

    var selectorObject = new GameObject
    {
      Transform = { Translation = new Vector3(0, 0, -1), Size = new Vector3(0.5f, 1f, 1f) }
    };
    selectorObject.AddComponent(new SelectorComponent
    {
      Children = { backUi },
      SelectKey = KeyboardButtonCode.Space,
      NextKey = KeyboardButtonCode.Down,
      PrevKey = KeyboardButtonCode.Up,
    });
    selectorObject.AddComponent(new Box2DRenderer { Color = new Vector4(1, 0, 0, 1) });

    scene.AddChild(uiContainerObject, selectorObject);

    scene.SetChild(uiContainerObject, logoObject);
    scene.SetChild(uiContainerObject, stackObject);

    scene.SetChild(stackObject, rulesObject);
    scene.SetChild(stackObject, backUiObject);

    return scene;
  }
}