class AcrofonyOptionCard extends Object2D
{
    constructor(name)
    {
        super(name);

        /** @type {String} */
        this.syllable = "";
        /** @type {Boolean} */
        this.isAnswer = false;
        /** @type {Boolean} */
        this.selected = false;
        /** @type {Boolean} */
        this.selectable = true;
        /** @type {Boolean} */
        this.mouseOver = false;
        /** @type  {Boolean} */
        this.mousePress = false;

        /** @type {Color} */
        this.fillColor = new Color(200, 200, 200);
        /** @type {Boolean} */
        this.tweenStarted = false;
        /** @type {Tween} */
        this.tween = null;
        /** @type {Timer} */
        this.timer = null;
    }

    _initSignals()
    {
        this.addSignal("selected");
    }

    _setup()
    {
        var area = new Area2D("area", SHAPES.RECT, new Rect(250, 200), true);
        area.connect("mouseEntered", this, "_onMouseEntered");
        area.connect("mouseExited", this, "_onMouseExited");
        this.addChild(area);

        this.addChild(new AcrofonyCardVisualEffect("CardVfx"));

        this.tween = new Tween("Tween");
        this.tween.interpolateProperty(this, "scale", PROPERTY_TYPE.VECTOR2, Vector2.ZERO(), Vector2.ONE(), 2, TRANS_TYPE.ELASTIC, EASE_TYPE.OUT);
        this.addChild(this.tween);

        this.timer = new Timer("Timer", 1, false, true);
        this.timer.connect("timeout", this, "_onTimerTimeout");
        this.addChild(this.timer);
    }

    _update( /** @type {Number} */ delta)
    {
        if (this.visible && !this.tweenStarted)
        {
            this.timer.start();
            this.tween.startAll();
            this.tweenStarted = true;
        }

        if (this.selectable && this.mouseOver)
        {
            if (InputHandler.mouseIsClicked)
            {
                this.selected = true;
                this.selectable = false;
                this.emitSignal("selected", this.isAnswer);
            }

            if (InputHandler.mouseIsPressed)
            {
                this.scale.x = max(this.scale.x - 3.0 * delta, 0.95);
                this.scale.y = max(this.scale.y - 3.0 * delta, 0.95);
            }
            else
            {
                this.scale.x = min(this.scale.x + 2.0 * delta, 1.2);
                this.scale.y = min(this.scale.y + 2.0 * delta, 1.2);
            }
        }

        else
        {
            this.scale.x = max(this.scale.x - 2.0 * delta, 1);
            this.scale.y = max(this.scale.y - 2.0 * delta, 1);
        }
    }

    _draw( /** @type {Number} */ delta, /** @type {p5.Graphics} */ db)
    {
        db.rectMode(CENTER);
        db.fill(this.fillColor.getP5Color());
        db.rect(0, 0, 250, 200, 10, 10);
        db.textAlign(CENTER, CENTER);
        db.fill(0);
        db.textSize(50);
        db.text(this.syllable, 0, 0);
    }

    _onMouseEntered()
    {
        this.mouseOver = true;
    }

    _onMouseExited()
    {
        this.mouseOver = false;
    }

    _onTimerTimeout()
    {
        this.tween.stopAll();
    }
}