#include "deletedialog.h"

#include "ui_deletedialog.h"

#include "../verificationwidget/verificationwidget.h"

#include <QDebug>

void DeleteDialog::done(int resultCode) {
  if (QDialog::Accepted == resultCode &&
      m_verificationWidget->inputVerified() == false) {
    m_verificationWidget->noticeRed();
    QApplication::beep();
    return;
  }
  QDialog::done(resultCode);
  return;
}

DeleteDialog::DeleteDialog(const QString &reference, QDialog *parent,
                           Qt::WindowFlags f)
    : QDialog(parent, f), m_ui(new Ui::DeleteDialog) {
  m_ui->setupUi(this);
  setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
  createWidgets();
  configureText();
  setReference(reference);
}

DeleteDialog::~DeleteDialog() { delete m_ui; }

void DeleteDialog::createWidgets() {
  m_verificationWidget = new VerificationWidget;
  m_ui->m_verificationLayout->addWidget(m_verificationWidget);
  m_verificationWidget->setFocus();
}

void DeleteDialog::configureText() {
  setWindowTitle(tr("Removing process"));
  m_ui->m_buttonBoxLabel->setText(tr("Do you confirm the removal?"));
}

void DeleteDialog::setReference(const QString &reference) {
  m_verificationWidget->setReference(reference);
}

void DeleteDialog::setTopText(const QString &value) {
  m_ui->m_topLabel->setText(value);
}
