package leigh.elements.javafx.type1;

import leigh.elements.ElementsFactoryBase;
import leigh.elements.javafx.ThemeJFX;
import leigh.elements.sdk.AppScreenInstance;
import leigh.elements.sdk.type1.*;
import leigh.eo.EO;
import leigh.mecha.log.MechaLogger;
import leigh.mecha.log.MechaLoggerFactory;
import leigh.mecha.nodegraph.NodeConfig;

import java.util.List;

/**
 * This class implements a factory for elements implementation.
 *
 * @author Alex Leigh
 */
public class ElementFactoryJFX extends ElementsFactoryBase {
    private static final MechaLogger logger = MechaLoggerFactory.getLogger(ElementFactoryJFX.class);

    // TODO Get rid of this
    private final List<NodeConfig> nodeConfigs;

    public ElementFactoryJFX(List<NodeConfig> nodeConfigs) {
        this.nodeConfigs = nodeConfigs;
    }

    public Element newNode(EO cfg, AppScreenInstance screen) {
        logger.debug("Instancing. [type: {}]", cfg.getApiType());
        switch (cfg.getApiType()) {
            case ScreenElement.EO_TYPE:
                return new ScreenElementJFX(cfg, screen);
            case PanelGroupElement.EO_TYPE:
                return new PanelGroupElementJFX(cfg, screen);
            case PanelElement.EO_TYPE:
                return new PanelElementJFX(cfg, screen);
            case TextElement.EO_TYPE:
                return new TextElementJFX(cfg);
            case TextFieldElement.EO_TYPE:
                return new FieldElementJFX(cfg, screen);
            case FormLayout.EO_TYPE:
                return new FormLayoutJFX(cfg, screen);
            case TableElement.EO_TYPE:
                return new TableElementJFX(cfg, screen, (ThemeJFX) screen.getTheme());
            case NodeGraphElement.EO_TYPE:
                return new GraphElementJFX(cfg, nodeConfigs);
            case ButtonElement.EO_TYPE:
                return new ButtonElementJFX(cfg, screen);
            case GridElement.EO_TYPE:
                return new GridElementJFX(cfg, screen);
            case TextTileElement.EO_TYPE:
                return new TextTileElementJFX(cfg);
            case GaugeTileElement.EO_TYPE:
                return new GaugeTileElementJFX(cfg);
            case FileFieldElement.EO_TYPE:
                return new FilePanelJFX(cfg, screen);
            case HorizontalLayoutElement.EO_TYPE:
                return new HorizontalLayoutElementJFX(cfg, screen);
            case FlowLayoutElement.EO_TYPE:
                return new FlowLayoutElementJFX(cfg, screen);
        }

        throw new IllegalStateException("Unknown Element type: " + cfg.getApiType());
    }
}
