local wibox = require("wibox")
local awful = require("awful")
local gears = require("gears")
local beautiful = require("beautiful")

local awmtk = {}

-- {{{ Utils
awmtk.create_class = function(name,overrides,style,parent_class) 
    return setmetatable(overrides,{
        __index = function(self,k)
            -- Per-widget overrides are top priority
            if rawget(self,k) then
                return rawget(self,k)
            -- Style overrides are second in priority
            elseif type(style[name]) == "table" and rawget(style[name],k) then
                return rawget(style[name],k)
            -- Parent class is fallback
            elseif parent_class[k] then
                return parent_class[k]
            end
        end
    })
end

awmtk.create_style = function(style_name,parent,overrides)
    local new_style = {}
    for name,parent_class in pairs(parent) do 
        new_style[name] = awmtk.create_class(
            name,
            (overrides and overrides[name]) or {},
            (beautiful[style_name] or {}),
            parent_class
        )
    end
    return new_style
end 

-- }}}


-- {{{ Default style

-- Default style
awmtk.default = {
    base = setmetatable({
        -- { Backgrounds
        -- custom background color for highlighting elements
        bg_highlight = beautiful.bg_highlight or beautiful.bg_focus,
        -- }
        -- { Borders
        -- Borders for popups
        shape_border_width = beautiful.shape_border_width or 0,
        shape_border_color = beautiful.shape_border_color or beautiful.bg_normal,
        -- }
        -- { Shapes
        inner_margin = beautiful.inner_margin or 5,
        rounding = beautiful.rounding or 0,
        -- }
    },{__index = beautiful})
}

-- Container subclass
awmtk.default.container = awmtk.create_class("container",{
},awmtk.default,awmtk.default.base)

-- Button subclass
awmtk.default.button = awmtk.create_class("button",{
    inner_margin = 1
},awmtk.default,awmtk.default.base)

-- Icon subclass
awmtk.default.icon = awmtk.create_class("icon",{
    inner_margin = 1
},awmtk.default,awmtk.default.base)

-- }}}

return awmtk
