<?php

namespace Drupal\restaurant_bookings\Form;

use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\restaurant\Form\AppForm;
use Drupal\restaurant\Bookings\Booking;
use Drupal\restaurant\Form\MultipartForm;

class Cancel extends MultipartForm {

  /**
   * Returns a unique string identifying the form.
   *
   * The returned ID should be a unique string that can be a valid PHP function
   * name, since it's used in hook implementation names such as
   * hook_form_FORM_ID_alter().
   *
   * @return string
   *   The unique string identifying the form.
   */
  public function getFormId() {
    return 'cancel_booking';
  }
  
  public function buildForm(array $form, FormStateInterface $form_state)
  {
     
     if (isset ($_GET['ref'])) {
     	
     		$form['submit'] = array(
     					'#type' => 'submit',
     					'#value' => 'Delete Booking'
     			);
     		
     }
     return $form;
  }
  
  public function submitForm(array &$form, FormStateInterface $form_state)
  {
      if (isset ($_GET['ref'])) {
      	$result = $this->conn->delete('restaurant_bookings')->condition('id', $_GET['ref'])->execute();
			$this->service->addMessage('Booking with reference No. <strong> ' . $_GET['ref'] . '</strong> deleted', 'error');
      }
  }
  
}