// Copyright 2015 - 2026, GIBIS-UNIFESP and the wiRedPanda contributors
// SPDX-License-Identifier: GPL-3.0-or-later

/** \file
 * \brief Graphic element for the D latch.
 */

#pragma once

#include "App/Core/ThemeManager.h"
#include "App/Element/GraphicElement.h"

/**
 * \class DLatch
 * \brief Graphical representation of a level-sensitive D latch.
 *
 * \details Has 2 inputs (D, Enable) and 2 outputs (Q, Q̄).
 */
class DLatch : public GraphicElement
{
    Q_OBJECT

public:
    // --- Lifecycle ---

    /// Constructs the element with optional \a parent.
    explicit DLatch(QGraphicsItem *parent = nullptr);

    // --- Visual ---

    static QString pixmapPath()
    {
        return ":/Components/Memory/" + ThemeManager::themePath() + "/D-latch.svg";
    }

    /// Updates port names for this latch.
    void updatePortsProperties() override;

    /// Refreshes the pixmap when the application theme changes.
    void updateTheme() override;

    /// Updates Q based on D and enable level.
    void updateLogic() override;
};
