import pandas as pd


from great_tables import GT, loc, style


def warm_editorial_table(table: GT) -> GT:
    return (
        table.opt_table_font(font=["Inter", "system-ui", "sans-serif"])
        .opt_align_table_header(align="left")
        .tab_options(
            table_background_color="#FFF7ED",
            table_font_color="#1C1917",
            table_font_size="14px",
            table_border_top_style="none",
            table_border_bottom_color="#E7DDD2",
            heading_title_font_size="18px",
            heading_subtitle_font_size="13px",
            heading_border_bottom_style="none",
            column_labels_font_weight="600",
            column_labels_border_top_style="none",
            column_labels_border_bottom_color="#1C1917",
            column_labels_border_bottom_width="1px",
            column_labels_vlines_style="none",
            table_body_hlines_color="#E7DDD2",
            table_body_vlines_style="none",
            table_body_border_bottom_color="#E7DDD2",
            row_group_font_weight="600",
            row_group_border_top_color="#E7DDD2",
            row_group_border_bottom_color="#E7DDD2",
            stub_border_style="none",
            summary_row_border_color="#1C1917",
            grand_summary_row_border_color="#1C1917",
            source_notes_font_size="12px",
        )
        .tab_style(
            style=style.text(font="Georgia, 'Times New Roman', serif", weight="600"),
            locations=loc.title(),
        )
        .tab_style(style=style.text(color="#57534E"), locations=loc.subtitle())
        .tab_style(style=style.text(color="#57534E"), locations=loc.source_notes())
    )


def load_data():
    return [("Canal", 2.2, 1), ("Hill", 3.8, 3), ("Park", 2.6, 2), ("Market", 3.2, 4)]


def make_before(data):
    rows = [
        (route if route != "Market" else "4 km on Market", distance, slope * distance)
        for route, slope, distance in data
    ]
    frame = pd.DataFrame(rows, columns=["ride_via", "km_diff", "delta_t"])
    return (
        warm_editorial_table(GT(frame))
        .tab_header(title="Estimated additional cycling time")
        .fmt_number(columns="delta_t", decimals=1)
        .tab_options(
            table_body_vlines_style="solid",
            table_body_vlines_width="2px",
            table_body_vlines_color="#57534E",
            row_striping_include_table_body=True,
            row_striping_background_color="#E7DDD2",
        )
        .tab_style(
            style=style.css("font-variant-numeric: proportional-nums;"),
            locations=loc.body(columns="delta_t"),
        )
    )


if __name__ == "__main__":
    print(make_before(load_data()).as_raw_html())
