#include "delete-user-confirm-panel.h"
#include <QFont>

DeleteUserConfirmPanel::DeleteUserConfirmPanel(const QString &username, QWidget *parent)
    : OverlayPanelBase(":/plugin/delete-user-confirm-panel.qss", parent), m_user(username)
{
    auto *content = this->contentLayout();
    auto *bottom = this->bottomLayout();

    auto *msg = new QLabel(tr("Confirm deletion of user '%1'?").arg(username));
        // Add 16px spacing above the message text
        content->addSpacing(16);

    msg->setObjectName("DialogMessage");
    msg->setWordWrap(true);
    msg->setAlignment(Qt::AlignCenter);
    QFont mf; mf.setPixelSize(18); mf.setWeight(QFont::Weight::Medium); msg->setFont(mf);
    content->addWidget(msg);

    // Create a lightweight form layout solely to host the inline warning row (reserved space)
    auto *form = new QFormLayout();
    form->setSpacing(12);
    form->setHorizontalSpacing(16);
    form->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow);
    content->addLayout(form);
    // Reserve inline warning space (top/bottom 0, icon-text spacing 6 for consistency)
    this->createInlineErrorRow(form, /*topBottomMargin=*/0, /*iconTextSpacing=*/8);
    hideInlineError();

    auto *btnRow = new QHBoxLayout();
    btnRow->addStretch();
    auto *cancelBtn = new DialogButton(tr("Cancel"), DialogButton::Cancel);
    auto *deleteBtn = new DialogButton(tr("Delete"), DialogButton::Confirm);
    btnRow->addWidget(deleteBtn);
    btnRow->addWidget(cancelBtn);
    btnRow->addStretch();
    bottom->addLayout(btnRow);

    connect(cancelBtn, &QToolButton::clicked, this, [this]{ emit cancelRequested(); });
        // Add 16px spacing below the buttons
        bottom->addSpacing(16);
    connect(deleteBtn, &QToolButton::clicked, this, [this]{ emit deleteConfirmed(m_user); });
}
