#ifndef QUARTZ_CLOCK_CONTROLLER_HPP_
#define QUARTZ_CLOCK_CONTROLLER_HPP_

#include <Widget/Layout/Row/Row.hpp>
#include <memory>
#include <Controller/InventoryController/InventoryController.hpp>
#include <Machine/MQuartzClock/MQuartzClock.hpp>

class QuartzClockController final : public InventoryController
{
private:
    static constexpr uint64_t maxPeriod = 60;

    std::shared_ptr<MQuartzClock> quartzClock;
    std::array<uint64_t, 4> periods = {};
    int energy = 0;

    Command<uint32_t, int> updateEnergy;
    Command<uint32_t, int, uint64_t> updatePeriod;
    Command<uint32_t, int, uint64_t> setPeriod;

    Row* makePeriodSetter(Material &icon, DataLink::Channel channel);

public:
    QuartzClockController(ControllerChannel &channel);

    void onConnect(std::shared_ptr<Machine> quartzClockMachine);

    virtual Widget* getRightPanel() override;
    virtual void update() override;
    virtual glm::vec4 getSlotHighlight(const std::string &id, int slot, ItemStack &stack) override;
};

#endif