#include "UIInitialization.h"

#include "Animation.h"
#include "Button.h"
#include "Camera2D.h"
#include "Diagram.h"
#include "FileSystem.h"
#include "Font.h"
#include "Image.h"
#include "List.h"
#include "M2DPreview.h"
#include "Model2D.h"
#include "Progress.h"
#include "SelectionBox.h"
#include "Table.h"
#include "UIMLView.h"
#include "Window.h"

using namespace Framework;

SelectionBox* createSelectionBox(const UIInitParam& p)
{
    SelectionBox* ret = new SelectionBox();
    ret->setStyle(SelectionBox::Style::Normal);
    ret->setBackgroundColor(0xFF000000);
    ret->setMouseEvent(_ret1ME);
    if (p.font) ret->setFontZ(dynamic_cast<Font*>(p.font->getThis()));
    ret->setBorderWidth(1);
    ret->setBorderColor(0xFFFFFFFF);
    ret->setMaxAuskappHeight(100);
    ret->setMouseBorderWidth(1);
    ret->setMouseBorderColor(0xFF005500);
    ret->setMouseAlphaFieldColor(0x00008700);
    ret->setMouseAlphaFieldStrength(-8);
    ret->setSelBorderWidth(1);
    ret->setSelBorderColor(0xFF00FF00);
    ret->setSelAlphaFieldColor(0x0000FF00);
    ret->setSelAlphaFieldStrength(-8);
    return ret;
}

SelectionList* createSelectionList(const UIInitParam& p)
{
    SelectionList* ret = new SelectionList();
    ret->setStyle(SelectionList::Style::Normal);
    if (p.font) ret->setFontZ(dynamic_cast<Font*>(p.font->getThis()));
    ret->setAlphaFieldColor(0x5500FF00);
    ret->setAlphaFieldStrength(-5);
    ret->setBorderWidth(1);
    ret->setBorderColor(0xFFFFFFFF);
    ret->setBackgroundColor(0xFF000000);
    ret->setMouseEvent(_ret1ME);
    ret->setSelectionBorderWidth(1);
    ret->setSelectionBorderColor(0xFF00FF00);
    ret->setSelectionAFColor(0x0000FF00);
    ret->setSelectionAFStrength(-8);
    ret->update();
    return ret;
}

ImageView* createImageView(const UIInitParam& p)
{
    ImageView* ret = new ImageView();
    ret->setStyle(ImageView::Style::normal);
    ret->setBorderWidth(1);
    ret->setBorderColor(0xFFFFFFFF);
    return ret;
}

ProgressBar* createProgressBar(const UIInitParam& p)
{
    ProgressBar* ret = new ProgressBar();
    ret->setStyle(ProgressBar::Style::normal);
    if (p.font) ret->setFontZ(dynamic_cast<Font*>(p.font->getThis()));
    ret->setSColor(0xFFFFFFFF);
    ret->setSSize(12);
    ret->setBorderColor(0xFFFFFFFF);
    ret->setBorderWidth(1);
#ifdef WIN32
    LTDBFile* datei = new LTDBFile();
    datei->setFile(new Text(
        "data/bilder/system.ltdb")); // TODO integrate this into the dll
    datei->readData(0);
    Image* fbhb = datei->load(0, new Text("fortschrittleh"));
    ret->setBackgroundImageZ(fbhb);
    Image* fbfhb = datei->load(0, new Text("fortschrittvol"));
    datei->release();
    ret->setFBgImageZ(fbfhb);
#endif
    ret->setFBgColor(0xFF00FF00);
    return ret;
}

Camera2D* createCamera2D(const UIInitParam& p)
{
    Camera2D* ret = new Camera2D();
    // TODO
    return ret;
}

Window* createWindow(const UIInitParam& p)
{
    Window* ret = new Window();
    ret->setMouseEvent(_ret1ME);
    ret->setKeyboardEvent(_ret1TE);
    ret->setStyle(Window::Style::normal);
    ret->setBorderWidth(1);
    ret->setBorderColor(0xFFFFFFFF);
    ret->setTitel("");
    if (p.font) ret->setTFontZ(dynamic_cast<Font*>(p.font->getThis()));
    ret->setTFontColor(0xFFFFFFFF);
    ret->zTTextField()->setSize(0, 20);
    ret->zTTextField()->addStyle(TextField::Style::Visible
                                 | TextField::Style::Center
                                 | TextField::Style::Border);
    ret->setTBorderColor(0xFF00FF00);
    ret->setTBorderWidth(1);
    ret->setTAfColor(0x1000FF00);
    ret->setTAfStrength(-15);
    ret->setCloseClickAfColor(0xFF00FF00);
    ret->setCloseClickAfStrength(30);
    return ret;
}

