timer_quest_mirror = {
    name = "panels",
    category = "UI",
};

function Spawn_QuestMirror()
    return Group
    {
        QuestMirror
        {
            x = 0, y = -1000,
            w = 1024, h = 768,
            
            timer_settings = timer_quest_mirror,
            name = "quest_mirror_dlg",
            
            pic_quest_item_coords = "722,275",
            
            
            state_handlers = {
                justcreated = function()
                    DisableControl("close_mirror");
                    SetItemCount("pnl_mirror_state", 0);
                end;
                showing = function()
                    Dump();
                    SetItemCount("pnl_mirror_state", 1);
                    if GetCount("hint_group_welcome") == 2 then
                        GM_StartPersistentAction("UIClick");
                    end;
                    PlaySound("audio/sfx/shop/dialogappear.ogg");
                    EnableControl("close_mirror");
                    DeactivateControl("start_day");
                    kDialogActive = true;
                    bmp_fade_StartCurveCallBack("curves/fade.xml","in","");
                    pic_new_quest_StartCurveCallBack("curves/game_ui_panels.xml", "mirror_out", "");
                    EnableWindow("new_quest", false);
                    DeactivateControl("start_day");
                    EnableWindow("quest_expert_achieved", false);
                    EnableWindow("quest_expert_fail", false);
                    EnableWindow("quest_text", true);
                end;
                showed = function()
                    ActivateControl("close_mirror");
                    ActivateControl("accept_quest");
                    ActivateControl("complete_quest");
                    ActivateControl("next_quest");
                    DeactivateControl("start_day");
                    SetItemCount("pnl_mirror_state", 2);
                    if GetCount("hint_group_welcome") == 2 then
                        GM_StartPersistentAction("UIClick");
                    end;
                end;
                hiding = function()
                    SetItemCount("pnl_mirror_state", 1);
                    PlaySound("audio/sfx/shop/dialogdisappear.ogg");
                    DeactivateControl("close_mirror");
                    DeactivateControl("accept_quest");
                    DeactivateControl("next_quest");
                    pic_new_quest_StartCurveCallBack("curves/game_ui_panels.xml", "mirror_in", "");
                    bmp_fade_StartCurveCallBack("curves/fade.xml","out","");
                end;
                hidden = function()
                    EnableWindow("new_quest", true);
                    ActivateControl("start_day");
                    if GetCount("lvl_gates") ~= 6 then
                        GM_StartPersistentAction("ShopClick");
                    end;
                    SetItemCount("pnl_mirror_state", 0);
                    
                    if (GetCount("hint_gate") == 0) and (GetCount("day_elapsed") == 1) and (GetCount("tutorial_skipped") == 0) then
                        SetItemCount("hint_gate", 1);
                    end;
                    if (GetCount("hint_water_reserve") == 0) and (GetCount("day_elapsed") == 2) and (GetCount("tutorial_skipped") == 0) then
                        SetItemCount("hint_water_reserve", 1);
                    end;
                    if (GetCount("hint_new_plant") == 0) and (GetCount("day_elapsed") == 2) and (GetCount("hint_go_back") == 1) then
                        SetItemCount("hint_new_plant", 1);
                    end;
                    
                    if --[[(GetCount("tutorial_skipped") == 0) and--]] (GetCount("day_elapsed") > 2) then
                        if (GetCount("hint_upgrade_storage") == 0) and (GetCount("bud_collected") >= GetCount("storage_capacity")) then
                            SetItemCount("hint_upgrade_storage", 1);
                        else
                            if (GetCount("hint_upgrade_water_jug") == 0) and (GetCount("water") >= GetCount("waterbarrel_capacity"))
                                and (GetCount("lvl_water_barrel") == 1) and (GetCount("day_elapsed") > 3)
                            then
                                SetItemCount("hint_upgrade_water_jug", 1);
                            else
                                if (GetCount("available_beds") == 0) and (GetCount("hint_shovel") == 0) then
                                    SetItemCount("hint_shovel", 1);
                                else
                                    if (GetCount("curr_garden") == 1) and (GetCount("hint_sell_plant") == 0) and (GetCount("plant_count") == 10) then
                                        SetItemCount("hint_sell_plant", 1);
                                    else
                                        if (GetCount("curr_garden") == 2) and (GetCount("hint_sell_plant2") == 0) and (GetCount("day_unlock_fertilizer_plant") == GetCount("day_elapsed")) then
                                            SetItemCount("hint_sell_plant2", 1);
                                        end;
                                    end;
                                end;
                            end
                        end;
                    end;
                    kDialogActive = false;
                end;
            },
            
            state_curves = {
                container = "curves/mirror_drop_down.xml",
                showing = {
                    set = "",
                    inverse = false,
                    offset = false
                },
                hiding = {
                    set = "",
                    inverse = true,
                    offset = false
                },
            },
            
            BitmapVisual
            {
                x=475,
                y=145,
                image="game/common/laboratory/gem_gate_0"..tostring(GetCount("curr_garden")),
                name = "mirror_gem_holder",
                BitmapVisual
                {
                    name = "gem_quest_1",
                    ini_file = "config/ui/gems.ini",
                    ini_tag  = "GEM"..tostring(GetCount("curr_garden")).."1",
                },
                BitmapVisual
                {
                    name = "gem_quest_2",
                    ini_file = "config/ui/gems.ini",
                    ini_tag  = "GEM"..tostring(GetCount("curr_garden")).."2",
                },
                BitmapVisual
                {
                    name = "gem_quest_3",
                    ini_file = "config/ui/gems.ini",
                    ini_tag  = "GEM"..tostring(GetCount("curr_garden")).."3",
                },
                BitmapVisual
                {
                    name = "gem_quest_4",
                    ini_file = "config/ui/gems.ini",
                    ini_tag  = "GEM"..tostring(GetCount("curr_garden")).."4",
                },
                BitmapVisual
                {
                    name = "gem_quest_5",
                    ini_file = "config/ui/gems.ini",
                    ini_tag  = "GEM"..tostring(GetCount("curr_garden")).."5",
                },
                TextVisual
                {
                    w=2, h = 2,
                    context = {"lvl_gates"},
                    context_change = function(item, old_val, new_val)
                        
                        gem_quest_1_SetVisible(new_val >= 2);
                        gem_quest_2_SetVisible(new_val >= 3);
                        gem_quest_3_SetVisible(new_val >= 4);
                        gem_quest_4_SetVisible(new_val >= 5);
                        gem_quest_5_SetVisible(new_val >= 6);
                        
                    end;
                },
            },
            Bitmap
            {
                image="interface/game/pnl_quest_mirror/back",
                x=kCenter+90,
                y=kCenter-20,
                
                BitmapVisual
                {
                    name = "reward_single",
                    x = 450,
                    y = 294,
                    image = "interface/game/pnl_quest_mirror/reward_1",
                    
                    SetStyle(TextStyle),
                    CreateOndineText(20, BlueOutline, kCenter+1, 40, "#"..GetString("blue_outline", GetString("quest_reward_txt")), 70, 20),
                    CreateOndineText(20, LightBlueText, kCenter, 39, "#"..GetString("blue_outline", GetString("quest_reward_txt")), 70, 20),
                    
                    BitmapVisual
                    {
                        name = "reward_s_1",
                        x = 82,
                        y = 105,
                        w = 90,
                        h = 90,
                        image = "game/garden_1/camomile/stem_02",
                    },
                },
                
                BitmapVisual
                {
                    name = "reward_double",
                    x = 460,
                    y = 291,
                    image = "interface/game/pnl_quest_mirror/reward_2",
                    
                    SetStyle(TextStyle),
                    CreateOndineText(20, BlueOutline, kCenter+1, 40, "#"..GetString("blue_outline", GetString("quest_reward_txt")), 70, 20),
                    CreateOndineText(20, LightBlueText, kCenter, 39, "#"..GetString("blue_outline", GetString("quest_reward_txt")), 70, 20),
                    
                    BitmapVisual
                    {
                        name = "reward_d_1",
                        x = 70,
                        y = 105,
                        w = 90,
                        h = 90,
                        image = "game/garden_1/camomile/stem_03",
                    },
                    
                    BitmapVisual
                    {
                        name = "reward_d_2",
                        x = 135,
                        y = 105,
                        w = 90,
                        h = 90,
                        image = "game/garden_1/fountain/icon_restored",
                    },
                },
                
                Window
                {
                    name = "quest_text",
                    x = 75, y = 35,
                    w = 260, h = 300,
                    
                    SetStyle(TextStyle),
                    
                    CreateOndineNamedText(40, BlueOutline, kCenter+1, 11, "#"..GetString("blue_outline", GetString("info_quest")), 120, 40, "m_quest_caption_sh"),
                    CreateOndineNamedText(40, LightBlueText, kCenter, 10, "#"..GetString("blue_outline", GetString("info_quest")), 120, 40, "m_quest_caption"),
                    CreateOndineNamedText(40, BlueOutline, kCenter+1, 11, "#"..GetString("blue_outline", GetString("gate_quest")), 220, 40, "m_g_quest_caption_sh"),
                    CreateOndineNamedText(40, LightBlueText, kCenter, 10, "#"..GetString("blue_outline", GetString("gate_quest")), 220, 40, "m_g_quest_caption"),
                    
                    CreateLucidaNamedText(22, BlackColor, 0, 45, "stub", 250, 200, "msg_body"),
                    
                    TextVisual
                    {
                        -- Show always deadline on current quest
                        -- Please complete in 2 days still remaining
                        font = CreateNamedFont(MinionSbItSymbolSet, 18, ButtonBrown),
                        flags = kVAlignCenter + kHAlignLeft,
                        x = 0,
                        y = 260,
                        w = 260,
                        h = 20,
                        name = "msg_expert",
                        context = {"quest_deadline",},
                        context_change = function(item, old_val, new_val)
                            if new_val ~= 0 then
                                if new_val ~= 1 then
                                    msg_expert_SetText(GetString("mirror_expert_info", tostring(new_val)));
                                else
                                    msg_expert_SetText(GetString("mirror_expert_info_1day"));
                                end;
                                EnableWindow("pic_small_expert_badge", true);
                                EnableWindow("msg_expert", true);
                            else
                                EnableWindow("pic_small_expert_badge", false);
                                EnableWindow("msg_expert", false);
                            end;
                        end;
                    },
                    Bitmap
                    {
                        name = "pic_small_expert_badge",
                        x = 215,
                        y = 247,
                        image = "interface/game/pnl_quest_mirror/expert_mirror_small",
                    },
                },
                Window
                {
                    -- Achieved expert
                    -- You have completed this quest in 2 days, Expert!
                    name = "quest_expert_achieved",
                    x = 75, y = 35,
                    w = 260, h = 300,
                    
                    SetStyle(TextStyle),
                    
                    CreateOndineText(40, BlueOutline, kCenter+1, 11, "#"..GetString("blue_outline", GetString("title_congratulations")), 260, 40),
                    CreateOndineText(40, LightBlueText, kCenter, 10, "#"..GetString("blue_outline", GetString("title_congratulations")), 260, 40),
                    
                    Bitmap
                    {
                        x = kCenter+20,
                        y = kCenter+25,
                        image = "interface/game/pnl_quest_mirror/expert_mirror_big",
                    },
                    SetStyle(TextStyle),
                    
                    CreateMinionText(30, CaptionBrown, kCenter+1, 221, "#"..GetString("caption_outline", GetString("txt_expert")), 260, 30),
                    CreateMinionText(30, CaptionYellow, kCenter, 220, "#"..GetString("caption_outline", GetString("txt_expert")), 260, 30),
                    
                    CreateMinionNamedText(18, ButtonBrown, 0, 260, "expert_achieved", 260, 20, "msg_expert_achieved"),
                },
                Window
                {
                    -- Failed to achieve expert
                    -- You have completed in 20 days
                    -- You shold complete in 10 days
                    name = "quest_expert_fail",
                    x = 75, y = 35,
                    w = 260, h = 300,
                    
                    Bitmap
                    {
                        x = kCenter,
                        y = 60,
                        image = "interface/game/pnl_quest_mirror/expert_silver",
                    },
                    SetStyle(TextStyle),
                    CreateOndineText(40, BlueOutline, kCenter+1, 11, "#"..GetString("blue_outline", GetString("title_congratulations")), 260, 40),
                    CreateOndineText(40, LightBlueText, kCenter, 10, "#"..GetString("blue_outline", GetString("title_congratulations")), 260, 40),

                    SetStyle(TextStyle),
                    CreateLucidaNamedText(22, BlackColor, kCenter, 150, "expert_fail", 200, 44, "msg_expert_fail"),
                    
                    CreateMinionNamedText(18, ButtonBrown, kCenter, 240, "expert_fail_cheer", 200, 36, "msg_expert_fail_cheer"),
                },

                -- LAMP FX
                WndFxSprite
                {
                    name = "right_lamp_firebugs_fx",
                    x = 552,
                    y = 80,
                    w = 100,
                    h = 100,
                    effect_position = "50,50",
                    file_name = "fx/lamp_firebugs.lua",
                    start_activate = true,
                    advance = 5000,
                    timer_settings = {
                        name = "control",
                        category = "control",
                    },
                },
                WndFxSprite
                {
                    name = "right_lamp_light_fx",
                    x = 552,
                    y = 80,
                    w = 100,
                    h = 100,
                    effect_position = "50,50",
                    file_name = "fx/lamp_light.lua",
                    start_activate = true,
                    advance = 5000,
                    timer_settings = {
                        name = "control",
                        category = "control",
                    },
                },

                -- REQUEST

                SetStyle(TextStyle),
                CreateOndineText(20, BlueOutline, 417, 68, "#"..GetString("blue_outline", GetString("txt_goal")), 70, 20),
                CreateOndineText(20, LightBlueText, 416, 67, "#"..GetString("blue_outline", GetString("txt_goal")), 70, 20),
                    
                CreateMinionNamedText(20, BlackColor, 416, 165, "stub", 70, 20, "quest_item_count"),
                
                SetStyle(BtnQuestMirror),
                ButtonExt
                {
                    label = "accept_quest_msg",
                    name = "accept_quest",
                    x = 205,
                    y = 355,
    
                    timer_settings = timer_quest_mirror,
                    font = CreateNamedFont(MinionSbItSymbolSet, 24, ButtonBrown),
                    command = function()
                        if (GetCount("hint_accept_quest") == 1) then
                            SetItemCount("hint_accept_quest", 2);
                        end;
                        
                        SetAllowQuestInfo(true);
                        
                        AcceptQuest();
                        ProcessQuestAvailability();
                        
                        EnableWindow("msg_expert", true);
                        EnableWindow("quest_counter", true);
                        EnableWindow("info_expert_reminder", true);
                        EnableWindow("scroll", true);
                        EnableWindow("pic_small_expert_badge", true);
                    end;
                },
                ButtonExt
                {
                    label = "next_quest_msg",
                    name = "next_quest",
                    x = 205,
                    y = 355,
                    timer_settings = timer_quest_mirror,
                    font = CreateNamedFont(MinionSbItSymbolSet, 24, ButtonBrown),
                    command = function()
                        NextQuest();
                        EnableWindow("next_quest", false);
                    end;
                },
                ButtonExt
                {
                    label = "complete_quest_msg",
                    name = "complete_quest",
                    x = 135,
                    y = 355,
    
                    timer_settings = timer_quest_mirror,
                    font = CreateNamedFont(MinionSbItSymbolSet, 24, ButtonBrown),
                    command = function()
                        SetAllowQuestInfo(false);
                        EnableWindow("msg_expert", false);
                        EnableWindow("pic_small_expert_badge", false);
                        CompleteQuest();
                        ProcessQuestAvailability();
                        
                        EnableWindow("quest_counter", false);
                        EnableWindow("info_expert_reminder", false);
                        EnableWindow("scroll", false);
                        EnableWindow("pic_small_expert_badge", false);
                    end;
                },
                -- CLOSE
                ButtonExt
                {
                    x = 205,
                    y = 355,
                    close = true,
                    label = "close",
                    name = "close_mirror",
                    font = CreateNamedFont(MinionSbItSymbolSet, 24, ButtonBrown),
                    command = function()
                        HideControl("quest_mirror_dlg");
                    end;
                },
            },
            BitmapVisual
            {
                image="interface/game/pnl_quest_mirror/mirror",
                x=243,
                y=350,
                rotation_val=-12,
                
                WndFxSprite
                {
                    x = kCenter-20,
                    y = kCenter-70,
                    w = 200,
                    h = 200,
                    effect_position = "100,100",
                    file_name = "fx/quest_mirror_portal.lua",
                    start_activate = true,
                    advance = 100,
                    timer_settings = timer_quest_mirror,
                    
                    BitmapVisual
                    {
                        x = 105,
                        y = 105,
                        image = "interface/game/pnl_quest_mirror/btn_person_2/p_02",
                        scale_val = 0.6,
                        rotation_val=-12,
                    },
                },
            },
        },
    };
end;