<?php

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

use DropshippingExportFreeVendor\WPDesk\View\Renderer\Renderer;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Form\ExportManagerForm;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Helper\PluginHelper;
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\DAO\ExportDAO;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Action\Process\Form\ExportManagerFormProcessAction;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Action\Process\ExportManagerActivateProcessAction;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Action\Process\ExportManagerCloneProcessAction;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Action\Process\ExportManagerDeleteProcessAction;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Action\Process\ExportManagerStopProcessAction;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Service\Locator\FileLocatorService;
/**
 * Class ImportManagerViewAction, import manager view action.
 *
 * @package WPDesk\Library\DropshippingExport\Action\View
 */
class ExportManagerViewAction implements Displayable, Registrable
{
    const MANAGER_NONCE = 'nonce_export_manager';
    /**
     * @var Renderer
     */
    private $renderer;
    /**
     * @var ExportManagerForm
     */
    private $form;
    /**
     * @var ExportDAO
     */
    private $export_dao;
    /**
     * @var PluginHelper
     */
    private $plugin_helper;
    /**
     *
     * @var FileLocatorService
     */
    private $file_locator;
    public function __construct(Renderer $renderer, ExportManagerForm $form, ExportDAO $export_dao, PluginHelper $helper, FileLocatorService $file_locator)
    {
        $this->renderer = $renderer;
        $this->form = $form;
        $this->export_dao = $export_dao;
        $this->plugin_helper = $helper;
        $this->file_locator = $file_locator;
    }
    public function register(): array
    {
        return [ExportManagerFormProcessAction::class, ExportManagerDeleteProcessAction::class, ExportManagerStopProcessAction::class, ExportManagerActivateProcessAction::class, ExportManagerCloneProcessAction::class];
    }
    public function show()
    {
        $exports = $this->export_dao->get_all();
        $imports_count = count($exports);
        $element = $imports_count > 1 ? __('elements', 'dropshipping-export-free') : __('element', 'dropshipping-export-free');
        $import_url = $this->plugin_helper->generate_url_by_view(ExportTypeViewAction::class);
        $data = ['title' => __('Export Manager', 'dropshipping-export-free'), 'import_url' => $import_url, 'header_url' => '<a href="' . $import_url . '" class="page-title-action" target="_self">' . __('create new', 'dropshipping-export-free') . '</a>', 'form' => new FormView($this->form, $this->renderer), 'exports' => $exports, 'elements' => strval($imports_count) . ' ' . $element, 'nonce' => wp_create_nonce(self::MANAGER_NONCE), 'plugin_helper' => $this->plugin_helper, 'renderer' => $this->renderer, 'file_locator' => $this->file_locator];
        $this->renderer->output_render('Export/ExportManager', $data);
    }
}
