<?php
/**
 * FW Food menu 5.1.1
 * @copyright (C) 2020 Fastw3b
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
 * @link http://www.fastw3b.net/ Official website
 **/

defined( '_JEXEC' ) or die( 'Restricted access' );

$view = $displayData['view'];

$qty = $displayData['qty'];
$cat = $displayData['cat'];
$col_qty = $displayData['col_qty'];
$align_by = $displayData['align_by'];

$num = 0;
$cols_displayed = 1;

$items_per_column = max(1, round($qty/$col_qty));
$shift = max(0, $qty - $items_per_column * $col_qty);
$view->prev_subcategory_id = 0;

?>
						<div class="fwfm-col">
<?php
foreach ($cat->_items as $i=>$row) {
	$view->row = $row;
	if (isset($row->type)) {
		$view->params = new JFParams($row->params, fwFoodMenuHelper::getParentCategories($row->parent));
		if ($align_by != 'meal' and $num > 0) {
			if (!empty($view->prev_subcategory_id)) {
?>
								</div>
							</div>
<?php
			}
?>
						</div>
						<div class="fwfm-col">
<?php
			$view->prev_subcategory_id = 0;
		}
		echo fwFoodMenuHelper::loadTemplate('menu.subcategoryitem', array('view'=>$view));
	} else {
		echo fwFoodMenuHelper::loadTemplate('menu.menuitem', array('view'=>$view));
		$num++;

		if ($align_by == 'meal' and ($num - $shift) and (($num - $shift) % $items_per_column) == 0 and $cols_displayed < $col_qty) {
			$cols_displayed++;
			if (!empty($view->prev_subcategory_id)) {
?>
								</div>
							</div>
<?php
			}
?>
						</div>
						<div class="fwfm-col">
<?php
			if (!empty($view->prev_subcategory_id)) {
				if (!empty($cat->_items[$i + 1]) and empty($cat->_items[$i + 1]->type)) {
?>
						<div class="fwfm-subcategory-item fwfm-subcategory-item-continue">
							<div class="fwfm-subcategory-meals">
<?php
				} else {
					$view->prev_subcategory_id = 0;
				}
			}
		}
	}
}
if (!empty($view->prev_subcategory_id)) {
?>
							</div>
<?php
	if (!empty($view->subcat_description) and $view->subcat_description_position == 'bottom') {
?>
							<div class="fwfm-subcategory-text">
								<?php echo $view->subcat_description; ?>
							</div>
<?php
	}
?>
						</div>
<?php
}
?>
						</div>
