using Gtk;

class DateItemLayout : Object, ChatItemLayout {
    public bool from_me { get; set; }
    public float vertical_padding { get; set; }
    public string id { get; set; }

    private Pango.Layout layout;
    private float max_width;

    public DateItemLayout(string date_str, Widget parent, float max_width) {
        this.max_width = max_width;

        layout = parent.create_pango_layout(date_str);
        layout.set_font_description(Pango.FontDescription.from_string("Sans 9"));
        layout.set_alignment(Pango.Alignment.CENTER);
    }

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

        return logical_rect.height + 50.0f;
    }

    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 = (max_width - logical_rect.width) / 2,
            y = (get_height() - logical_rect.height) / 2
        });

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

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