<commit_before>local A, L = unpack(select(2, ...))
local M = A:NewModule("chooseGui")
A.chooseGui = M
M.private = {
  window = false,
  close = {},
  mockSession = false,
}
local R = M.private
local H, HA = A.util.Highlight, A.util.HighlightAddon

local format, gsub, ipairs, strlower, tinsert = format, gsub, ipairs, strlower, tinsert
local tconcat = table.concat
local CreateFrame, GameFontHighlight, GameTooltip, IsAddOnLoaded, IsControlKeyDown, IsShiftKeyDown, PlaySound, UIParent = CreateFrame, GameFontHighlight, GameTooltip, IsAddOnLoaded, IsControlKeyDown, IsShiftKeyDown, PlaySound, UIParent
local CLASS_SORT_ORDER, LOCALIZED_CLASS_NAMES_MALE = CLASS_SORT_ORDER, LOCALIZED_CLASS_NAMES_MALE
-- GLOBALS: ElvUI

local AceGUI = LibStub("AceGUI-3.0")

local function onCloseWindow(widget)
  R.window = false
  AceGUI:Release(widget)
end

function M:CloseWindow()
  if R.window then
		PlaySound("gsTitleOptionExit")
    R.window.frame:Hide()
  end
end

local function addPadding(frame)
  local padding = AceGUI:Create("Label")
  padding:SetText(" ")
  padding:SetFullWidth(true)
  frame:AddChild(padding)
  return padding
end

local function onLeaveButton(widget)
  GameTooltip:Hide()
  R.window:SetStatusText("")
end

local function getCommand(mode, modeType)
  return "/choose "..mode
end

local function addModeButton(frame, mode, modeType)
  local button = AceGUI:Create("Button")
  local label
  if mode == "option2" then
    mode = format("%s %s %s", L["letter.1"], L["word.or"], L["letter.2"])
    label = mode
  elseif mode == "option3+" then
    mode = format("%s, %s, %s", L["letter.1"], L["letter.2"], L["letter.3"])
    label = mode..", ..."
  else
    label = A.chooseCommand.MODE_ALIAS[mode].primary
    if modeType == "tierToken" then
      label = A.util:LocaleLowerNoun(label)
    end
  end
  button:SetText(label)
  button:SetCallback("OnClick", function(widget)
    if IsShiftKeyDown() then
      A.util:InsertText(getCommand(mode, modeType))
      return
    end
    A.chooseCommand:Command(mode)
    if IsControlKeyDown() then
      R.window:Hide()
    end
  end)
  button:SetCallback("OnEnter", function(widget)
    M:SetupTooltip(widget, mode, modeType)
  end)
  button:SetCallback("OnLeave", onLeaveButton)
  button:SetWidth(104)
  frame:AddChild(button)
  return button
end

local function addCloseButton()
  -- AceGUI puts the close button on the bottom right, which is fine.
  -- However for consistency's sake we also want an X in the upper right.
  local C = R.close
  local hasElvUI = IsAddOnLoaded("ElvUI") and ElvUI

  C.frame = C.frame or CreateFrame("FRAME")
  C.frame:SetParent(R.window.frame)
  C.frame:SetWidth(17)
  C.frame:SetHeight(40)
  C.frame:SetPoint("TOPRIGHT", hasElvUI and 0 or -16, 12)

  C.button = C.button or CreateFrame("BUTTON")
  C.button:SetParent(C.frame)
  C.button:SetWidth(30)
  C.button:SetHeight(30)
  C.button:SetPoint("CENTER", C.frame, "CENTER", 1, -1)
  C.button:SetNormalTexture("Interface\\BUTTONS\\UI-Panel-MinimizeButton-Up.blp")
  C.button:SetPushedTexture("Interface\\BUTTONS\\UI-Panel-MinimizeButton-Down.blp")
  C.button:SetHighlightTexture("Interface\\BUTTONS\\UI-Panel-MinimizeButton-Highlight.blp")
  C.button:SetScript("OnClick", M.CloseWindow)

  if hasElvUI then
    ElvUI[1]:GetModule("Skins"):HandleCloseButton(C.button)
  else
    C.borderTB = C.borderTB or C.frame:CreateTexture(nil, "BACKGROUND")
    C.borderTB:SetParent(C.frame)
    C.borderTB:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header")
    C.borderTB:SetTexCoord(0.31, 0.67, 0, 0.63)
    C.borderTB:SetAllPoints(C.frame)

    C.borderL = C.borderL or C.frame:CreateTexture(nil, "BACKGROUND")
    C.borderL:SetParent(C.frame)
    C.borderL:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header")
    C.borderL:SetTexCoord(0.235, 0.275, 0, 0.63)
    C.borderL:SetPoint("RIGHT", C.borderTB, "LEFT")
    C.borderL:SetWidth(10)
    C.borderL:SetHeight(40)

    C.borderR = C.borderR or C.frame:CreateTexture(nil, "BACKGROUND")
    C.borderR:SetParent(C.frame)
    C.borderR:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header")
    C.borderR:SetTexCoord(0.72, 0.76, 0, 0.63)
    C.borderR:SetPoint("LEFT", C.borderTB, "RIGHT")
    C.borderR:SetWidth(10)
    C.borderR:SetHeight(40)
  end
end

local function resetWindowSize()
  R.window:ClearAllPoints()
  R.window:SetPoint("CENTER", UIParent, "CENTER", 0, 0)
  R.window:SetWidth(700)
  R.window:SetHeight(569)
end

function M:Open()
  if A.DEBUG >= 1 then A.console:Debugf(M, "open") end
  if R.window then
    resetWindowSize()
    return<commit_msg>refactor<commit_after>local A, L = unpack(select(2, ...))