Button* createButton(const UIInitParam& p)
{
    Button* ret = new Button();
    if (p.font) ret->setFontZ(dynamic_cast<Font*>(p.font->getThis()));
    ret->setStyle(Button::Style::Normal);
    return ret;
}

CheckBox* createCheckBox(const UIInitParam& p)
{
    CheckBox* ret = new CheckBox();
    ret->setMouseEvent(_ret1ME);
    ret->setStyle(CheckBox::Style::Normal);
    if (p.font) ret->setFontZ(dynamic_cast<Font*>(p.font->getThis()));
    ret->setSColor(0xFFFFFFFF);
    ret->setSSize(12);
    ret->setAlphaFieldColor(0x5500FF00);
    ret->setAlphaFieldStrength(-5);
    ret->setBorderWidth(1);
    ret->setBorderColor(0xFF00FF00);
#ifdef WIN32
    ret->loadData(
        "data/bilder/system.ltdb"); // TODO integrate this into the dll
#endif
    return ret;
}

LineDiagram* createLineDiagram(const UIInitParam& p)
{
    LineDiagram* ret = new LineDiagram();
    ret->setStyle(LineDiagram::Style::normal);
    if (p.font) ret->setFontZ(dynamic_cast<Font*>(p.font->getThis()));
    ret->setBorderWidth(1);
    ret->setBorderColor(0xFFFFFFFF);
    ret->setDataBorderWidth(1);
    ret->setDataBorderColor(0xFFFFFFFF);
    ret->setBackgroundColor(0xFF000000);
    ret->setDataBackgroundColor(0xFF000000);
    return ret;
}

M2DPreview* createM2DPreview(const UIInitParam& p)
{
    M2DPreview* ret = new M2DPreview();
    // TODO
    return ret;
}

Model2D* createModel2D(const UIInitParam& p)
{
    Model2D* ret = new Model2D();
    // TODO
    return ret;
}

Animation2D* createAnimation2D(const UIInitParam& p)
{
    Animation2D* ret = new Animation2D();
    // TODO
    return ret;
}

TextField* createTextField(const UIInitParam& p)
{
    TextField* ret = new TextField();
    ret->setStyle(TextField::Style::Text);
    if (p.font) ret->setFontZ(dynamic_cast<Font*>(p.font->getThis()));
    ret->setFontColor(0xFFFFFFFF);
    ret->setFontSize(12);
    ret->setAlphaFieldColor(0x5500FF00);
    ret->setAlphaFieldStrength(-5);
    ret->setBorderWidth(1);
    ret->setBorderColor(0xFF00FF00);
    return ret;
}

ObjTable* createObjTable(const UIInitParam& p)
{
    ObjTable* ret = new ObjTable();
    ret->setStyle(ObjTable::Style::normal);
    ret->setMouseEvent(_ret1ME);
    ret->setBorderWidth(1);
    ret->setBorderColor(0xFFFFFFFF);
    ret->setGridWidth(1);
    ret->setGridColor(0xFFFFFFFF);
    ret->setVerticalClickScroll(5);
    ret->setHorizontalClickScroll(5);
    return ret;
}

LiveLineDiagram* createLiveLineDiagram(const UIInitParam& p)
{
    LiveLineDiagram* ret = new LiveLineDiagram();
    // TODO
    return ret;
}

UIMLView* createUIMLView(const UIInitParam& p)
{
    UIMLView* ret = new UIMLView();
    // TODO
    return ret;
}

UIInit Framework::defaultUI(Font* zFont, Screen* zScreen)
{
    UIInit uii;
    uii.initParam.font = zFont;
    uii.initParam.bildschirm = zScreen;
    uii.initParam.data = 0;
    uii.createSelectionBox = createSelectionBox;
    uii.createSelectionList = createSelectionList;
    uii.createImageView = createImageView;
    uii.createProgressBar = createProgressBar;
    uii.createCamera2D = createCamera2D;
    uii.createWindow = createWindow;
    uii.createButton = createButton;
    uii.createCheckBox = createCheckBox;
    uii.createLiveLineDiagram = createLiveLineDiagram;
    uii.createM2DPreview = createM2DPreview;
    uii.createModel2D = createModel2D;
    uii.createAnimation2D = createAnimation2D;
    uii.createTextField = createTextField;
    uii.createObjTable = createObjTable;
    uii.createLineDiagram = createLineDiagram;
    uii.createUIMLView = createUIMLView;
    return uii;
}