#pragma once

#include <QPoint>

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

class BeltItemList;
class QLabel;
class QListWidget;

// The card for a single selected Splitter (REQ-UI-SELECTION-CONTENT): its two per-output
// item filters (REQ-BLD-SPLITTER), then what it is holding and the clear action every
// belt-subsystem tile has (REQ-UI-BELT-ITEMS, REQ-UI-BELT-CLEAR).
//
// Only for a splitter selected on its own. The filters are per-object, so a selection
// holding a splitter among other belt-subsystem tiles aggregates into BeltContent and
// shows none (REQ-UI-SELECTION-AGGREGATE).
//
// 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 item list and the clear
// action are runtime and therefore are 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;
    BeltItemList* m_itemList;
    QLabel*       m_filterALabel;
    QListWidget*  m_filterAList;
    QLabel*       m_filterBLabel;
    QListWidget*  m_filterBList;
};
