const Tool = @import("Tool.zig");

const Toolbar = @This();

pub const ToolDescriptor = struct {
    name: []const u8,
    icon_tvg: []const u8,
    implementation: *const Tool.Tool,
};

tools: []const ToolDescriptor,
selected_index: ?usize,

pub fn init(tools_list: []const ToolDescriptor) Toolbar {
    return .{
        .tools = tools_list,
        .selected_index = null,
    };
}

pub fn deinit(_: *Toolbar) void {}

pub fn currentDescriptor(self: *const Toolbar) ?*const ToolDescriptor {
    if (self.tools.len == 0) return null;
    if (self.selected_index) |index| {
        return &self.tools[index];
    }
    return null;
}

pub fn select(self: *Toolbar, index: ?usize) void {
    if (index == self.selected_index) {
        self.selected_index = null;
        return;
    }
    if (index) |i| {
        if (i < self.tools.len) {
            self.selected_index = i;
        }
    } else {
        self.selected_index = null;
    }
}
