#pragma once

#include "Game/GameModeManager.hpp"
#include "System/SysNew.hpp"
#include "Unknown/Common.hpp"
#include "types.h"

#include <nitro/g2.h>
#include <nitro/reg.h>

DECL_PTMF(TitleScreenPTMF, Input *pButtons, TouchControl *pTouchControl);

typedef u32 TitleScreenState;
enum TitleScreenState_ {
    TitleScreenState_None                 = 0, // does nothing
    TitleScreenState_IdleBeforeUI         = 1,
    TitleScreenState_DrawUIOnInput        = 2,
    TitleScreenState_DrawUIOnCsCmd        = 3, //! TODO: definitely related to the cs, "cs cmd" is assumed
    TitleScreenState_IdleBeforeFileSelect = 4,
    TitleScreenState_ToFileSelect         = 5,
    TitleScreenState_Max                  = 6
};

class TitleScreen_Sub2 : public LinkList<TitleScreen_Sub2> {
public:
    /* 00 (vtable) */
    /* 0C */ unk32 mUnk_0C;
    /* 10 */ bool mUnk_10;
    /* 11 */ unk8 mUnk_11;
    /* 12 */ unk8 mUnk_12;
    /* 13 */ unk8 mUnk_13;

    TitleScreen_Sub2() :
        mUnk_0C(0),
        mUnk_10(false) {}

    // data_ov025_020c5b24 vtable
    /* 00 */ virtual void vfunc_00();
};

// similar to UnkSubStruct1
class TitleScreen_Sub3 : public UnkSubStruct1_Base {
public:
    /* 00 (base) */
    /* 20 */ unk32 mUnk_20;
    /* 24 */

    TitleScreen_Sub3();
    void func_0201effc(unk32 param1, unk32 param2, unk32 param3);
    bool func_0201f04c();

    // data_020442d4 vtable
    /* 00 */ virtual void vfunc_00() override;
    /* 04 */ virtual void vfunc_04() override;
    /* 08 */ virtual void vfunc_08() override;

    void Subprocess1_UnkValueSets() {
        this->mUnk_10 = this->mUnk_18;
    }

    void Subprocess2_UnkValueSets() {
        this->mUnk_10 = this->mUnk_14;
    }

    UnkSubStruct1_Methods;
};

class TitleScreen : public GameModeManagerBase_104 { // 0233c6d4
public:
    /* 000 (base) */
    /* 01C */ TitleScreenState mState;
    /* 020 */ bool mShowUI;
    /* 021 */ u8 mUnk_021;
    /* 022 */ unk8 mUnk_022;
    /* 023 */ unk8 mUnk_023;
    /* 024 */ CellAnimObject mUnk_024; // feather
    /* 09C */ CellAnimObject mUnk_09C; // green rectangle
    /* 114 */ CellAnimObject mUnk_114; // "touch screen!" text
    /* 18C */ CellAnimObject mUnk_18C; // copyright text
    /* 204 */ TitleScreen_Sub2 mUnk_204;
    /* 218 */ TitleScreen_Sub3 mUnk_218;
    /* 23C */ UnkStruct_ov019_020d24c8_28_258 mUnk_23C;
    /* 254 */ CellAnimObject mUnk_254; // logo shine
    /* 2CC */ CellAnimObject mUnk_2CC; // logo shine outline (it's barely visible)
    /* 344 */ unk32 mUnk_344;
    /* 348 */

    TitleScreen();

    void func_ov025_020c4e54();
    void func_ov025_020c4e6c();
    void func_ov025_020c4e90();
    void func_ov025_020c4ea0(TitleScreenState state);
    void func_ov025_020c592c();
    void func_ov025_020c5964();
    void func_ov025_020c5988();

    // data_ov025_020c5aec
    void func_ov025_020c5200(Input *pButtons, TouchControl *pTouchControl);
    void func_ov025_020c5204(Input *pButtons, TouchControl *pTouchControl);
    void func_ov025_020c5240(Input *pButtons, TouchControl *pTouchControl);
    void func_ov025_020c53d0(Input *pButtons, TouchControl *pTouchControl);
    void func_ov025_020c55a4(Input *pButtons, TouchControl *pTouchControl);
    void func_ov025_020c55e4(Input *pButtons, TouchControl *pTouchControl);

    // data_ov025_020c5b30 vtable
    /* 00 */ virtual ~TitleScreen() override;
    /* 08 */ virtual void vfunc_08(Input *pButtons, TouchControl *pTouchControl) override;
    /* 0C */ virtual void vfunc_0C(unk32 param1) override;
    /* 10 */ virtual void vfunc_10(unk8 *param1) override;
    /* 14 */ virtual void vfunc_14(unk8 *param1) override;
};

class TitleScreenManager : public TitleScreenManager_Base {
public:
    /* 000 (base) */
    /* 154 */ GameModeBase *mpGameMode;
    /* 158 */

    TitleScreenManager(unk32 param1) NO_INLINE {
        this->mpGameMode = NULL;
        GX_SetGraphicsMode(1, 0, 1);
        GXS_SetGraphicsMode(5);
        G2S_SetBG3Control(1, 0, 14, 5, 0);
    }

    void func_ov025_020c4c20();
    void func_ov025_020c4c30();

    // data_ov025_020c5a98 vtable
    /* 08 */ virtual ~TitleScreenManager() override;
    /* 14 */ virtual void vfunc_14() override;
    /* 18 */ virtual void vfunc_18() override;
    /* 24 */ virtual void vfunc_24() override;
    /* 28 */ virtual void vfunc_28(unk8 *param1) override;
    /* 2C */ virtual void DrawUI(unk8 *param1) override;
    /* 38 */ virtual void vfunc_38(u32 sceneIndex, u8 roomIndex, unk16 param3, unk16 param4) override;

    static TitleScreenManager *Create(unk32 param1);
};
