/**
 * Copyright (c) 2021 Dominic Masters
 * 
 * This software is released under the MIT License.
 * https://opensource.org/licenses/MIT
 */

#pragma once
#include "../../libs.h"
#include "../../ui/label.h"
#include "../../ui/image.h"
#include "../../display/framebuffer.h"
#include "../../display/primitive.h"
#include "../../display/primitives/quad.h"
#include "../../display/primitives/cube.h"
#include "../../display/shader.h"
#include "../../engine/engine.h"
#include "../../input/input.h"
#include "../../display/camera.h"
#include "../../vn/vncharacter.h"
#include "../../ui/grid.h"
#include "../../ui/align.h"
#include "../../vn/vnscene.h"
#include "../../poker/poker.h"
#include "pokerworld.h"
#include "pokergameassets.h"

#define POKER_UI_PLAYER_IMAGE_SIZE 64
#define POKER_UI_PLAYER_WIDTH 300
#define POKER_UI_PLAYER_HEIGHT POKER_UI_PLAYER_IMAGE_SIZE

#define POKER_UI_PLAYER_IMAGE_RESOLUTION POKER_UI_PLAYER_IMAGE_SIZE * 2
#define POKER_UI_PLAYER_IMAGE_DIST 0.7f
#define POKER_UI_PLAYER_IMAGE_Y 0.1f
#define POKER_UI_PLAYER_PADDING 8
#define POKER_UI_PLAYER_CHIPS_ANIMATION_SPEED 0.5f

#define POKER_UI_BET_ACTION_NONE 0x00
#define POKER_UI_BET_ACTION_FOLD 0x01
#define POKER_UI_BET_ACTION_BET 0x02

typedef struct {
  primitive_t quad;
  label_t label;
  grid_t grid;
  image_t card;
  framebuffer_t frames[POKER_PLAYER_COUNT_MAX];

  /** Betting UI */
  bool betShow;
  pokerturn_t betTurn;
  bool betTurnMade;
} pokerui_t;

/**
 * Initializes the UI Module.
 * 
 * @param ui UI to initialize.
 */
void pokerUiInit(pokerui_t *ui);

/**
 * Update the Poker Game UI.
 * 
 * @param ui UI to update.
 * @param engine Engine to use for updating.
 * @param shader Shader to use for rendering.
 * @param characters Visual Novel characters to render.
 * @param players Array of poker players.
 */
void pokerUiUpdate(
  pokerui_t *ui, engine_t *engine, shader_t *shader,
  vncharacter_t *characters, pokerplayer_t *players
);

/**
 * Render the Poker Game UI.
 * 
 * @param ui UI to render.
 * @param engine Engine to use for the render.
 * @param assets Poker game assets.
 * @param poker Poker instance.
 */
void pokerUiRender(
  pokerui_t *ui, engine_t *engine, pokergameassets_t *assets, poker_t *poker
);

/**
 * Cleanup only the UI elements for a poker game.
 * 
 * @param ui UI to dispose.
 */
void pokerUiDispose(pokerui_t *ui);

/**
 * Updates the given image to represent a card UI image.
 * 
 * @param image Image to update.
 * @param texture Texture to use.
 * @param card Card to set to.
 */
void pokerUiSetImageToCard(image_t *image, texture_t *texture, card_t card);

/**
 * Show and reset the betting UI.
 * 
 * @param ui UI to reset the bet state for.
 */
void pokerUiBetShow(pokerui_t *ui);