#pragma once

#include <DNSServer.h>

#include <ESPUI.h>              // https://github.com/s00500/ESPUI
#include <ArduinoJson.h>

#include "common.h"
#include "syringe.h"
#include "syringefilled.h"

#include <EEPROM.h>


class Web
{

private :

//Create tabs
 uint16_t configurations, new_syringe, features;

//***ABOVE***//

 int status_syringe_pump;
 uint16_t stop_syringe_pump;

 int status_syringe_filled_placement;
 uint16_t syringe_filled_placement;

 int status_limit_switch;

 uint16_t calibration, fast_backward, fast_forward, slow_backward, slow_forward, confirm_initialisation;

 uint16_t volume_exchange_mL_label, volume_exchange_mL, exchange_throughtput_uL_per_min_or_duration_sec_label, exchange_throughtput_uL_per_min_or_duration_sec, throughput_or_duration, label_push_pull_choice, switch_push_pull_choice, start_exchange;

 uint16_t label_remaining_volume_mL, label_remaining_time_sec;
 uint16_t remaining_volume_mL, remaining_time_sec;

//Configurations
 uint16_t syringe_selection, syringe_ref, syringe_brand, syringe_volume_mL, syringe_diameter_mm, initial_volume_mL_label, initial_volume_mL, choose_syringe, load_syringe_json;

 uint16_t option_nb = 0;
 uint16_t options_id[20];

 float syringe_volume_mL_value, syringe_diameter_mm_value;

 std::string syringe_volume_mL_string, syringe_diameter_mm_string;

//New_syringe
 uint16_t name_new_syringe, name_new_syringe_label, internal_diameter_mm_new_syringe, internal_diameter_mm_new_syringe_label, total_volume_mL_new_syringe, total_volume_mL_new_syringe_label, save_syringe, save_syringe_label;
 String name_new_syringe_value, total_volume_mL_new_syringe_value, internal_diameter_mm_new_syringe_value;

//Features
 uint16_t syringe_pump_length_mm_value;
 uint16_t lead_screw_pitch_mm, clockwise_equals_push_label, clockwise_equals_push, microstep_configuration, motor_steps, motor_release, motor_release_label;


//Other
 String select_value;

 char couleur1[30], couleur2[30], couleur3[30], couleur4[30], couleur5[30], couleur6[30], couleur7[30], couleur8[30], couleur9[30], couleur10[30];

 long unsigned last_time;

// Couleurs à utiliser
 const char* couleurs[10];



public :

 void web_setup();
 void web_loop();


/************CALLBACK_METHODS****************/

//GENERAL CALLBACKS//
 void number_callback(Control* sender, int type);

//SPECIFIC CALLBACKS//

//***ABOVE***//
 void stop_syringe_pump_callback (Control* sender, int value);
 void syringe_filled_placement_callback (Control* sender, int value);
 void calibration_callback(Control* sender, int type);
 void fast_backward_callback (Control *sender, int type);
 void fast_forward_callback (Control *sender, int type);
 void slow_backward_callback (Control *sender, int type);
 void slow_forward_callback (Control *senmotor_release_labelder, int type);
 void confirm_initialisation_callback (Control *sender, int type);
 void volume_exchange_mL_callback (Control* sender, int value);
 void exchange_throughtput_uL_per_min_or_duration_sec_callback (Control* sender, int value);
 void throughput_or_duration_callback (Control *sender, int type);
 void switch_push_pull_choice_callback (Control* sender, int value);
 void remaining_volume_mL_callback (Control* sender, int value);
 void remaining_time_sec_callback (Control* sender, int value);
 void start_exchange_callback (Control* sender, int value);

//Configurations
 void choose_syringe_callback (Control* sender, int value);
 void load_syringe_json_callback (Control* sender, int value);
 void initial_volume_mL_callback (Control* sender, int value);

 void name_new_syringe_callback(Control* sender, int type);
 void total_volume_mL_new_syringe_callback(Control* sender, int type);
 void internal_diameter_mm_new_syringe_callback(Control* sender, int type);
 void save_syringe_callback (Control* sender, int value);

//features : Configurations avancées
 void syringe_pump_length_mm_callback(Control* sender, int type);
 void clockwise_equals_push_callback(Control* sender, int value);
 void microstep_configuration_callback(Control* sender, int type);
 void motor_steps_callback(Control* sender, int type);
 void motor_release_callback(Control* sender, int type);

//
 void syringe_selection_callback(Control* sender, int value);



//ON_OFF METHODS
 void syringe_pump_on_off();



//STYLE_METHODS
 void style (uint16_t id, int style);
 void set_initial_style();
 void set_theme(int theme);
 void style_syringe_pump_on();
 void style_syringe_pump_off();
 void style_syringe_filled_placement_on();
 void style_syringe_filled_placement_off();
 void style_initialisation(int style_choice);
 void style_exchange_configuration(int style_choice);


//OTHER_METHODS
 void select_syringe_update(uint16_t tab);
 void number_max_min(int min, int max, uint16_t control);
 void motor_release_action();
 void serial_print (String name, Control* sender);

};