--   This file is part of Reno desktop.
--
--  Reno desktop is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
--
--  Reno desktop is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
--
--  You should have received a copy of the GNU General Public License along with Reno desktop. If not, see <https://www.gnu.org/licenses/>. 
-- Base for widgets
local awmtk2 = require("awmtk2")
local wibox = require("wibox")
local gears = require("gears")
local awful = require("awful")
local beautiful = require("beautiful")

return function(args)
    local style = awmtk2.create_style("taglist",awmtk2.default,args.style)
    local templates = awmtk2.create_template_lib("taglist",awmtk2.templates,args.templates)
    local t = awmtk2.build_templates(templates,style)
    local widget = wibox.widget(t.container(awful.widget.taglist({
        screen = args.screen,
        filter = awful.widget.taglist.filter.all,
        style = {
            shape = style.button.shape
        },
        layout = {
            spacing = style.base.spacing,
            spacing_widget = style.base.spacing_widget,
            layout = style.base.layout or wibox.layout.fixed.horizontal
        },
        widget_template = t.button(t.article({
            icon_id = "icon_role",
            title_id = "text_role"
        }),{
            id = "background",
            create_callback = function(self, tag, index, tags)
                self:connect_signal("button::press",function(self,x,y,b)
                    if b == 1 then
                        awful.tag.viewmore({tag})
                    elseif b == 3 then
                        awful.tag.viewtoggle(tag)
                    end
                end)
                local bg = self:get_children_by_id("background")[1]
                if tag.selected then
                    bg.bgimage = style.button.bgimage_focus
                    bg.bg = style.button.bg_focus
                else
                    bg.bgimage = style.button.bgimage_normal
                    bg.bg = style.button.bg_normal
                end
            end,
            update_callback = function(self, tag, index, tags)
                local bg = self:get_children_by_id("background")[1]
                if tag.selected then
                    bg.bgimage = style.button.bgimage_focus
                    bg.bg = style.button.bg_focus
                else
                    bg.bgimage = style.button.bgimage_normal
                    bg.bg = style.button.bg_normal
                end
            end
        })
    })))
    return widget
end
