1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use chrono::{DateTime, Utc};
use term_table::row::Row;
use term_table::table_cell::TableCell;

use crate::render::table::builder::BergTableBuilder;

pub fn render_comment(
    username: &str,
    creation_time: DateTime<Utc>,
    comment: &str,
    max_width: usize,
) -> String {
    const PARENTHESES: usize = 2;
    const COLON: usize = 1;

    const BORDER_CHARS: usize = 2;
    const BORDER_PADDING: usize = 2;
    const EXTRA_PADDING_IF_UNEVEN: usize = 1;

    let creation_time_formatted = creation_time.format("%d.%m.%Y - %H:%M").to_string();

    let comment_text_width =
        max_width - (2 * BORDER_CHARS + 2 * BORDER_PADDING + EXTRA_PADDING_IF_UNEVEN);
    println!("{comment_text_width}");

    format!(
        "{}\n({}):\n{}\n\n{}",
        username,
        creation_time_formatted,
        "=".repeat(creation_time_formatted.len() + PARENTHESES + COLON),
        BergTableBuilder::new()
            .with_max_column_width(comment_text_width)
            .add_row(Row::new(vec![TableCell::new(comment)]))
            .build()
            .render()
    )
}