-- -------------------------------------------------------------------
-- Edit the conditions to dictate when a certain layout is displayed.
function main()
    local termHeight, termWidth = go_getTermSize()

	if termWidth > 120 and termHeight > 25 then
        long_layout(termHeight, termWidth)
        return
	--	 remember to change last number to 30
    elseif termWidth > 55 and termHeight > 20 then
        short_layout(termHeight, termWidth)
        return
    elseif termWidth > 30 and termHeight > 20 then
        small_layout(termHeight, termWidth)
        return
    else
        go_print("Terminal too small: Panic")
        return
    end
end

-- -------------------------------------------------------------------



CONFIG_PATH = go_getConfigPath()
LOGO_PATH = CONFIG_PATH .. "/logos.toml"
EXTRA_PATH = CONFIG_PATH .. "/extra.toml"


function short_layout(termHeight, termWidth)

    -- ENDVR logo
    local logo, logoHeight, logoWidth = go_getLogo(EXTRA_PATH, "short")
    -- Mew art
    local art, artHeight, artWidth = go_getLogo(LOGO_PATH, "short")

    local header = go_colorize(4, string.rep("-", termWidth-2))

    local lineUnderLogo = go_colorize(5, string.rep("-", logoWidth+logoWidth/10))
    local msg = "Be Careful: They're Watching"

    local infoLine1 = go_colorize(1, "■  Kernel: ") .. go_getHostInfo("os") .. " | " .. go_getHostInfo("kernel")
    local infoLine2 = go_colorize(2, "■  CPU: ") .. "Pentium(R) (2) E6700 @ 3.20G"
    local infoLine3 = go_colorize(3, "■  DISK: ") .. go_getDisk(105, 97, 210)
    local infoLine4 = go_colorize(4, "■  SWAP: ") .. go_getSwap(105, 97, 210)
    local infoLine5 = go_colorize(5, "■  RAM: ") .. go_getRam(105, 97, 210)
    local infoLine6 = go_colorize(6, "■  UPTIME: ") .. go_getHostInfo("uptime")

    -- What gets shown
    go_print(go_centerString(termWidth, go_len(header), header))
    go_print(go_appendHorizontal(art, go_centerString(termWidth-artWidth, logoWidth, logo), 1, 1))
    go_print(go_appendHorizontal(art, go_centerString(termWidth-artWidth, logoWidth, logo), 2, 2))
    go_print(go_appendHorizontal(art, go_centerString(termWidth-artWidth, logoWidth, logo), 3, 3))
    go_print(go_appendHorizontal(art, go_centerString(termWidth-artWidth, logoWidth, logo), 4, 4))
    go_print(go_appendHorizontal(art, go_centerString(termWidth-artWidth, logoWidth, logo), 5, 5))
    go_print(go_appendHorizontal(art, go_centerString(termWidth-artWidth, logoWidth, logo), 6, 6))
    go_print(go_appendHorizontal(art, go_centerString(termWidth-artWidth, go_len(lineUnderLogo), lineUnderLogo), 7, 1))
    go_print(go_appendHorizontal(art, go_centerString(termWidth-artWidth, go_len(msg), go_colorize(2, msg)), 8, 1))
    go_print(go_appendHorizontal(art, go_centerString(termWidth-artWidth, go_len(lineUnderLogo), lineUnderLogo), 9, 1))
    -- I want the color block inline with the logo, so i use logoWidth
    go_print(go_appendHorizontal(art, go_centerString(termWidth-artWidth, logoWidth, infoLine1), 10, 1))
    go_print(go_appendHorizontal(art, go_centerString(termWidth-artWidth, logoWidth, infoLine2), 11, 1))
    go_print(go_appendHorizontal(art, go_centerString(termWidth-artWidth, logoWidth, infoLine3), 12, 1))
    go_print(go_appendHorizontal(art, go_centerString(termWidth-artWidth, logoWidth, infoLine4), 13, 1))
    go_print(go_appendHorizontal(art, go_centerString(termWidth-artWidth, logoWidth, infoLine5), 14, 1))
    go_print(go_appendHorizontal(art, go_centerString(termWidth-artWidth, logoWidth, infoLine6), 15, 1))
    go_print(go_centerString(termWidth, go_len(header), header))
end


