<?php

/**
 * @author          Tassos Marinos <info@tassos.gr>
 * @link            https://www.tassos.gr
 * @copyright       Copyright © 2024 Tassos All Rights Reserved
 * @license         GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/

// No direct access to this file
defined('_JEXEC') or die;

use Joomla\CMS\Component\ComponentHelper;

require_once JPATH_PLUGINS . '/system/nrframework/fields/conditionbuilder.php';

class JFormFieldSPConditionBuilder extends JFormFieldConditionBuilder
{
    /**
     * Returns the field options.
     * 
     * @return  array
     */
    protected function getOptions()
    {
        $exclude_rules = (string) $this->element['exclude_rules'];

        $params = ComponentHelper::getParams('com_smilepack');
        $context = $this->form->getName();
        $isBackendModule = $params->get('display_conditions_enabled', '1') === '1' && $params->get('display_conditions_support_admin_modules', '0') === '1' && $context === 'com_modules.module.admin';
        if ($isBackendModule)
        {
            $exclude_rules = [
                'Component\ContentArticle',
                'Component\ContentCategory',
                'Component\ContentView',
                'Component\VirtueMartCartContainsProducts',
                'Component\VirtueMartCartContainsXProducts',
                'Component\VirtueMartCartValue',
                'Component\VirtueMartSingle',
                'Component\VirtueMartCategory',
                'Component\VirtueMartCurrentProductPrice',
                'Component\VirtueMartCurrentProductStock',
                'Component\VirtueMartCategoryView',
                'Component\VirtueMartPurchasedProduct',
                'Component\VirtueMartLastPurchasedDate',
                'Component\VirtueMartTotalSpend',
                'Component\HikashopCartContainsProducts',
                'Component\HikashopCartContainsXProducts',
                'Component\HikashopCartValue',
                'Component\HikashopSingle',
                'Component\HikashopCategory',
                'Component\HikashopCurrentProductPrice',
                'Component\HikashopCurrentProductStock',
                'Component\HikashopCategoryView',
                'Component\HikashopPurchasedProduct',
                'Component\HikashopLastPurchasedDate',
                'Component\HikashopTotalSpend',
                'Homepage',
                'Joomla\Menu',
                'Joomla\Component',
                'Pageviews',
                'TimeOnSite',
                'ReturningNewVisitor'
            ];
            $exclude_rules = implode(',', $exclude_rules);
        }

        $options = [
            'include_rules' => (string) $this->element['include_rules'],
            'exclude_rules' => $exclude_rules,
            'exclude_rules_pro' => 'false'
        ];
        
        return $options;
    }
}