local M = A:NewModule("chooseGui")
A.chooseGui = M
M.private = {
  window = false,
  close = {},
  mockSession = false,
}
local R = M.private
local H, HA = A.util.Highlight, A.util.HighlightAddon

local format, gsub, ipairs, strlower, tinsert = format, gsub, ipairs, strlower, tinsert
local tconcat = table.concat
local CreateFrame, GameFontHighlight, GameTooltip, IsAddOnLoaded, IsControlKeyDown, IsShiftKeyDown, PlaySound, UIParent = CreateFrame, GameFontHighlight, GameTooltip, IsAddOnLoaded, IsControlKeyDown, IsShiftKeyDown, PlaySound, UIParent
local CLASS_SORT_ORDER, LOCALIZED_CLASS_NAMES_MALE = CLASS_SORT_ORDER, LOCALIZED_CLASS_NAMES_MALE
-- GLOBALS: ElvUI

local AceGUI = LibStub("AceGUI-3.0")

local function onCloseWindow(widget)
  R.window = false
  AceGUI:Release(widget)
end

local function addPadding(frame)
  local padding = AceGUI:Create("Label")
  padding:SetText(" ")
  padding:SetFullWidth(true)
  frame:AddChild(padding)
  return padding
end

local function onLeaveButton(widget)
  GameTooltip:Hide()
  R.window:SetStatusText("")
end

local function getCommand(mode, modeType)
  return "/choose "..mode
end

local function addModeButton(frame, mode, modeType)
  local button = AceGUI:Create("Button")
  local label
  if mode == "option2" then
    mode = format("%s %s %s", L["letter.1"], L["word.or"], L["letter.2"])
    label = mode
  elseif mode == "option3+" then
    mode = format("%s, %s, %s", L["letter.1"], L["letter.2"], L["letter.3"])
    label = mode..", ..."
  else
    label = A.chooseCommand.MODE_ALIAS[mode].primary
    if modeType == "tierToken" then
      label = A.util:LocaleLowerNoun(label)
    end
  end
  button:SetText(label)
  button:SetCallback("OnClick", function(widget)
    if IsShiftKeyDown() then
      A.util:InsertText(getCommand(mode, modeType))
      return
    end
    A.chooseCommand:Command(mode)
    if IsControlKeyDown() then
      R.window:Hide()
    end
  end)
  button:SetCallback("OnEnter", function(widget)
    M:SetupTooltip(widget, mode, modeType)
  end)
  button:SetCallback("OnLeave", onLeaveButton)
  button:SetWidth(104)
  frame:AddChild(button)
  return button
end

local function addCloseButton()
  -- AceGUI puts the close button on the bottom right, which is fine.
  -- However for consistency's sake we also want an X in the upper right.
  local C = R.close
  local hasElvUI = IsAddOnLoaded("ElvUI") and ElvUI

  C.frame = C.frame or CreateFrame("FRAME")
  C.frame:SetParent(R.window.frame)
  C.frame:SetWidth(17)
  C.frame:SetHeight(40)
  C.frame:SetPoint("TOPRIGHT", hasElvUI and 0 or -16, 12)

  C.button = C.button or CreateFrame("BUTTON")
  C.button:SetParent(C.frame)
  C.button:SetWidth(30)
  C.button:SetHeight(30)
  C.button:SetPoint("CENTER", C.frame, "CENTER", 1, -1)
  C.button:SetNormalTexture("Interface\\BUTTONS\\UI-Panel-MinimizeButton-Up.blp")
  C.button:SetPushedTexture("Interface\\BUTTONS\\UI-Panel-MinimizeButton-Down.blp")
  C.button:SetHighlightTexture("Interface\\BUTTONS\\UI-Panel-MinimizeButton-Highlight.blp")
  C.button:SetScript("OnClick", M.CloseWindow)

  if hasElvUI then
    ElvUI[1]:GetModule("Skins"):HandleCloseButton(C.button)
  else
    C.borderTB = C.borderTB or C.frame:CreateTexture(nil, "BACKGROUND")
    C.borderTB:SetParent(C.frame)
    C.borderTB:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header")
    C.borderTB:SetTexCoord(0.31, 0.67, 0, 0.63)
    C.borderTB:SetAllPoints(C.frame)

    C.borderL = C.borderL or C.frame:CreateTexture(nil, "BACKGROUND")
    C.borderL:SetParent(C.frame)
    C.borderL:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header")
    C.borderL:SetTexCoord(0.235, 0.275, 0, 0.63)
    C.borderL:SetPoint("RIGHT", C.borderTB, "LEFT")
    C.borderL:SetWidth(10)
    C.borderL:SetHeight(40)

    C.borderR = C.borderR or C.frame:CreateTexture(nil, "BACKGROUND")
    C.borderR:SetParent(C.frame)
    C.borderR:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header")
    C.borderR:SetTexCoord(0.72, 0.76, 0, 0.63)
    C.borderR:SetPoint("LEFT", C.borderTB, "RIGHT")
    C.borderR:SetWidth(10)
    C.borderR:SetHeight(40)
  end
end

local function resetWindowSize()
  R.window:ClearAllPoints()
  R.window:SetPoint("CENTER", UIParent, "CENTER", 0, 0)
  R.window:SetWidth(700)
  R.window:SetHeight(569)
end

function M:Close()
  if R.window then
		PlaySound("gsTitleOptionExit")
    R.window.frame:Hide()
  end
end

function M:Open()
  if A.DEBUG >= 1 then A.console:Debugf(M, "open") end
  if R.window then
    resetWindowSize()
    return
{'fraction_non_alphanumeric': 0.13838550247116968, 'fraction_numerical': 0.0171334431630972, 'mean_word_length': 4.482239614689946, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3671289', 'n_tokens_mistral': 3391, 'n_tokens_neox': 3250, 'n_words': 653}