#ifndef CANDIS_SCREEN_ITEMS_HPP
#define CANDIS_SCREEN_ITEMS_HPP
//----------------------------------------------------------------------------
///
/// \brief   CANDis screen showing can messages
///
///          Static table
///
/// \date   20220903
/// \author Maximilian Seesslen <mes@seesslen.net>
///
//----------------------------------------------------------------------------


//---Includes-----------------------------------------------------------------


//---Own------------------------------

#include <ocelli/screen.hpp>
#include <biwak/gdisplay.h>
#include <ocelli/clock.hpp>
#include <ocelli/button.hpp>
#include <minutnik/mn_core.hpp>
#include <mn_core.h>
#include <list>
#include <theme.hpp>


//---Declaration--------------------------------------------------------------


class CButtonItem: public OButton
{
   private:
      const CMinutnikCore::SItem &m_item;

   public:
      CSignal<void, const CMinutnikCore::SItem &> signalAddItem;

      CButtonItem( const OPoint p1, const OPoint p2, const char *text, const CMinutnikCore::SItem &item)
         : OButton( p1, p2, text, OButton::EButtonStyle::flat)
         , m_item(item)
      {
         eventSignal.connect(this,  &CButtonItem::slotItemPressed );
      }

      void slotItemPressed(const Ocelli::SEvent&)
      {
         signalAddItem.emitSignal(m_item);
      }
};


class CScreenItems: public OScreen
{

    static const CMinutnikCore::SItem eitem[];
   private:
      const int m_border=240/6;
      const int m_dist=(240-(2*m_border))/2;
      const int m_size=80;

   public:
      CButtonItem *m_pButtonItem[9];
      //CSignal<void, const SItem &> m_signalAlarm;
      CSignal<void, const CMinutnikCore::SItem &> signalAddItem;

      OPoint leftTop(int x, int y)
      {
         return( OPoint( m_border + ( x * m_dist ) - ( m_size / 2 )
                       , m_border + ( y * m_dist ) - ( m_size / 2 ) ) );
      }

      CScreenItems( );
      virtual void draw() override
      {
         OWidget::display().clear();
         OScreen::draw();
      }
      virtual void eventLoop() override
      {
      }
      void slotAddItem(const CMinutnikCore::SItem &item)
      {
         signalAddItem.emitSignal(item);
      }
      static const CMinutnikCore::SItem &getItem(int index)
      {
         return(eitem[index]);
      }
};


const CMinutnikCore::SItem CScreenItems::eitem[]
{
   {
      .duration=25,
      .description="ESPRESSO",
      .finished="IST FERTIG",
      .icon=&iconRef_coffee48_flash
   },
   {
      .duration=(5*60)+30,
      .description="WEICHES EI",
      .finished="IST FERTIG",
      .icon=&iconRef_egg48_flash
   },
   {
      .duration=60*12,
      .description="WEI\x00DFW\x00DCRST",
      .finished="SIND FERTIG",
      .icon=&iconRef_bretzel48_flash
   },
   {
      .duration=9*60,
      .description="NUDELN",
      .finished="SIND FERTIG",
      .icon= & iconRef_spaghetti48_flash
   },
   {
      .duration=9*60,
      .description="PIZZA",
      .finished="IST FERTIG",
      .icon = &iconRef_pizza48_flash
   },
   {
      .duration=120*60,
      .description="WASCHM.",
      .finished="IST FERTIG",
      .icon = &iconRef_socks48_flash
   },
   {
      .duration=12*60,
      .description="KARTOFFELN",
      .finished="SIND FERTIG",
      .icon = &iconRef_potato48_flash
   },
   {
      .duration=12*60,
      .description="FRITTEN",
      .finished="SIND FERTIG",
      .icon = &iconRef_frenchfries48_flash
   },
};


CScreenItems::CScreenItems( )
{
   for(int i1=0; i1< arraySize(eitem); i1++)
   {
      addWidget(  m_pButtonItem[i1] =
                     new CButtonItem( leftTop( i1 % 3, i1 / 3), OPoint(m_size, m_size, sizes)
                                  , eitem[i1].description, eitem[i1]) );
      m_pButtonItem[i1]->signalAddItem.connect(this, &CScreenItems::slotAddItem);

      if(eitem[i1].icon->find())
      {
         //printf("Found Icon\n");
         m_pButtonItem[i1]->setIcon( eitem[i1].icon );
      }
      else
      {
         printf("Could not find Icon\n");
      }
   }
}


//---fin----------------------------------------------------------------------
#endif // ? ! CANDIS_SCREEN_ITEMS_HPP
