#pragma once

#include <QPoint>

#include "BuildingId.h"
#include "SelectionContent.h"
#include "SelectionContentFactory.h"

class QLabel;
class QListWidget;

// The card for a Splitter (REQ-UI-SELECTION-CONTENT): its two per-output item filters
// (REQ-BLD-SPLITTER) plus the clear action every belt-subsystem tile has
// (REQ-UI-BELT-CLEAR).
//
// The filters are configuration, so they are shown for a construction site too and set
// through the site's own command (REQ-BLD-SITE-CONFIG); the clear action is runtime and
// therefore is not, because a site's tile is not registered with the belt subsystem yet.
class SplitterContent : public SelectionContent
{
    Q_OBJECT

public:
    SplitterContent(const SelectionContext& context, const SelectionRequest& request,
                    QWidget* parent = nullptr);

protected:
    void refreshConfiguration() override;
    void refreshRuntime() override {}

private:
    // Sends the checked items of both lists as the splitter's new filters. Routed to the
    // site command or the live command depending on what the id names.
    void applyFilters();
    // Rebuilds both lists from the splitter's current outputs and filters. Only run when
    // the lists are not already populated, so a per-tick refresh cannot uncheck a box
    // the player is in the middle of clicking.
    void populateFilters();

    BuildingId   m_id;
    bool         m_isSite;
    QPoint       m_tile;
    QLabel*      m_filterALabel;
    QListWidget* m_filterAList;
    QLabel*      m_filterBLabel;
    QListWidget* m_filterBList;
};
