using Gtk;

private class SenderAnnotationLayout : Object, ChatItemLayout
{
    public string sender;
    public float max_width;
    public bool from_me { get; set; default = false; }
    public float vertical_padding { get; set; default = 0.0f; }
    public string id { get; set; }

    private Pango.Layout layout;
    private BubbleLayoutConstants constants;
    private const float padding = 10.0f;

    public SenderAnnotationLayout(string sender, float max_width, Widget parent) {
        this.sender = sender;
        this.max_width = max_width;
        this.constants = BubbleLayoutConstants(parent.get_scale_factor());

        layout = parent.create_pango_layout(sender);
        var font_desc = Pango.FontDescription.from_string("Sans 8");
        layout.set_font_description(font_desc);
    }

    public float get_height() {
        Pango.Rectangle ink_rect, logical_rect;
        layout.get_pixel_extents(out ink_rect, out logical_rect);

        return logical_rect.height + padding;
    }

    public float get_width() {
        return max_width;
    }

    public void draw(Snapshot snapshot) {
        snapshot.save();

        Pango.Rectangle ink_rect, logical_rect;
        layout.get_pixel_extents(out ink_rect, out logical_rect);


        snapshot.translate(Graphene.Point() {   
            x = constants.text_x_padding + constants.tail_width,
            y = get_height() - logical_rect.height,
        });

        snapshot.append_layout(layout, Gdk.RGBA() {
            red = 1.0f,
            green = 1.0f,
            blue = 1.0f,
            alpha = 0.8f
        });

        snapshot.restore();
    }

    public void copy(Gdk.Clipboard clipboard) {
        clipboard.set_text(sender);
    }
}