<?php
declare(strict_types = 1);
namespace Meramo\mrm_be\Form\Element;

use \TYPO3\CMS\Backend\Form\Element\AbstractFormElement;

class PagesDkzSelector extends AbstractFormElement
{
    public function render()
    {
        // Custom TCA properties and other data can be found in $this->data, for example the above
        // parameters are available in $this->data['parameterArray']['fieldConf']['config']['parameters']
        $result = $this->initializeResultArray();
        $html = array(
          '<div class="formengine-field-item t3js-formengine-field-item">',
            '<div class="form-control-wrap" style="max-width: 100%;">',
              '<div class="form-wizards-wrap">',
                '<div class="form-wizards-element">',
                  '<div class="form-control-clearable">',
                    '<script type="application/javascript">window.dkzFormElementId="'.$this->data['parameterArray']['itemFormElID'].'";</script>',
                    '<input class="form-control mrm_be_dkz_form_hidden" type="text" name="'.$this->data['parameterArray']['itemFormElName'].'" id="'.$this->data['parameterArray']['itemFormElID'].'" value="'.$this->data['parameterArray']['itemFormElValue'].'" />',
                  '</div>',
                '</div>',
              '</div>',
            '</div>',
          '</div>',
          '<script type="application/javascript" src="/typo3conf/ext/mrm_be/Resources/Public/Javascript/dkz_page_tree.js"></script>',
          '<link rel="stylesheet" type="text/css" href="/typo3conf/ext/mrm_be/Resources/Public/Css/dkz_page_tree.css" media="all" >',
        );
        $result['html'] = implode('', $html);
//        $this->log($result, false);
//        $this->log($this->data['parameterArray'], false);
        return $result;
    }

    private function log($msg, $isString = true){
      if(!$isString){
        $msg = json_encode($msg, JSON_PRETTY_PRINT);
      }
      file_put_contents('/var/www/html/typo3temp/debug.log', "--- Form/Element/PagesDkzSelector ---".PHP_EOL.$msg.PHP_EOL, FILE_APPEND);
    }
}
