<?php

namespace Drupal\restaurant_bookings\Controller;



use Drupal\restaurant\Controller\AppController;
use Drupal\restaurant\Date\Date;
use Drupal\restaurant\Bookings\Booking;
use Drupal\restaurant_bookings\Form\Guests;
//use Drupal\restaurant_bookings\Guests;


class RestaurantBookingsController extends AppController
{

  public function __construct()
  {
    parent::__construct();
    $this->setPath('restaurant_bookings' . DIRECTORY_SEPARATOR . 'HtmlScripts' . DIRECTORY_SEPARATOR);
  }

  public function delete()
  {
    if ($this->hasParam('bookingid')) {
      $this->conn->delete('restaurant_bookings')->condition('id', $this->getParam('bookingid'), '=')->execute();
      $this->addMessage("Booking deleted", "success")->http_redirect('/admin/restaurant/bookings');
    }
  }

  public function index()
  {

    $bookings = new Booking();

    $date = date("Y-m-d");
    $times = $this->db->fetchCol("SELECT DISTINCT bookingtime from restaurant_bookings WHERE '$date' = DATE(bookingtime)");

    $bookings = array();
    foreach ($times as $key => $val) {
      $bookings[$key]['time'] = date('H:i', strtotime($val));
    }

    return $this->render('index.phtml');
  }

  public function confirm()
  {
      return array();
  }

  public function ajax()
  {
  		if ($this->getSetting('requirelogin')) {

            if (! \Drupal::currentUser()->isAuthenticated()) {
        	   $this->addMessage($this->t('Login required to make a booking'), 'error')->http_redirect('/user/login');
      	    }
    	}

/*$html = <<<HTML
<div id="bookings-div">



<div class="dialog-off-canvas-main-canvas" data-off-canvas-main-canvas>
      <div>
    <div id="block-ajax-content">


      <form class="ajax-front" data-drupal-selector="ajax-front" action="big_pipe_nojs_placeholder_attribute_safe:form_action_p_pvdeGsVG5zNF_XLGPTvYSKCf43t8qZYSwcfZl2uzM" method="post" id="ajax-front" accept-charset="UTF-8">
  <div class="padd2">    		<div class="dialog-off-canvas-main-canvas" data-off-canvas-main-canvas>
      <div>
    <div id="block-ajax-content">



  <div class="padd2"></div><div id="bookings-left-col"></div><div id="bookings-right-col"></div><div></div>





  </div>

  </div>

  </div>
</div><div id="bookings-left-col"></div><div id="bookings-right-col"></div><div></div><input autocomplete="off" data-drupal-selector="form-petje-ui8-oucxwotl3tbwacgsosrxx6vg6ehhj36o" type="hidden" name="form_build_id" value="form--pEtjE_ui8-OuCXWoTL3tbwAcgsosRXX6vg6ehhj36o" />
<input data-drupal-selector="edit-ajax-front-form-token" type="hidden" name="form_token" value="big_pipe_nojs_placeholder_attribute_safe:form_token_placeholder_FLipWHUudd6Hcj8cJVkWyUTfBNMQsn9O14EOnvQIO7U" />
<input data-drupal-selector="edit-ajax-front" type="hidden" name="form_id" value="ajax_front" />

</form>

  </div>

  </div>

  </div>

  </div>



HTML; */
$html = <<<HTML
<div id="bookings-div">
</div>
HTML;

      return array('#markup' => $this->t($html));

    	$this->getSession()->set('guests', 1);
    	$this->getSession()->set('date', time());

    	return array('#markup' => $this->t('<div id="bookings-div"></div>'));

  }




}
