import Utils from "../common/utils";
import ColorPickerTool from "./color-picker-tool";
import Layer from "./layer";




/**
 * Simple image layer 
 */
export default class ImageLayer extends Layer {


  images : HTMLImageElement[] = [];

  constructor(...images: HTMLImageElement[]) {
    super(images[0].width, images[0].height);
    this.images = images;
    this.addTool(new ColorPickerTool());
  }

  override get defaultToolKey(): string { return new ColorPickerTool().key }

  public set image(img: HTMLImageElement) {
    this.images[0] = img;
    this.invalidate()
  }

  public get image(): HTMLImageElement {
    return this.images[0];
  }

  override draw(ctx: CanvasRenderingContext2D): void {

    Utils.setImageSmoothing(ctx, false);
    this.images.forEach(img => {
      ctx.drawImage(img, 0, 0);
    })

  }


}