#include "mainwindow.h"
//#include "xanimparts.h"

#include <QMessageBox>
#include <QLabel>
#include <QFile>
#include <QVBoxLayout>
#include <QDebug>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow{parent} {
    setWindowTitle("Asset Assess");
    setMinimumSize(250, 150);

    mTextEdit = new QPlainTextEdit(this);
    mTextEdit->setAcceptDrops(false);
    mTextEdit->setPlaceholderText("Drag .*_raw file here...");

    setCentralWidget(mTextEdit);
}

MainWindow::~MainWindow() {

}

void MainWindow::LogLine(const QString &aLogText)
{
    if (mTextEdit->toPlainText().isEmpty()) {
        mTextEdit->setPlainText(aLogText);
    } else {
        mTextEdit->setPlainText(mTextEdit->toPlainText() + "\r\n" + aLogText);
    }
}

void MainWindow::dragEnterEvent(QDragEnterEvent *event) {
    const QMimeData *mimeData = event->mimeData();
    bool goodDrag = true;
    if (mimeData->hasUrls()) {
        qDebug() << mimeData->urls();
    } else {
        goodDrag = false;
    }
    if (goodDrag) {
        event->acceptProposedAction();
    }
}

void MainWindow::dragMoveEvent(QDragMoveEvent *event) {
    Q_UNUSED(event);
}

void MainWindow::dragLeaveEvent(QDragLeaveEvent *event) {
    Q_UNUSED(event);
}

void MainWindow::dropEvent(QDropEvent *event) {
    // const QMimeData *mimeData = event->mimeData();
    // if (mimeData->hasUrls()) {
    //     foreach (const QUrl &url, mimeData->urls()) {
    //         const QString fileName = url.toString().split('/').last();
    //         LogLine(QString("Processing %1").arg(fileName));

    //         QFile file(url.toLocalFile());
    //         if (!file.open(QIODevice::ReadOnly)) {
    //             LogLine(QString("Failed to open %1").arg(fileName));
    //             continue;
    //         }
    //         LogLine(QString("Opened %1").arg(fileName));

    //         QDataStream dataStream(file.readAll());
    //         dataStream.setByteOrder(QDataStream::LittleEndian);
    //         LogLine(QString("Created data stream"));

    //         if (fileName.contains(".xanim_raw")) {
    //             LogLine(QString("Opening XANIM raw file"));

    //             XAnimParts animParts;
    //             dataStream >> animParts;
    //             LogLine(XAnimPartsToString(animParts));
    //         }
    //     }
    // }
}
