<?php
$loader = $this->registry->get('load');
$loader->controller('product/productList');

class ControllerModuleFeatured extends ControllerProductProductList {

	public function index($setting=null) {
        $this->language->load('module/featured');

        if (!isset($setting['featured_product'])) {
            return false;
        }

        if (!isset($setting['featured_title'])) {
            $setting['featured_title'] = $this->config->get('featured_title');
        }

        if (empty($setting['featured_title'])) {
            $setting['featured_title'] = $this->language->get('heading_title');
        }

        if(!isset($setting['featured_subtitle'])){
            $setting['featured_subtitle'] = $this->config->get('featured_module')[0]["featured_subtitle"] ?? "";
        }

        $this->data['productListTitle'] = array();

        $name = str_replace('.php', '', basename( __FILE__ ));
        $index = '';
        if (isset($setting['featured_index'])) {
            $index = '&index='. $setting['featured_index'];
        }
            $link = $this->url->link(
            'product/modules_in_page',
            '&name=' . $name . $index,
            'SSL'
        );

		$this->data['heading_title'] = $setting['featured_title'];

		$this->data['grid'] = (isset($setting['entry_type'])) ? $setting['entry_type'] : 0;
		$this->data['link'] = $link;

		$this->data['productsIds'] = $setting['featured_product'];
		$this->data['product_list_title_style'] = $this->config->get('product_list_title_style');
        $this->data['Type_ProductListTitleStyle'] = $this->load->typeForTwig('Type_ProductListTitleStyle');

        $this->data['productListTitle'] = array(
            'heading_title' => $setting['featured_title'],
            'heading_subtitle' => $setting['featured_subtitle'],
            'link' => (isset($this->data['link'])) ? $this->data['link'] : '',
        );

        $this->productlistitle->setProductListTitle($this->data['productListTitle']);

        $this->childrenData = array(
            'product/productList/moduleFeatured' => $setting
        );

        $this->children = array(
            'common/product_list_title',
        );

    	$this->render('module/featured');
	}

}
