local utils = require("utils")
local bindings   = utils.bindings
local buttonbind = utils.buttonbind

client.connect_signal('request::titlebars', function(c)
	local function move_client()
        client.focus = c
        c:raise()
        awful.mouse.client.move(c)
	end

	local function resize_client()
        client.focus = c
        c:raise()
        awful.mouse.client.resize(c)
	end

    local buttons = bindings{
		buttonbind({}, 1, move_client),
		buttonbind({}, 3, resize_client),
    }

    awful.titlebar(c, {size = 30}):setup{
        {
            { -- Left
                { -- Title
                    align = 'center',
                    widget = awful.titlebar.widget.titlewidget(c)
                },
                -- awful.titlebar.widget.iconwidget(c),
                buttons = buttons,
                layout = wibox.layout.fixed.horizontal
            },
            { -- Middle
                buttons = buttons,
                layout = wibox.layout.flex.horizontal
            },
            { -- Right
                {
                    awful.titlebar.widget.minimizebutton(c),
                    awful.titlebar.widget.closebutton(c),
                    spacing = dpi(10),
                    layout = wibox.layout.fixed.horizontal
                },
                top = dpi(5),
                bottom = dpi(5),
                widget = wibox.container.margin
            },
            layout = wibox.layout.align.horizontal
        },
        right = dpi(10),
        left = dpi(10),
        top = dpi(0),
        bottom = dpi(5),
        widget = wibox.container.margin
    }
end)
