use glib::Object;
use gtk::{prelude::*, subclass::prelude::*};
use otg_core::Color;
use sgf::Player;

#[derive(Default)]
pub struct PlayerCardPrivate {
    // player_name: gtk::Label,
    // clock: gtk::Label,
}

#[glib::object_subclass]
impl ObjectSubclass for PlayerCardPrivate {
    const NAME: &'static str = "PlayerCard";
    type Type = PlayerCard;
    type ParentType = gtk::Box;
}

impl ObjectImpl for PlayerCardPrivate {}
impl WidgetImpl for PlayerCardPrivate {}
impl BoxImpl for PlayerCardPrivate {}

glib::wrapper! {
    pub struct PlayerCard(ObjectSubclass<PlayerCardPrivate>) @extends gtk::Box, gtk::Widget, @implements gtk::Orientable;
}

impl PlayerCard {
    pub fn new(
        color: Color,
        player: &Player, /* add on current number of captures and time remaining on the clock*/
    ) -> PlayerCard {
        let s: Self = Object::builder().build();
        // I forget really the BEM system, but I know that what I want here is the block name and
        // the modifier. I don't need an element here. So I'm going to mock it up and look up the
        // real standard in my notes later.
        match color {
            Color::Black => s.set_css_classes(&["player-card", "player-card___black"]),
            Color::White => s.set_css_classes(&["player-card", "player-card___white"]),
        }
        s.set_orientation(gtk::Orientation::Vertical);
        /*
        s.imp()
            .player_name
            .set_text(&format!("{} ({})", element.name, element.rank));
            */
        // s.imp().clock.set_text(&element.clock);

        let name: String = player.name.clone().unwrap_or(color.to_string());
        let player_name = gtk::Label::new(Some(&name));

        s.append(&player_name);
        // s.append(&s.imp().clock);
        s
    }
}
