<?php

namespace Internetgalerie\IgDatapoolFe\ViewHelpers\Form\FileReference;

use Internetgalerie\IgDatapoolFe\ViewHelpers\Form\AbstractFileReferenceViewHelper;

/**
 * Renders an AJAX File Field in a FileReference.
 */
class FileViewHelper extends AbstractFileReferenceViewHelper
{
    /**
     * Initialize the arguments.
     *
     * @return void
     * @api
     */
    public function initializeArguments(): void
    {
        parent::initializeArguments();
        $this->registerArgument('defaultLangValue', 'string', 'language Value');
    }

    /**
     * Renders the upload field with possible resource pointer
     *
     * @return string
     * @api
     */
    public function render(): string
    {
        $this->pageRenderer->loadJavaScriptModule('@dp/elements/upload.js');
        $this->formUtility->addJsFooter();
        $this->prepareOptions();

        if ($this->dragAndDrop) {
            $this->cssClasses[]='dp-dropzone';
        }

        $value = $this->getValueAttribute();
        return $this->renderHtml($value);
    }



    protected function renderInputFields($currentValue, $options)
    {
        $this->registerFieldNameForFormTokenGeneration($this->getName());
        return $this->formUtility->renderFileInputFields($this->getName(), $currentValue, $options);
    }



}
