import { Label, ShapeCircle, ShapeRect, ShapeRectNew } from "./Unit";

export class Letter{
    data;

    images;

    bgColor;

    lineColor;

    scaleX = 1;

    scaleY = 1;

    bg : ShapeRectNew;

    dW;

    canDrag = true;


    init(images, data, bgColor, scaleX = 1, scaleY = 1) {

        this.images = images;

        this.data = data;

        this.bgColor = bgColor;

        this.scaleX = scaleX;

        this.scaleY = scaleY;

        this.initBg();

        let letter = this.initView();
  
        let w = 40 * this.scaleX + letter.getBoundingBox().width;

        let h = 90 * this.scaleY;

        this.bg.setSize(w, h, 0);
        letter.x = w / 2;
        letter.y = h / 2;
    }

    initBg(){

        let bg = new ShapeRectNew();
        bg.fillColor = this.bgColor;
        bg.setOutLine(this.lineColor, 6 * this.scaleX)

        this.bg = bg;

    }

    setColor(bgColor = "#dbd0e7", lineColor = "#8d4fad"){
        this.bgColor = bgColor;
        this.lineColor = lineColor;

        if(this.bg){
            this.bg.fillColor = bgColor;
            this.bg.strokeColor = lineColor;
        }
        
    }

    initView(){
        const letter = new Label();
        letter.text = this.data.val;
        letter.textAlign = 'center';
        letter.fontSize = 64;
        letter.fontName = "FUTURAB";
        letter.fontColor = "#2b292e";
        letter.setScaleXY(this.scaleX);
        letter.refreshSize();
        this.bg.addChild(letter);

        return letter;
    }
}