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

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

#pragma once

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

/**
 * \class SRLatch
 * \brief Graphical representation of a level-sensitive SR latch.
 *
 * \details Has 2 inputs (S̄, R̄, active-low) and 2 outputs (Q, Q̄).
 */
class SRLatch : public GraphicElement
{
    Q_OBJECT

public:
    // --- Lifecycle ---

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

    // --- Visual ---

    static QString pixmapPath()
    {
        return ":/Components/Memory/" + ThemeManager::themePath() + "/SR-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 S and R inputs.
    void updateLogic() override;
};

