<?= $this->extend('App\Views\website\index') ?>
<?= $this->section('content') ?>
<div class="container">
<?= $this->include('App\Views\website\ads\main_top') ?>
<!-- Page Content !-->
<div class="row grey lighten-2">
    <div class="col s12 ybcrumbs">
        <small>
        <a href="<?= base_url(); ?>" class="breadcrumb">Home</a>
        <a href="<?= base_url('posts'); ?>" class="breadcrumb">Posts</a>
        <a href="<?= base_url('posts/'.$post->master_category_alias); ?>" class="breadcrumb"><?= $post->master_category; ?></a>
        <a href="<?= base_url('posts/'.$post->master_category_alias.'/'.$post->category_alias); ?>" class="breadcrumb"><?= $post->category; ?></a>
        <a href="<?= base_url('posts/'.$post->master_category_alias.'/'.$post->category_alias.'/'.$post->alias); ?>" class="breadcrumb"><?= $post->title; ?></a>
        </small>
    </div>
</div><!-- Breadcrumb !-->
<div class="row">
    <div class="col l2 m2 side-stay hide-on-small-only">
        <?= $this->include('App\Views\website\home\sidebar') ?>
        <hr>
        <?= $this->include('App\Views\website\ads\sidebar_ad') ?>
    </div><!-- Menu col !-->
    <div class="col l7 m6 s12 pages">
        <div class="card z-depth-0" data-aos="fade-up">
            <div class="card-content">
                <h3><?= $post->title; ?></h3>
                <span class="crumbs"><?= date('jS M Y', strtotime($post->published_date)); ?> | category: <a href="<?= base_url('posts/'.$post->master_category_alias.'/'.$post->category_alias); ?>"><?= $post->category; ?></a>  |  Hits: <?= $post->hits; ?> </span>
                <img src="<?= $post->photo; ?>" alt="<?= $post->title; ?>" class="responsive-img" /><br/>
                <!-- Show Post Blocks or just Post !-->
                <?php if($post->is_block == "No"):?>
                <?= nl2br($post->content); ?><br/>
                <?php else:?>
                    <!-- Display Blocks !-->
                <div class="block-post">
                    <?php foreach ($blockData as $block): ?>
                        <?php if ($block->block_type === 'text'): ?>
                            <!-- Display Text Block -->
                            <div class=" text-block">
                                <div class="mb-3">
                                    <!-- Display text content -->
                                    <p><?= nl2br($block->content); ?></p>
                                </div>
                            </div>
                        <?php elseif ($block->block_type === 'image'): ?>
                            <!-- Display Image Block -->
                            <div class="image-block">
                                <div class="mb-3">
                                    <!-- Display image and caption -->
                                    <img src="<?= $block->photo; ?>" alt="<?= $block->caption; ?>" class="img-fluid">
                                    <span style="font-size: 12px; color: #666; font-style: italic; margin-bottom: 10px, margin-top: 3px; align-self: center"><?= $block->caption; ?></span>
                                </div>
                            </div>
                        <?php elseif ($block->block_type === 'video'): ?>
                            <!-- Display Video Block -->
                            <div class="video-block">
                                <div class="mb-3">
                                    <!-- Display Video and caption -->
                                    <iframe width="100%" height="345"
                                    src="<?= $block->url; ?>">
                                    </iframe>
                                    <span style="font-size: 12px; color: #666; font-style: italic; margin-bottom: 10px, margin-top: 3px; align-self: center"><?= $block->content; ?></span>
                                </div>
                            </div>
                        <?php elseif ($block->block_type === 'heading'): ?>
                            <!-- Display Heading Block -->
                            <div class=" heading-block">
                                <div class="mb-3">
                                    <!-- Display heading content -->
                                    <<?= $block->heading_type; ?> style="color: <?= $block->color?>"><?= $block->heading; ?></<?= $block->heading_type; ?>>
                                </div>
                            </div>
                        <?php elseif ($block->block_type === 'list'): ?>
                            <div class="list-block">
                                <div class="mb-3">
                                    <?php
                                    $items = explode(PHP_EOL, $block->content);
                                    if ($block->list_type === 'unordered'): ?>
                                        <!-- Unordered List -->
                                        <ul type="square">
                                            <?php foreach ($items as $item): ?>
                                                <li><?= $item; ?></li>
                                            <?php endforeach; ?>
                                        </ul>
                                    <?php elseif ($block->list_type === 'ordered'): ?>
                                        <!-- Ordered List -->
                                        <ol>
                                            <?php foreach ($items as $item): ?>
                                                <li><?= $item; ?></li>
                                            <?php endforeach; ?>
                                        </ol>
                                    <?php endif; ?>
                                </div>
                            </div>
                        <?php elseif ($block->block_type === 'code'): ?>
                            <!-- Display Code Block -->
                            <div class=" code-block">
                                <div class="mb-3">
                                    <!-- Display code content -->
                                    <pre> 
                                    <div class="codemirror-container" data-code="<?= htmlspecialchars($block->code); ?>"></div></pre>
                                </div>
                            </div>
                        <?php elseif ($block->block_type === 'advert'): ?>
                            <!-- Display ADVERT Code Block -->
                            <div class="advertcode-block">
                                <div class="mb-3">
                                    <!-- Display code content -->
                                    <pre><code><?= $block->advert_code; ?></code></pre>
                                </div>
                            </div>
                        <?php endif; ?>
                        <!-- End of Display of Blocks !-->
                    <?php endforeach; ?>
                    </div>
                    <!-- END Display Blocks !-->
                <?php endif;?>
                <!-- END POST Block !-->
                <div class="page-footer transparent black-text">
                <span class="left">Tags:<br/>   <?php foreach($tags as $tag):?>
                    <a href="<?= base_url('tags/tag/'.$tag->tag_alias);?>"><span class="badge teal lighten-1 white-text" style="margin: 3px;font-size: 11px;"><?= $tag->tag; ?></span> </a>
                <?php endforeach; ?>  
                </span>         
                    <span class="right">Share link: 
                    <div class="row">
                            <div class="col">
                                <a class="" href="https://www.facebook.com/sharer/sharer.php?u=<?= base_url('posts/'.$post->master_category_alias.'/'.$post->category_alias.'/'.$post->alias);?>" target="_blank" rel="noopener noreferrer" title="Facebook">
                                <small><i class="bi bi-facebook"></i> Share</small>
                                </a>
                            </div><!-- Facebook !-->
                            <div class="col">
                                <a class="" href="https://twitter.com/intent/tweet?url=<?= base_url('posts/'.$post->master_category_alias.'/'.$post->category_alias.'/'.$post->alias);?>&text=<?= $post->title; ?>" target="_blank" rel="noopener noreferrer" title="X">
                                <small> <i class="bi bi-twitter-x"></i> share</small>
                                </a>
                            </div><!-- Twitter !-->
                            <div class="col">
                                <a class="" href="whatsapp://send?text=Check out this product: <?= $post->title; ?> - <?= base_url('posts/'.$post->master_category_alias.'/'.$post->category_alias.'/'.$post->alias);?>" data-action="share/whatsapp/share" title="WhatsApp">
                                <small><i class="bi bi-whatsapp"></i> WhatsApp</small>
                                </a>
                            </div><!-- WhatsApp !-->
                        </div><!-- social sharing !-->
                    </span>
                </div>
            </div><!-- card content !-->
        </div><!-- card !-->
    </div><!-- Main Content !-->
    <div class="col l3 m4 s12 side-stay grey lighten-4">
        <h5 class="card-title">Related Posts</h5>
        <div class="collection" style="border:0px !important;">
            <?php foreach($relatedPosts as $rpost):?>
                <a href="<?= base_url('posts/'.$rpost->master_category_alias.'/'.$rpost->category_alias.'/'.$rpost->alias) ?>" class="collection-item grey lighten-4 " style="border:0px !important; border-bottom: 1px solid #ccc !important; padding: 5px 1px; font-size: 14px; "><?= $rpost->title; ?></a>
            <?php endforeach; ?>
        </div><!-- Related Posts !-->
        <div>
            <?= $this->include('App\Views\website\ads\right_square') ?>
        </div><!-- advert !--> 
    </div><!-- More Content !-->
</div><!-- row !-->
<!-- END Page Content !-->
</div><!-- main container !-->

<!-- JS !-->
<script src="<?= base_url();?>/assets/js/modules/block-posts.js"></script> 
<?= $this->endSection() ?>