<?php 
/* 
* Block Name: List
* Post Type: page, post
*/
if (!isset($block['data']['previewImage']))
{
    // Enable script and style
    wp_enqueue_style('block-style-counter');

    // Include helpers
    include get_template_directory() . '/inc/block-helper.php';

    // Get assinged values
    $list = get_field('list') ?: false;
    $cols = get_field('items_per_row') ?: false;
    $align = get_field('align') ?: '';
    $type = get_field('list_type') ?: false;
?>
    <section class="section list-section-wrapper block<?php echo $className; ?>" id="<?php echo $sectionId; ?>">
        <div class="container">
            <?php if ($title): ?>
                <h2 class="d-block text-center"><?php echo $title; ?></h2>
            <?php endif; ?>
            <?php if ($text): ?>
                <div class="text text-center pb-5">
                    <?php echo $text; ?>
                </div>
            <?php endif; ?>
            <div class="row g-2 d-flex <?php echo $align; ?>">
                <?php if ($list && is_array($list)): ?>
                    <?php foreach ($list as $no => $item): ?>
                        <?php if (array_key_exists('text', $item) && $itemText = $item['text']): ?>
                            <div class="<?php echo $cols; ?>">
                                <div class="item h-100 d-md-flex align-items-center">
                                    <?php 
                                        switch ($type) {
                                            case 'number':
                                                echo '<strong class="icon number pe-3">' . ($no + 1) . '.</strong>';
                                                break;

                                            case 'check':
                                                echo '<i class="fa fa-check icon pe-3"></i>';
                                                break;
                                        }
                                    ?>
                                    <?php echo $itemText; ?>
                                </div>
                            </div>
                        <?php endif ?>
                    <?php endforeach ?>
                <?php endif ?>
            </div>
        </div>
    </section>
<?php 
} else {
    $path = str_replace([$_SERVER['DOCUMENT_ROOT'], '\\', '.php'], ['', '/', '.png'], __FILE__);
    $url = home_url($path);

    echo "<img src=\"{$url}\" style=\"width:100%; height:auto;\">";
}
