-- This file is part of AutoInvite
--
-- (C) 2014 Scott Yeskie (Sasky)
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 2 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program.  If not, see <http://www.gnu.org/licenses/>.

AutoInviteUI = AutoInviteUI or {}
local ui = AutoInviteUI
local wm = WINDOW_MANAGER

function AutoInviteUI:CreateOptionFragment()
    ui.main = wm:CreateTopLevelWindow("AutoInviteOptionsFragment")
    ui.main:SetAnchor(TOPRIGHT, ZO_GroupList, TOPRIGHT, -40, 60)
    ui.main:SetHidden(true)
    ui.scroll = ui.main -- For using LAM controls
    ui.data = {}

    ui.refreshList = wm:CreateControlFromVirtual(nil, ui.main, "ZO_DefaultButton")
    ui.refreshList:SetAnchor(TOPRIGHT, ui.main, TOPRIGHT, -365, 5)
    ui.refreshList:SetWidth(160)
    ui.refreshList:SetText(GetString(SI_AUTO_INVITE_BTN_REFRESH))
    ui.refreshList:SetHandler("OnClicked", function() MINI_GROUP_LIST:RefreshData() end)

    ui.max = LAMCreateControl.slider(ui, {
        type = "slider",
        name = GetString(SI_AUTO_INVITE_OPT_MAX_SIZE),
        tooltip = GetString(SI_AUTO_INVITE_TT_MAX_SIZE),
        min = 4,
        max = 24,
        getFunc = function() return AutoInvite.cfg.maxSize end,
        setFunc = function(val) AutoInvite.cfg.maxSize = val end,
        default = 24,
        --width = "half"
    })
    ui.max:SetAnchor(TOPRIGHT, ui.main, TOPRIGHT, 0, 55)

    ui.restart = LAMCreateControl.checkbox(ui, {
        type = "checkbox",
        name = GetString(SI_AUTO_INVITE_OPT_RESTART),
        tooltip = GetString(SI_AUTO_INVITE_TT_RESTART),
        getFunc = function() return AutoInvite.cfg.restart end,
        setFunc = function(val) AutoInvite.cfg.restart = val  end,
        --width = "half"
    })
    ui.restart:SetAnchor(TOPLEFT, ui.max, BOTTOMLEFT, 0, 25)

    ui.cyr = LAMCreateControl.checkbox(ui, {
        type = "checkbox",
        name = GetString(SI_AUTO_INVITE_OPT_CYRCHECK),
        tooltip = GetString(SI_AUTO_INVITE_TT_CYRCHECK),
        getFunc = function() return AutoInvite.cfg.cyrCheck end,
        setFunc = function(val) AutoInvite.cfg.cyrCheck = val end,
        --width = "half"
    })
    ui.cyr:SetAnchor(TOPLEFT, ui.restart, BOTTOMLEFT, 0, 25)

    ui.kick = LAMCreateControl.checkbox(ui, {
        type = "checkbox",
        name = GetString(SI_AUTO_INVITE_OPT_KICK),
        tooltip = GetString(SI_AUTO_INVITE_TT_KICK),
        getFunc = function() return AutoInvite.cfg.autoKick end,
        setFunc = function(val) AutoInvite.cfg.autoKick = val  end,
        --width = "half"
    })
    ui.kick:SetAnchor(TOPLEFT, ui.cyr, BOTTOMLEFT, 0, 25)

    ui.kickTime = LAMCreateControl.slider(ui, {
        type = "slider",
        name = GetString(SI_AUTO_INVITE_OPT_KICK_TIME),
        tooltip = GetString(SI_AUTO_INVITE_TT_KICK_TIME),
        min = 5,
        max = 600,
        getFunc = function() return AutoInvite.cfg.kickDelay end,
        setFunc = function(val) AutoInvite.cfg.kickDelay = val end,
        default = 300,
        --width = "half"
    })
    ui.kickTime:SetAnchor(TOPLEFT, ui.kick, BOTTOMLEFT, 0, 25)

    ui.regroup = wm:CreateControlFromVirtual(nil, ui.main, "ZO_DefaultButton")
    ui.regroup:SetAnchor(TOPLEFT, ui.kickTime, BOTTOMLEFT, 70, 70)
    ui.regroup:SetWidth(160)
    ui.regroup:SetText(GetString(SI_AUTO_INVITE_BTN_REFORM))
    ui.regroup:SetHandler("OnClicked", function() AutoInvite:resetGroup() end)

    local slashcmds = GetString(SI_AUTO_INVITE_SLASHCMD_START) ..
            "\n" .. GetString(SI_AUTO_INVITE_SLASHCMD_HELP) ..
            "\n" .. GetString(SI_AUTO_INVITE_SLASHCMD_STOP)
    ui.note = LAMCreateControl.description(ui, {
        type = "description",
        title = GetString(SI_AUTO_INVITE_OPT_SLASHCMD),
        text = slashcmds,
    })
    ui.note:SetAnchor(BOTTOMRIGHT, ZO_GroupList, BOTTOMRIGHT, -40, -40)
    ui.note.desc:SetColor(.7,.7,.7,1)

    AUTO_INVITE_OPTIONS_FRAGMENT = ZO_FadeSceneFragment:New(ui.main)
end