/*
Copyright 2023-2024, Savanni D'Gerinel <savanni@luminescent-dreams.com>

This file is part of FitnessTrax.

FitnessTrax is free software: you can redistribute it and/or modify it under the terms of the GNU
General Public License as published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

FitnessTrax is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License along with FitnessTrax. If not, see <https://www.gnu.org/licenses/>.
*/

use crate::types::{FormatOption, WeightFormatter};
use gtk::prelude::*;

pub struct WeightLabel {
    label: gtk::Label,
}

impl WeightLabel {
    pub fn new(weight: Option<WeightFormatter>) -> Self {
        let label = gtk::Label::builder()
            .css_classes(["card", "weight-view"])
            .can_focus(true)
            .build();

        match weight {
            Some(w) => label.set_text(&w.format(FormatOption::Abbreviated)),
            None => label.set_text("No weight recorded"),
        }

        Self { label }
    }

    pub fn widget(&self) -> gtk::Widget {
        self.label.clone().upcast()
    }
}
