#include "AboutDialog.h"

#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLabel>
#include <QPushButton>
#include <QFrame>
#include <QFont>
#include <QApplication>

AboutDialog::AboutDialog(QWidget *parent)
    : QDialog(parent)
{
    setWindowTitle(tr("Über BareCode"));
    setFixedSize(440, 310);
    setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);

    QVBoxLayout *root = new QVBoxLayout(this);
    root->setContentsMargins(0, 0, 0, 0);
    root->setSpacing(0);

    // -----------------------------------------------------------------------
    // Header-Banner
    // -----------------------------------------------------------------------
    QFrame *banner = new QFrame(this);
    banner->setFixedHeight(88);
    banner->setStyleSheet(
        "background: qlineargradient(x1:0, y1:0, x2:1, y2:0,"
        " stop:0 #1a1a2e, stop:1 #16213e);"
    );

    QVBoxLayout *bannerLayout = new QVBoxLayout(banner);
    bannerLayout->setContentsMargins(24, 10, 24, 10);
    bannerLayout->setSpacing(2);

    QLabel *appName = new QLabel("BareCode", banner);
    QFont nameFont = appName->font();
    nameFont.setPointSize(22);
    nameFont.setBold(true);
    appName->setFont(nameFont);
    appName->setStyleSheet("color: #e0e0ff; background: transparent;");

    QLabel *tagline = new QLabel(tr("Modularer Code-Editor"), banner);
    tagline->setStyleSheet("color: #8888bb; background: transparent;");

    bannerLayout->addWidget(appName);
    bannerLayout->addWidget(tagline);
    root->addWidget(banner);

    // -----------------------------------------------------------------------
    // Info-Tabelle
    // -----------------------------------------------------------------------
    QVBoxLayout *info = new QVBoxLayout();
    info->setContentsMargins(28, 20, 28, 8);
    info->setSpacing(10);

    auto makeRow = [&](const QString &label, const QString &value)
    {
        QHBoxLayout *row = new QHBoxLayout();
        row->setSpacing(12);

        QLabel *lbl = new QLabel(label, this);
        QFont boldFont = lbl->font();
        boldFont.setBold(true);
        lbl->setFont(boldFont);
        lbl->setFixedWidth(100);
        lbl->setAlignment(Qt::AlignRight | Qt::AlignVCenter);

        QLabel *val = new QLabel(value, this);
        val->setTextInteractionFlags(Qt::TextSelectableByMouse);

        row->addWidget(lbl);
        row->addWidget(val, 1);
        info->addLayout(row);
    };

    makeRow(tr("Version"),    "1.1.0");
    makeRow(tr("Entwickler"), "Dany Thinnes");
    makeRow(tr("Projekt"),    "Projekt Hirnfrei");
    makeRow(tr("Framework"),  QString("Qt %1").arg(qVersion()));
    makeRow(tr("Sprache"),    "C++17");

    root->addLayout(info);
    root->addStretch();

    // -----------------------------------------------------------------------
    // Trennlinie + Schließen-Button
    // -----------------------------------------------------------------------
    QFrame *line = new QFrame(this);
    line->setFrameShape(QFrame::HLine);
    line->setFrameShadow(QFrame::Sunken);
    root->addWidget(line);

    QHBoxLayout *btnRow = new QHBoxLayout();
    btnRow->setContentsMargins(12, 8, 12, 12);
    btnRow->addStretch();

    QPushButton *btnClose = new QPushButton(tr("Schließen"), this);
    btnClose->setDefault(true);
    btnClose->setFixedWidth(110);
    connect(btnClose, &QPushButton::clicked, this, &QDialog::accept);
    btnRow->addWidget(btnClose);

    root->addLayout(btnRow);
}
