#include "ui/ui_extensions.lua"
#include "ui/ui_helpers.lua"
#include "ui/components/buttons.lua"

GpHint = function(obj)
    local icon = obj.icon
    local hintText = obj.text

    obj.icon = nil
    obj.text = nil

    icon.colorFilter = { 1, 1, 1, 0.7 }

    local view = Ui.HorizontalLayout
    {
        text = hintText,

        alignment = Ui.V.Middle,

        icon,

        Ui.Text
        {
            font = { "regular.ttf", 22 },
            text = Ui.bind().parent.text,
            color = { 1, 1, 1, 0.7 }
        }
    }

    return view:new(obj)
end

TutorialWindow = Ui.Window
{
    w = 792,
    h = 720,

    animator = { playTime = 0.25, curveType = Ui.AnimationCurves.Cosine },
    ignoreNavigation = true,

    onShow = function (self)
        SetBool("game.tutorial.enabled", true)
    end,

    onClose = function (self)
        SetBool("game.tutorial.enabled", false)
    end,

    Ui.Frame
    {
        resizeToParent = true,

        Ui.Rect
        {
            resizeToParent = true,
            cornerRadius = 8,
            color = { 0, 0, 0, 0.55 },
        },

        Ui.Text
        {
            hAlign = Ui.H.Center,
            vAlign = Ui.V.Top,

            margin = { top = 30 },

            font = { "bold.ttf", 30 },
            text = "loc@UI_THIRD_PERSON_VIEW_HINT_TITLE"
        },

        Ui.Rect
        {
            hAlign = Ui.H.Center,
            vAlign = Ui.V.Top,

            w = 600,
            h = 375,
            margin = { top = 96 },

            cornerRadius = 10,
            fillImagePath = "ui/common/3rd_preview.png"
        },

        Ui.Frame
        {
            w = 600,
            h = 160,
            
            hAlign = Ui.H.Center,
            margin = { top = 491 },

            Ui.Text
            {
                vAlign = Ui.V.Middle,
                hAlign = Ui.H.Center,

                font = { "regular.ttf", 22 }, 

                text = GetTranslatedStringByKey("loc@UI_CHANGE_VIEW_HINT," .. string.upper(GetString("options.input.keymap.camera_view"))),
                wrapWidth = 600
            }
        },

        GpHint 
        { 
            hAlign = Ui.H.Center,
            vAlign = Ui.V.Bottom,

            margin = { bottom = 20 },

            icon = Ui.ActionIcons["menu:menu_cancel"],
            text = "loc@UI_BUTTON_CLOSE",

            visible = Ui.bind():call(function() return LastInputDevice() == UI_DEVICE_GAMEPAD end)
        },

        Teardown.GenericButton
        {
            w = 230,
            h = 40,

            hAlign = Ui.H.Center,
            vAlign = Ui.V.Bottom,

            margin = { bottom = 20 },

            visible = Ui.bind():call(function() return LastInputDevice() ~= UI_DEVICE_GAMEPAD end),

            text = "loc@UI_BUTTON_CLOSE",

            onPressed = function(self)
                self.root:hide()
            end
        }
    },

    onPreDraw = function(self)
        UiMakeInteractive()
        if LastInputDevice() == UI_DEVICE_GAMEPAD then
            UiSetCursorState(UI_CURSOR_HIDE_AND_LOCK)
        else
            UiSetCursorState(UI_CURSOR_SHOW)
        end

        local canvas = UiCanvasSize()

        self.x = canvas.w / 2 - self.w / 2
        self.y = canvas.h / 2 - self.h / 2
    end,
}