function long_layout(termHeight, termWidth)
    -- ENDEAVOUROS logo
    local logo, logoHeight, logoWidth = go_getLogo(EXTRA_PATH, "long")
    -- Pika art
    local art, artHeight, artWidth = go_getLogo(LOGO_PATH, "long")

    local header = go_colorize(4, string.rep("-", logoWidth+artWidth+8))
    local verticalSeperator = go_colorize(4, " | ")

    local line1 = go_appendHorizontal(logo, verticalSeperator, 1, 1)
    local line1 = go_appendHorizontal(line1, art, 1, 1)
    local line2 = go_appendHorizontal(logo, verticalSeperator, 2, 1)
    local line2 = go_appendHorizontal(line2, art, 1, 2)
    local line3 = go_appendHorizontal(logo, verticalSeperator, 3, 1)
    local line3 = go_appendHorizontal(line3, art, 1, 3)
    local line4 = go_appendHorizontal(logo, verticalSeperator, 4, 1)
    local line4 = go_appendHorizontal(line4, art, 1, 4)
    local line5 = go_appendHorizontal(logo, verticalSeperator, 5, 1)
    local line5 = go_appendHorizontal(line5, art, 1, 5)
    local line6 = go_appendHorizontal(logo, verticalSeperator, 6, 1)
    local line6 = go_appendHorizontal(line6, art, 1, 6)

    local seperator = go_colorize(4, string.rep("-", logoWidth) .. " | ")
    local line7 = go_appendHorizontal(seperator, art, 1, 7)

    -- swap is the longest line in the right column
    -- I use it to make everything else in line with it, hence why it is defined earlier than its numerical order
    local disk = go_colorize(3, "■  DISK: ") .. go_getDisk(105, 97, 210)
    local swap = go_colorize(4, "■  SWAP: ") .. go_getSwap(105, 97, 210)
    local infoForLine10 = disk .. string.rep(" ", (logoWidth-go_len(disk)-go_len(swap))) .. swap
    local line10 =  infoForLine10 .. verticalSeperator
    local line10 = go_appendHorizontal(line10, art, 1, 10)

    local kernel = go_colorize(1, "■  Kernel: ") .. go_getHostInfo("os") .. " | " .. go_getHostInfo("kernel")
    local uptime = go_colorize(2, "■  UPTIME: ") .. go_getHostInfo("uptime")
    local infoForLine8 = kernel .. string.rep(" ", (logoWidth-go_len(kernel)-go_len(swap))) .. uptime
    local line8 =  infoForLine8 .. string.rep(" ", (logoWidth-go_len(infoForLine8))) .. verticalSeperator
    local line8 = go_appendHorizontal(line8, art, 1, 8)

    
    local cpu = go_colorize(5, "■  CPU: ") .. "Pentium(R) (2) E6700 @ 3.20G"
    local monitor = go_colorize(6, "■  MONITOR: ") .. go_getMonitorResolution() .. "@ 60Hz"
    local infoForLine9 = cpu .. string.rep(" ", (logoWidth-go_len(cpu)-go_len(swap))) .. monitor
    local line9 =  infoForLine9 .. string.rep(" ", (logoWidth-go_len(infoForLine9))) .. verticalSeperator
    local line9 = go_appendHorizontal(line9, art, 1, 9)



    local ram = go_colorize(7, "■  RAM: ") .. go_getRam(105, 97, 210)
    local msg = go_colorize(8, "■  SITE STATUS: ") .. "Secure" 
    local infoForLine11 = ram .. string.rep(" ", (logoWidth-go_len(ram)-go_len(swap))) .. msg
    local line11 =  infoForLine11 .. string.rep(" ", (logoWidth-go_len(infoForLine11))) .. verticalSeperator
    local line11 = go_appendHorizontal(line11, art, 1, 11)

    go_print(go_centerString(termWidth, go_len(header), header))
    go_print(go_centerString(termWidth, go_len(line1)+11, line1))
    go_print(go_centerString(termWidth, go_len(line2)+11, line2))
    go_print(go_centerString(termWidth, go_len(line3)+11, line3))
    go_print(go_centerString(termWidth, go_len(line4)+11, line4))
    go_print(go_centerString(termWidth, go_len(line5)+11, line5))
    go_print(go_centerString(termWidth, go_len(line6)+11, line6))
    go_print(go_centerString(termWidth, go_len(line7)+11, line7))
    go_print(go_centerString(termWidth, go_len(line8)+11, line8))
    go_print(go_centerString(termWidth, go_len(line9)+11, line9))
    go_print(go_centerString(termWidth, go_len(line10)+11, line10))
    go_print(go_centerString(termWidth, go_len(line11)+11, line11))
    go_print(go_centerString(termWidth, go_len(header), header))

end


function small_layout(termHeight, termWidth)

    -- Arch Logo
    local logo, logoHeight, logoWidth = go_getLogo(LOGO_PATH, "small")

    local header = go_colorize(4, string.rep("-", termWidth-2))

    local endeavouros = go_colorize(210, "E") .. go_colorize(97, " N D E A V O U R O ") .. go_colorize(105, "S")
    local endeavouros = go_centerString(termWidth-logoWidth+5, go_len(endeavouros), endeavouros)

	-- My terminal counts "■" as 2 spaces, hence why shape width is 2.
	local swatchWidth, swatch = go_getColorSwatch(15, 1, "■", 2, 0)

    local kernel = go_colorize(1, "■  Kernel: ") .. go_getHostInfo("kernel")
    local ram = go_colorize(2, "■  RAM: ") .. string.sub(go_getRam(105, 97, 210), 1, -25)
    local uptime = go_colorize(3, "■  UP: ") .. string.sub(go_getHostInfo("uptime"), 1, -10)
    local swap = go_colorize(4, "■  SWAP: ") .. string.sub(go_getSwap(105, 97, 210), 1, -25)
    local monitor = go_colorize(5, "■  MONITOR: ") .. go_getMonitorResolution() .. " 60Hz"

    go_print(go_centerString(termWidth, go_len(header), header))
    go_print(go_appendHorizontal(logo, endeavouros, 1, 1))
    go_print(go_appendHorizontal(logo, swatch, 2, 1))
    go_print(go_appendHorizontal(logo, kernel, 3, 1))
    go_print(go_appendHorizontal(logo, ram, 4, 1))
    go_print(go_appendHorizontal(logo, uptime, 5, 1))
    go_print(go_appendHorizontal(logo, swap, 6, 1))
    go_print(go_appendHorizontal(logo, monitor, 7, 1))
    go_print(go_centerString(termWidth, go_len(header), header))

end
