<?php

namespace DropshippingXmlFreeVendor\WPDesk\Library\DropshippingXmlCore\Action\Loader\Notification;

use DropshippingXmlFreeVendor\WPDesk\Library\DropshippingXmlCore\Infrastructure\Service\Listener\Items\Hookable\Hookable;
use DropshippingXmlFreeVendor\WPDesk\Library\DropshippingXmlCore\Service\Limiter\FileSizeLimiterService;
/**
 * Class FileLimitNotificationAction.
 */
class FileLimitNotificationAction implements Hookable
{
    const FILTER_FILES_LIMIT_MESSAGE = 'wpdesk_dropshipping_files_limit_message';
    private FileSizeLimiterService $file_limit_service;
    public function __construct(FileSizeLimiterService $file_limit_service)
    {
        $this->file_limit_service = $file_limit_service;
    }
    public function hooks()
    {
        add_action('admin_init', function () {
            if ($this->file_limit_service->is_file_limit_reached()) {
                add_action('admin_notices', [$this, 'show_error_notification'], 10);
            }
        });
    }
    public function show_error_notification()
    {
        $max_file_size_message = \apply_filters(self::FILTER_FILES_LIMIT_MESSAGE, __('You have reached the maximum file size limit in the dropshipping xml plugin. Delete old imports and remove images to be able to create new ones.', 'dropshipping-xml-for-woocommerce'));
        $class = 'notice notice-error';
        printf('<div class="%1$s"><p>%2$s</p></div>', esc_attr($class), esc_html($max_file_size_message));
    }
}
