<?php

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

use DropshippingExportFreeVendor\WPDesk\View\Renderer\Renderer;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Helper\PluginHelper;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Infrastructure\Request\Request;
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\DAO\ExportDAO;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Factory\DataProviderFactory;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Service\EntityCreator\ExportEntityCreatorService;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Service\Locator\FileLocatorService;
/**
 * Class ImportStatusViewAction, import status view action.
 *
 * @package WPDesk\Library\DropshippingExport\Action\View
 */
class ExportStatusViewAction implements Displayable, Registrable
{
    /**
     * @var ExportDAO
     */
    private $export_dao;
    /**
     * @var Request
     */
    private $request;
    /**
     * @var PluginHelper
     */
    private $plugin_helper;
    /**
     * @var Renderer
     */
    private $renderer;
    /**
     *
     * @var FileLocatorService
     */
    private $file_locator;
    public function __construct(Request $request, Renderer $renderer, ExportDAO $export_dao, PluginHelper $plugin_helper, FileLocatorService $file_locator, DataProviderFactory $dp_factory)
    {
        $this->export_dao = $export_dao;
        $this->request = $request;
        $this->plugin_helper = $plugin_helper;
        $this->renderer = $renderer;
        $this->file_locator = $file_locator;
    }
    public function register(): array
    {
        return [ExportEntityCreatorService::class];
    }
    public function show()
    {
        $uid = $this->request->get_param('get.uid')->getAsString();
        $export = $this->export_dao->find_by_uid($uid);
        $file_url = $this->file_locator->get_url_to_file($uid, \false);
        $zip_file_url = $this->file_locator->get_url_to_zip_file($uid, \false);
        $data = ['title' => __('Export', 'dropshipping-export-free'), 'edit' => \false, 'mode' => $this->request->get_param('get.mode')->getAsString(), 'export' => $export, 'export_manager_url' => $this->get_export_manager_url(), 'products_url' => $this->get_products_url(), 'renderer' => $this->renderer, 'file_url' => $file_url, 'zip_file_url' => $zip_file_url];
        $this->renderer->output_render('Export/ExportStatus', $data);
    }
    private function get_products_url()
    {
        return add_query_arg(['post_type' => 'product'], admin_url('edit.php'));
    }
    private function get_export_manager_url()
    {
        return $this->plugin_helper->generate_url_by_view(ExportManagerViewAction::class);
    }
}
