/*
 *
 * GenericLayerT
 *
 * GenericLayerT is the class that all layers must inherit from in order to be drawn. This allows for the GUI to properly
 * draw the layers on which you want your canvas to exist!
 *
 *
*/

package jesse.keeblarcraft.gui;

import jesse.keeblarcraft.Utils.CommonStructures.Position2d;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder;
import net.minecraft.client.gui.widget.ClickableWidget;
import net.minecraft.text.Text;

abstract public class GenericLayerT extends ClickableWidget {
    // These are the box bounds of the widget
    public int startX;
    public int startY;
    public int endX;
    public int endY;

    public GenericLayerT() {
        // default constructor
        super(0, 0, 0, 0, Text.of(""));
    }

    /////////////////////////////////////////////////////////////////////////////
    /// @fn         GenericLayerT
    ///
    /// @brief      Constructor for class. This is setup directly by the screen
    ///             manager object and it is not recommended to change the x/y
    ///             positions or you may break the relation of your widget to
    ///             others on the screen at the same time!
    /////////////////////////////////////////////////////////////////////////////
    public GenericLayerT(int x, int y, int width, int height, Text message) {
        super(x, y, width, height, message);
    }

    /////////////////////////////////////////////////////////////////////////////
    /// @fn         DrawLayer
    ///
    /// @brief      Draw on a layer! This is an early implementation of being
    ///             able to choose the layer you are drawing on and making sure
    ///             you can customize which layer your context will draw on.
    ///             This will be called by the overall screen manager so the
    ///             layer id will be passed in. You will need to handle the layer
    ///             id yourself.
    ///
    /// @note       It is possible to get passed any layer id and you handle each
    ///             layer respectively; however, it is possible to draw on the
    ///             wrong layer if handled wrong. For example, you could be
    ///             passed layer '3' but this function is called for every layer
    ///             drawn on screen; so you must handle this to only draw on a
    ///             specific layer. Be careful!
    /////////////////////////////////////////////////////////////////////////////
    public abstract void DrawLayer(DrawContext context, int layer);

    public void UpdateAnchorValues(int x, int y) {
        this.startX = x;
        this.startY = y;
    }

    // Calculated based on center of box values
    public Position2d GetScreenCenter() {
        return new Position2d((this.endX - this.startX) / 2, (this.endY - this.startY) / 2);
    }

    public abstract void renderButton(DrawContext context, int mouseX, int mouseY, float delta);
    protected abstract void appendClickableNarrations(NarrationMessageBuilder builder);
}