-- Shared code for including icons
-- Icons definitions for custom widgets
local beautiful = require("beautiful")
local beautiful_assets = require("beautiful").theme_assets
local gears = require("gears")
function beautiful.recolor_icon_group(tbl,write_to,regex,color)
    for k,v in pairs(tbl) do
        if k:match(regex) then
            write_to[k] = gears.color.recolor_image(v,color)
        end
    end
end
global.themes_dir = global.themes_dir or (os.getenv("HOME").."/.config/awesome/themes/")
return function(theme)
    local temp = {}
    -- Define dir to icons
    theme.icon_dir = theme.icon_dir or global.themes_dir..theme.name.."/icons/"
    -- Powermenu icons
    temp.powercontrol_icon_shutdown = theme.icon_dir.."shutdown.svg"
    temp.powercontrol_icon_suspend = theme.icon_dir.."suspend.svg"
    temp.powercontrol_icon_lock = theme.icon_dir.."lock.svg"
    beautiful.recolor_icon_group(temp,theme,"^powercontrol_.+",theme.fg_normal)

    -- Volume icons
    temp.volume_icon_high = theme.icon_dir.."volume-high.svg"
    temp.volume_icon_medium = theme.icon_dir.."volume-medium.svg"
    temp.volume_icon_low = theme.icon_dir.."volume-low.svg"
    temp.volume_icon_muted = theme.icon_dir.."volume-muted.svg"
    beautiful.recolor_icon_group(temp,theme,"^volume_.+",theme.fg_normal)
    
    -- Battery icons
    temp.battery_caution_charging_symbolic = theme.icon_dir.."battery-caution-charging-symbolic.svg"
    temp.battery_caution_symbolic = theme.icon_dir.."battery-caution-symbolic.svg"
    temp.battery_empty_charging_symbolic = theme.icon_dir.."battery-empty-charging-symbolic.svg"
    temp.battery_empty_symbolic = theme.icon_dir.."battery-empty-symbolic.svg"
    temp.battery_full_charged_symbolic = theme.icon_dir.."battery-full-charged-symbolic.svg"
    temp.battery_full_charging_symbolic = theme.icon_dir.."battery-full-charging-symbolic.svg"
    temp.battery_full_symbolic = theme.icon_dir.."battery-full-symbolic.svg"
    temp.battery_good_charging_symbolic = theme.icon_dir.."battery-good-charging-symbolic.svg"
    temp.battery_good_symbolic = theme.icon_dir.."battery-good-symbolic.svg"
    temp.battery_low_charging_symbolic = theme.icon_dir.."battery-low-charging-symbolic.svg"
    temp.battery_low_symbolic = theme.icon_dir.."battery-low-symbolic.svg"
    temp.battery_missing_symbolic = theme.icon_dir.."battery-missing-symbolic.svg"
    beautiful.recolor_icon_group(temp,theme,"^battery_.+",theme.fg_normal)
    
    -- Widget icons
    theme.wallpapers_icon = gears.color.recolor_image(theme.icon_dir.."wallpaper.svg",theme.fg_normal)
    theme.mailbox_icon = gears.color.recolor_image(theme.icon_dir.."mail.svg",theme.fg_normal)
    theme.username_logout_icon = gears.color.recolor_image(theme.icon_dir.."system-log-out-symbolic.svg",theme.fg_normal)
    theme.drawer_open_icon = gears.color.recolor_image(theme.icon_dir.."drawer-open.svg",theme.fg_normal)
    theme.drawer_closed_icon = gears.color.recolor_image(theme.icon_dir.."drawer-closed.svg",theme.fg_normal)
    
    -- Generic icons
    theme.warning_icon = gears.color.recolor_image(theme.icon_dir.."warning.svg",theme.fg_normal)
    
    -- Fallback application icon
    theme.fallback_icon = gears.surface(theme.icon_dir.."fallback-application.svg")

    return theme
end
