<?php
	/**
	 * @package     Joomla\Component\Formea\Plugins\Core\Multipage\Field
	 * @subpackage
	 *
	 * @copyright   A copyright
	 * @license     A "Slug" license name e.g. GPL2
	 */

	namespace Joomla\Component\Formea\Plugins\Core\Multipage\Field;

	use Joomla\CMS\Form\FormField;
  use Joomla\CMS\Language\Multilanguage;
  use Joomla\Component\Formea\Site\Helper\FormeaGeneralHelper;
  use Joomla\Registry\Registry;

  class MpButtonTextField extends FormField
	{
    /**
     * The name field type.
     *
     * @var    string
     */
    protected $type = 'MpButtonText';

    /**
     * Method to get the field input markup for the file field.
     * Field attributes allow specification of a maximum file size and a string
     * of accepted file extensions.
     *
     * @return  string  The field input markup.
     *
     * @note    The field does not include an upload mechanism.
     * @see     \Joomla\CMS\Form\Field\MediaField
     * @since   1.7.0
     */
    protected function getInput()
    {


      /*$value = '[]';
      if (!empty($this->value))
      {
        if(!is_string($this->value)){
          $value = (new Registry($this->value))->toArray();
          $value = json_encode($value);
        }else{
          $value = $this->value;
        }
      }*/
      $value = new Registry([]);
      if (!empty($this->value))
      {
        $value = new Registry($this->value);
      }
      $langLists                      = FormeaGeneralHelper::getLanguages();
      $langLists = array_reverse($langLists);
      $totalLang = count($langLists);
      $input = '<table class="table">';
      $input .='<thead><tr><th style="width: 100px;"></th><th>Previous</th><th>Next</th><th>Submit</th></tr></thead>';
      $input .='<tbody>';
      for($i = 0; $i < $totalLang; $i++) {
        $name = $this->name.'['.$langLists[$i]->lang_code.']';
        $input .='<tr>';
        $input .='<th>'.strtoupper($langLists[$i]->lang_code).'</th>';
        $input .='<td><input type="text" class="form-control" name="'.$name.'[prev]" value="'.htmlspecialchars($value->get($langLists[$i]->lang_code.'.prev','JPREVIOUS')).'" style="width:100%" /></td>';
        $input .='<td><input type="text" class="form-control" name="'.$name.'[next]" value="'.htmlspecialchars($value->get($langLists[$i]->lang_code.'.next','JNEXT')).'" style="width:100%" /></td>';
        $input .='<td><input type="text" class="form-control" name="'.$name.'[submit]" value="'.htmlspecialchars($value->get($langLists[$i]->lang_code.'.submit','JSUBMIT')).'" style="width:100%" /></td>';
        $input .='</tr>';
      }
      $input .='</tbody>';
      $input .='</table>';


      return $input;
    }

	}
