#include "password-line-edit.h"

PasswordLineEdit::PasswordLineEdit(QWidget *parent)
    : QLineEdit(parent)
{
    setEchoMode(QLineEdit::Password);
    setupToggle();
}

void PasswordLineEdit::setupToggle() {
    if (m_toggleAction) return;
    m_toggleAction = new QAction(this);
    m_toggleAction->setCheckable(true);
    m_toggleAction->setIcon(QIcon(":/plugin/icons/eye-hidden.svg"));
    addAction(m_toggleAction, QLineEdit::TrailingPosition);
    connect(m_toggleAction, &QAction::toggled, this, [this](bool vis){
        setEchoMode(vis ? QLineEdit::Normal : QLineEdit::Password);
        m_toggleAction->setIcon(QIcon(vis ? ":/plugin/icons/eye-visible.svg" : ":/plugin/icons/eye-hidden.svg"));
    });
}
