<?php

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

use DropshippingExportFreeVendor\WPDesk\View\Renderer\Renderer;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Factory\DataProviderFactory;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Factory\ViewActionFactory;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Form\ExportOptionsForm;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Helper\PluginHelper;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Infrastructure\Request\Request;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Infrastructure\Service\Listener\Items\Initable\Initable;
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\Action\Process\Form\ExportOptionsFormProcessAction;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Infrastructure\View\FormView;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\DataProvider\ExportOptionsDataProvider;
/**
 *
 * @package WPDesk\Library\DropshippingExport\Action\View
 */
class ExportOptionsViewAction implements Displayable, Registrable, Initable
{
    /**
     * @var Renderer
     */
    private $renderer;
    /**
     * @var PluginHelper
     */
    private $plugin_helper;
    /**
     * @var Request
     */
    private $request;
    /**
     * @var ViewActionFactory
     */
    private $view_factory;
    /**
     * @var ExportOptionsForm
     */
    private $form;
    /**
     * @var DataProviderFactory
     */
    private $data_provider_factory;
    public function __construct(Request $request, Renderer $renderer, ExportOptionsForm $form, ViewActionFactory $view_factory, DataProviderFactory $data_provider_factory, PluginHelper $helper)
    {
        $this->renderer = $renderer;
        $this->plugin_helper = $helper;
        $this->request = $request;
        $this->view_factory = $view_factory;
        $this->form = $form;
        $this->data_provider_factory = $data_provider_factory;
    }
    public function register(): array
    {
        return [ExportOptionsFormProcessAction::class];
    }
    public function init()
    {
        $uid = $this->request->get_param('get.uid')->get();
        $data_provider = $this->data_provider_factory->create_by_class_name(ExportOptionsDataProvider::class, ['postfix' => $uid]);
        $this->form->set_data($data_provider);
    }
    public function show()
    {
        $uid = $this->request->get_param('get.uid')->get();
        $data = ['title' => __('Export options', 'dropshipping-export-free'), 'form' => new FormView($this->form, $this->renderer), 'previous_step' => $this->plugin_helper->generate_url_by_view(ExportMapperViewAction::class, ['uid' => $this->request->get_param('get.uid')->get()]), 'edit' => $this->request->get_param('get.mode')->getAsString() === 'edit', 'mode' => $this->request->get_param('get.mode')->getAsString(), 'renderer' => $this->renderer];
        $this->renderer->output_render('Export/Options', $data);
    }
}
