use crate::{
    types::{Color, GameState},
    ui::types,
};
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct PlayingFieldView {
    pub board: types::BoardElement,
    pub player_card_black: types::PlayerCardElement,
    pub player_card_white: types::PlayerCardElement,
    pub chat: types::ChatElement,
    pub message: types::TextFieldElement,
    pub current_player: Color,
}

pub fn playing_field(game: &GameState) -> PlayingFieldView {
    let board = types::BoardElement::from(&game.board);

    let player_card_black = types::PlayerCardElement {
        color: Color::Black,
        name: game.black_player.name.clone(),
        rank: game
            .black_player
            .rank
            .map(String::from)
            .unwrap_or("".to_owned()),
        clock: "".to_owned(),
    };

    let player_card_white = types::PlayerCardElement {
        color: Color::White,
        name: game.white_player.name.clone(),
        rank: game
            .black_player
            .rank
            .map(String::from)
            .unwrap_or("".to_owned()),
        clock: "".to_owned(),
    };

    let chat = types::ChatElement {
        messages: vec![
            "[22:05] Savanni: oops".to_owned(),
            "[22:06] Opal: you know I'll take advantage of that, right?".to_owned(),
        ],
    };
    let message = types::TextFieldElement {};

    PlayingFieldView {
        board,
        player_card_black,
        player_card_white,
        chat,
        message,
        current_player: game.current_player,
    }
}
