<?php
slot('title', __('Каталог'));
include_partial('main/breadcrumbs');
echo '<h1 class="content_title">' . __('Каталог') . '</h1>';
?>
<div class="catalog_wrap">
    <?php
    if (count($catalogs) > 0) {
        foreach ($catalogs as $cat) {
            ?><div class="catalog_category_item">
                <table class="to_div" cellpadding="0" cellspacing="0" width="100%" height="100%">
                    <tbody align="left" valign="top">
                    <tr>
                        <td width="1" class="mobile_hide">
                            <?php
                            if (strlen($cat['photo']) > 3) {
                                echo '<a href="' . url_for('@catalog_show?alias=' . $cat['alias']) . '" style="border-bottom:none;"><img src="/i/n.gif" style="background-image: url(/u/i/' . Page::replaceImageSize($cat['photo'], 'S') . ');" /></a>';
                            } else {
                                echo '<a href="' . url_for('@catalog_show?alias=' . $cat['alias']) . '" style="border-bottom:none;"><img src="/i/n.gif" style="background-image: url(/i/no_photo.png);" /></a>';
                            }
                            ?>
                        </td>
                        <td width="24"></td>
                        <td class="align_center">
                            <?php echo '<a href="' . url_for('@catalog_show?alias=' . $cat['alias']) . '" class="catalog_category_item__title black_link">' . $cat['Translation'][$culture]['title'] . '</a>'; ?>

                            <div class="mobile">
                                <i class="br20"></i>
                                <?php if (strlen($cat['photo']) > 3) {
                                    echo '<a href="' . url_for('@catalog_show?alias=' . $cat['alias']) . '" style="border-bottom:none;"><img src="/i/n.gif" style="background-image: url(/u/i/' . Page::replaceImageSize($cat['photo'], 'S') . ');" /></a>';
                                } else {
                                    echo '<a href="' . url_for('@catalog_show?alias=' . $cat['alias']) . '" style="border-bottom:none;"><img src="/i/n.gif" style="background-image: url(/i/no_photo.png);" /></a>';
                                } ?>
                            </div>

                            <?php $products_html = '';

                            if (strpos($cat['alias'], 'kamen') !== false && count($cat['Products']) > 0) {
                                $counter = 0;
                                foreach ($cat['Products'] as $product){
                                    if($product['offer_count'] == 0 || !$product['is_detail']){
                                        continue;
                                    }
                                    $products_html .= '<td><a href="' . url_for('@product_show?alias=' . $product['alias']) . '" class="black_link">' . $product['Translation'][$culture]['title'] . '</a></td>';
                                    if ($counter > 0) {
                                        $products_html .= '</tr><tr>';
                                        $counter = 0;
                                    } else {
                                        $products_html .= '<td width="24"></td>';
                                        $counter++;
                                    }
                                }
                                if($products_html != ''){
                                    echo '<table cellspacing="0" cellpadding="0" class="catalog_category_item__childs align_left">';
                                    echo '<tbody valign="top" align="left">';
                                    echo '<tr>' . $products_html . '</tr>';
                                    echo '</tbody>';
                                    echo '</table>';
                                }
                            }

                            if(count($cat['Children']) > 0) {
                                $counter = 0;
                                foreach ($cat['Children'] as $child){
                                    $products_html .= '<td><a href="' . url_for('@catalog_show?alias=' . $child['alias']) . '" class="black_link">' . $child['Translation'][$culture]['title'] . '</a></td>';
                                    if ($counter > 0) {
                                        $products_html .= '</tr><tr>';
                                        $counter = 0;
                                    } else {
                                        $products_html .= '<td width="24"></td>';
                                        $counter++;
                                    }
                                }
                                if($products_html != ''){
                                    echo '<table cellspacing="0" cellpadding="0" class="catalog_category_item__childs">';
                                    echo '<tbody valign="top" align="left">';
                                    echo '<tr>' . $products_html . '</tr>';
                                    echo '</tbody>';
                                    echo '</table>';
                                }
                            }
                            ?>
                        </td>
                    </tr>
                    </tbody>
                </table>
            </div><?php
        }
    }
    ?>
</div>