import * as $float from "../gleam_stdlib/gleam/float.mjs";
import * as $int from "../gleam_stdlib/gleam/int.mjs";
import * as $paint from "../paint/paint.mjs";
import * as $canvas from "../paint/paint/canvas.mjs";
import { toList, CustomType as $CustomType } from "./gleam.mjs";
import * as $physics from "./physics.mjs";
import { Vec2 } from "./physics.mjs";
import * as $target from "./target.mjs";
import { Colorable } from "./target.mjs";

export class Score extends $CustomType {
  constructor(position, colorable, score) {
    super();
    this.position = position;
    this.colorable = colorable;
    this.score = score;
  }
}
export const Score$Score = (position, colorable, score) =>
  new Score(position, colorable, score);
export const Score$isScore = (value) => value instanceof Score;
export const Score$Score$position = (value) => value.position;
export const Score$Score$0 = (value) => value.position;
export const Score$Score$colorable = (value) => value.colorable;
export const Score$Score$1 = (value) => value.colorable;
export const Score$Score$score = (value) => value.score;
export const Score$Score$2 = (value) => value.score;

export class CrossHair extends $CustomType {
  constructor(position, colorable, size) {
    super();
    this.position = position;
    this.colorable = colorable;
    this.size = size;
  }
}
export const CrossHair$CrossHair = (position, colorable, size) =>
  new CrossHair(position, colorable, size);
export const CrossHair$isCrossHair = (value) => value instanceof CrossHair;
export const CrossHair$CrossHair$position = (value) => value.position;
export const CrossHair$CrossHair$0 = (value) => value.position;
export const CrossHair$CrossHair$colorable = (value) => value.colorable;
export const CrossHair$CrossHair$1 = (value) => value.colorable;
export const CrossHair$CrossHair$size = (value) => value.size;
export const CrossHair$CrossHair$2 = (value) => value.size;

export class Health extends $CustomType {
  constructor(position, size, amount, max_health) {
    super();
    this.position = position;
    this.size = size;
    this.amount = amount;
    this.max_health = max_health;
  }
}
export const Health$Health = (position, size, amount, max_health) =>
  new Health(position, size, amount, max_health);
export const Health$isHealth = (value) => value instanceof Health;
export const Health$Health$position = (value) => value.position;
export const Health$Health$0 = (value) => value.position;
export const Health$Health$size = (value) => value.size;
export const Health$Health$1 = (value) => value.size;
export const Health$Health$amount = (value) => value.amount;
export const Health$Health$2 = (value) => value.amount;
export const Health$Health$max_health = (value) => value.max_health;
export const Health$Health$3 = (value) => value.max_health;

export class Hud extends $CustomType {
  constructor(score, cross_hair, health) {
    super();
    this.score = score;
    this.cross_hair = cross_hair;
    this.health = health;
  }
}
export const Hud$Hud = (score, cross_hair, health) =>
  new Hud(score, cross_hair, health);
export const Hud$isHud = (value) => value instanceof Hud;
export const Hud$Hud$score = (value) => value.score;
export const Hud$Hud$0 = (value) => value.score;
export const Hud$Hud$cross_hair = (value) => value.cross_hair;
export const Hud$Hud$1 = (value) => value.cross_hair;
export const Hud$Hud$health = (value) => value.health;
export const Hud$Hud$2 = (value) => value.health;

export function score_to_picture(score) {
  let position;
  let color;
  let score$1;
  position = score.position;
  score$1 = score.score;
  color = score.colorable.color;
  let _pipe = $paint.text("Score: " + $int.to_string(score$1), 32);
  let _pipe$1 = $paint.translate_xy(_pipe, position.x, position.y);
  return $paint.fill(_pipe$1, color);
}

export function cross_hair_to_picture(cross_hair) {
  let x;
  let y;
  let color;
  let size;
  size = cross_hair.size;
  x = cross_hair.position.x;
  y = cross_hair.position.y;
  color = cross_hair.colorable.color;
  let _pipe = $paint.circle(size);
  let _pipe$1 = $paint.stroke(_pipe, color, 5.0);
  return $paint.translate_xy(_pipe$1, x, y);
}

function health_to_picture_helper(loop$health, loop$acc, loop$count) {
  while (true) {
    let health = loop$health;
    let acc = loop$acc;
    let count = loop$count;
    let $ = count < health.max_health;
    if ($) {
      let _block;
      let $1 = count < health.amount;
      if ($1) {
        _block = $canvas.image_from_src("../res/heart.svg");
      } else {
        _block = $canvas.image_from_src("../res/no-heart.svg");
      }
      let heart_image = _block;
      let size = $float.round(health.size);
      loop$health = health;
      loop$acc = $paint.combine(
        toList([
          acc,
          (() => {
            let _pipe = $paint.image(heart_image, size, size);
            let _pipe$1 = $paint.image_scaling_pixelated(_pipe);
            return $paint.translate_xy(
              _pipe$1,
              $int.to_float(count) * (health.size + 10.0),
              0.0,
            );
          })(),
        ]),
      );
      loop$count = count + 1;
    } else {
      return acc;
    }
  }
}

export function health_to_picture(health) {
  let _pipe = health_to_picture_helper(health, $paint.blank(), 0);
  return $paint.translate_xy(_pipe, health.position.x, health.position.y);
}
