<?php

namespace DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Action\View;

use DropshippingExportFreeVendor\WPDesk\View\Renderer\Renderer;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Form\ExportFileTypeForm;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Infrastructure\Service\Listener\Items\Registrable\Registrable;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Infrastructure\View\Abstraction\Displayable;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Infrastructure\View\FormView;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Action\Process\Form\ExportTypeFormProcessAction;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\DataProvider\ExportFileTypeDataProvider;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\View\ImportFileView;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Infrastructure\Service\Listener\Items\Initable\Initable;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Factory\DataProviderFactory;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Infrastructure\Request\Request;
/**
 * Class ImportFileViewAction, import file view action.
 *
 * @package WPDesk\Library\DropshippingExport\Action\View
 */
class ExportTypeViewAction implements Displayable, Registrable, Initable
{
    /**
     * @var Renderer
     */
    private $renderer;
    /**
     * @var ExportFileTypeForm
     */
    private $form;
    /**
     * @var DataProviderFactory
     */
    private $data_provider_factory;
    /**
     * @var Request
     */
    private $request;
    public function __construct(Request $request, Renderer $renderer, ExportFileTypeForm $form, DataProviderFactory $data_provider_factory)
    {
        $this->request = $request;
        $this->renderer = $renderer;
        $this->form = $form;
        $this->data_provider_factory = $data_provider_factory;
    }
    public function register(): array
    {
        return [ExportTypeFormProcessAction::class];
    }
    public function init()
    {
        $uid = $this->request->get_param('get.uid')->getAsString();
        if (!empty($uid)) {
            $data_provider = $this->data_provider_factory->create_by_class_name(ExportFileTypeDataProvider::class, ['postfix' => $uid]);
            $this->form->set_data($data_provider);
        }
    }
    public function show()
    {
        $mode = $this->request->get_param('get.mode')->getAsString();
        $data = ['title' => __('Export', 'dropshipping-export-free'), 'mode' => $mode, 'edit' => \false, 'has_ftp_addon' => \false, 'form' => new FormView($this->form, $this->renderer), 'renderer' => $this->renderer];
        $this->renderer->output_render('Export/ExportType', $data);
    }
}
