local gl = require('galaxyline')
local gls = gl.section
local condition = require('galaxyline.condition')

gl.short_line_list = {'NvimTree', 'packer', 'Outline'}

local colors = require('colors.' .. vim.g.global_theme).colors

gls.left[1] = {
    LeftCorner = {
        provider = function()
            return '▊ '
        end,
        highlight = {colors.blue, colors.grey1}
    }
}

gls.left[2] = {
    ViMode = {
        provider = function()
            local mode_color = {
                n      = colors.green,  -- Normal
                no     = colors.green,  -- N-Pending
                i      = colors.blue,   -- Insert
                ic     = colors.blue,   -- Insert
                v      = colors.yellow, -- Visual
                [''] = colors.yellow, -- V-Block
                V      = colors.yellow, -- V-Line
                c      = colors.white2, -- Command
                s      = colors.purple, -- Select
                S      = colors.purple, -- S-Line
                [''] = colors.purple, -- S-Block
                R      = colors.red,    -- Replace
                Rv     = colors.red,    -- V-Replace
                cv     = colors.white2, -- Vim-Ex
                ce     = colors.white2, -- Ex
                r      = colors.cyan,   -- Prompt
                rm     = colors.cyan,   -- More
                ['r?'] = colors.cyan,   -- Confirm
                ['!']  = colors.orange, -- Shell
                t      = colors.orange  -- Terminal
            }
            vim.api.nvim_command('hi GalaxyViMode guifg=' .. mode_color[vim.fn.mode()])
            return '  '
        end,
        highlight = {colors.green, colors.grey1}
    }
}

gls.left[3] = {
    FileSize = {
        provider = 'FileSize',
        condition = condition.buffer_not_empty,
        highlight = {colors.fg, colors.grey1}
    }
}

gls.left[4] ={
    FileIcon = {
        provider = 'FileIcon',
        condition = condition.buffer_not_empty,
        highlight = {
            require('galaxyline.provider_fileinfo').get_file_icon_color,
            colors.grey1
        }
    }
}

gls.left[5] = {
    FileName = {
        provider = 'FileName',
        condition = condition.buffer_not_empty,
        highlight = {colors.fg, colors.grey1, 'bold'}
    }
}

gls.left[6] = {
    LineInfo = {
        provider = 'LineColumn',
        highlight = {colors.fg, colors.grey1}
    }
}

gls.left[7] = {
    PerCent = {
        provider = 'LinePercent',
        highlight = {colors.fg, colors.grey1, 'bold'}
    }
}

gls.left[8] = {
    DiagnosticError = {
        provider = 'DiagnosticError',
        icon = '  ',
        highlight = {colors.red, colors.grey1}
    }
}

gls.left[9] = {
    DiagnosticWarn = {
        provider = 'DiagnosticWarn',
        icon = '  ',
        highlight = {colors.yellow, colors.grey1}
    }
}

gls.left[10] = {
  DiagnosticHint = {
    provider = 'DiagnosticHint',
    icon = '  ',
    highlight = {colors.cyan, colors.grey1}
  }
}

gls.left[11] = {
    DiagnosticInfo = {
        provider = 'DiagnosticInfo',
        icon = '  ',
        highlight = {colors.blue, colors.grey1}
    }
}

gls.right[1] = {
    ShowLspClient = {
        provider = 'GetLspClient',
        condition = function ()
            local tbl = {['dashboard'] = true, [''] = true}
            if tbl[vim.bo.filetype] then
                return false
            end
            return true
        end,
        icon = '  LSP:',
        highlight = {colors.purple, colors.grey1, 'bold'}
    }
}

gls.right[2] = {
    FileEncode = {
        provider = 'FileEncode',
        condition = condition.hide_in_width,
        separator = ' ',
        separator_highlight = {'NONE', colors.grey1},
        highlight = {colors.fg, colors.grey1}
    }
}

gls.right[3] = {
    FileFormat = {
        provider = 'FileFormat',
        condition = condition.hide_in_width,
        separator = ' ',
        separator_highlight = {'NONE', colors.grey1},
        highlight = {colors.fg, colors.grey1}
    }
}

gls.right[4] = {
    GitIcon = {
        provider = function() return '  ' end,
        condition = condition.check_git_workspace,
        separator = ' ',
        separator_highlight = {'NONE', colors.grey1},
        highlight = {colors.green, colors.grey1, 'bold'}
    }
}

gls.right[5] = {
    GitBranch = {
        provider = 'GitBranch',
        condition = condition.check_git_workspace,
        highlight = {colors.green, colors.grey1, 'bold'}
    }
}

gls.right[6] = {
    GitSeparator = {
        provider = function()
            return ' '
        end,
        highlight = {colors.green, colors.grey1}
    }
}

gls.right[7] = {
    DiffAdd = {
        provider = 'DiffAdd',
        condition = condition.hide_in_width,
        icon = ' ',
        highlight = {colors.green, colors.grey1}
    }
}

gls.right[8] = {
    DiffModified = {
        provider = 'DiffModified',
        condition = condition.hide_in_width,
        icon = '柳',
        highlight = {colors.yellow, colors.grey1}
    }
}

gls.right[9] = {
    DiffRemove = {
        provider = 'DiffRemove',
        condition = condition.hide_in_width,
        icon = ' ',
        highlight = {colors.red, colors.grey1}
    }
}

gls.short_line_left[1] = {
    BufferType = {
        provider = 'FileTypeName',
        separator = ' ',
        separator_highlight = {'NONE', colors.grey1},
        highlight = {colors.blue, colors.grey1, 'bold'}
    }
}

gls.short_line_left[2] = {
    SFileName = {
        provider = 'SFileName',
        condition = condition.buffer_not_empty,
        highlight = {colors.fg, colors.grey1, 'bold'}
    }
}

gls.short_line_right[1] = {
    BufferIcon = {
        provider= 'BufferIcon',
        highlight = {colors.fg, colors.grey1}
    }
}
