<?php
/**
 * @author 1902 Software
 * @copyright Copyright © 2023 1902 Software (https://1902software.com/magento/)
 * @package WriteTextAI_WriteTextAI
 */

declare(strict_types=1);

namespace WriteTextAI\WriteTextAI\Block\Adminhtml;

use Magento\Backend\Block\Template;
use Magento\Backend\Block\Template\Context;
use Magento\Framework\UrlInterface;
use WriteTextAI\WriteTextAI\Model\UserFieldsSelectedManager;

class InvalidImagePopup extends Template
{
    /**
     * @var UrlInterface
     */
    protected $urlBuilder;

    /**
     * @var UserFieldsSelectedManager
     */
    protected $userFieldsSelectedManager;

    /**
     * Constructor
     *
     * @param Context $context
     * @param UserFieldsSelectedManager $userFieldsSelectedManager
     * @param array $data
     */
    public function __construct(
        Context $context,
        UserFieldsSelectedManager $userFieldsSelectedManager,
        array $data = []
    ) {
        $this->userFieldsSelectedManager = $userFieldsSelectedManager;
        $this->urlBuilder = $context->getUrlBuilder();
        parent::__construct($context, $data);
    }

    /**
     * Get save URL for AJAX request
     *
     * @return string
     */
    public function getSaveUrl(): string
    {
        return $this->urlBuilder->getUrl('wtai/settings/save');
    }

    /**
     * Check if "Do not show again" is enabled (record exists)
     *
     * @return bool
     */
    public function isDoNotShowAgain(): bool
    {
        return $this->userFieldsSelectedManager->checkUserFieldsSelected(
            UserFieldsSelectedManager::ACTION_TYPE_INVALID_IMAGE_POPUP_DO_NOT_SHOW_AGAIN,
            '',
            'edit'
        );
    }
}
