<?php

namespace Drupal\restaurant_settings\Form;

use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\restaurant\Form\AppForm;
use Drupal\restaurant\Form\Heading;

class Confirmemail extends AppForm {

  /**
   * 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 'confirm_email';
  }

  public function buildForm(array $form, FormStateInterface $form_state)
  {
    
    Heading::addHeading($form, 'Email template');
      
    $template = $this->conn->query("SELECT data FROM restaurant_settings WHERE name = ?", array('emailtemplate'))->fetchField();
    
    $form['data'] = array(
        '#type' => 'textarea',
        '#default_value' => $template,
        '#description' => $this->t('Email template for booking email'),
        '#attributes' => array('rows' => 15),
        '#required' => true
    );
    
    $form['submit'] = array(
        '#type' => 'submit',
        '#value' => 'Save'
    );
    
    
    return $form;
  }


  public function submitForm(array &$form, FormStateInterface $form_state)
  {
      $this->conn->update('restaurant_settings')->fields(array('data' => $form_state->getValue('data')))->condition('name', 'emailtemplate', '=')->execute();
      $this->addMessage("Thank you, your email template has been updated");
  }

}
