<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
<?php $this->need('header.php'); ?>

<article class="single-post">
    <?php 
    $banner = getPostImage($this, 'large');
    ?>
    <div class="single-post-header" style="background-image: url('<?php echo $banner; ?>');">
        <div class="single-post-overlay">
            <h1 class="single-post-title"><?php $this->title(); ?></h1>
            <div class="single-post-meta">
                <?php
                $viewsCounterActive = false;
                $plugins = Typecho_Plugin::export();
                if (isset($plugins['activated']['ViewsCounter'])) {
                    $viewsCounterActive = true;
                }
                ?>
                <span><i class="fa-regular fa-user"></i> <a href="<?php $this->author->permalink(); ?>"><?php $this->author(); ?></a></span>
                <span><i class="fa-regular fa-calendar"></i> <?php echo getLocalizedDate($this->created); ?></span>
                <?php if ($this->categories): ?>
                    <span><i class="fa-regular fa-folder"></i> <?php $this->category(', '); ?></span>
                <?php endif; ?>
                <?php if ($viewsCounterActive): ?>
                    <span><i class="fa-regular fa-eye"></i> <?php echo toPersianNumbers(ViewsCounter_Plugin::getViewsById($this->cid)); ?></span>
                <?php endif; ?>
                <span><i class="fa-regular fa-comment"></i> <?php $this->commentsNum('۰', '۱', '%d'); ?></span>
            </div>
        </div>
    </div>
    
    <div class="single-post-content">
        <?php $this->content(); ?>
        
        <!-- گالری تصاویر با قابلیت انتخاب نسبت تصویر -->
        <?php 
        $galleryUrls = $this->fields->galleryUrls;
        if (!empty($galleryUrls)):
            $urls = array_filter(array_map('trim', explode("\n", $galleryUrls)));
            $galleryStyle = $this->fields->galleryStyle ?: 'style-zoom';
            $galleryColumns = $this->fields->galleryColumns ?: '3';
            $galleryRatio = $this->fields->galleryRatio ?: 'landscape';
            
            if (!empty($urls)):
        ?>
            <div class="post-gallery-section">
                <div class="section-title">
                    <i class="fa-solid fa-images"></i>
                    <h2>گالری تصاویر</h2>
                </div>
                <div class="post-gallery grid-<?php echo $galleryColumns; ?> <?php echo $galleryStyle; ?> ratio-<?php echo $galleryRatio; ?>">
                    <?php foreach ($urls as $url): ?>
                        <div class="gallery-item">
                            <a href="<?php echo $url; ?>" class="gallery-link" data-lightbox="gallery-<?php $this->cid(); ?>">
                                <img src="<?php echo $url; ?>" alt="<?php $this->title(); ?>" loading="lazy">
                                <?php if($galleryStyle == 'style-dark'): ?>
                                    <div class="gallery-overlay">
                                        <i class="fa-solid fa-magnifying-glass-plus"></i>
                                    </div>
                                <?php endif; ?>
                            </a>
                        </div>
                    <?php endforeach; ?>
                </div>
            </div>
        <?php 
            endif;
        endif; 
        ?>
        
        <!-- اشتراک‌گذاری -->
        <div class="share-section">
            <div class="share-title">
                <i class="fa-solid fa-share-alt"></i> اشتراک‌گذاری
            </div>
            <div class="share-buttons">
                <a href="https://t.me/share/url?url=<?php echo urlencode($this->permalink); ?>&text=<?php echo urlencode($this->title); ?>" target="_blank" class="telegram">
                    <i class="fa-brands fa-telegram"></i>
                </a>
                <a href="https://wa.me/?text=<?php echo urlencode($this->title . ' - ' . $this->permalink); ?>" target="_blank" class="whatsapp">
                    <i class="fa-brands fa-whatsapp"></i>
                </a>
                <a href="https://twitter.com/intent/tweet?url=<?php echo urlencode($this->permalink); ?>&text=<?php echo urlencode($this->title); ?>" target="_blank" class="twitter">
                    <i class="fa-brands fa-twitter"></i>
                </a>
            </div>
        </div>
        
        <!-- برچسب‌ها -->
        <?php if ($this->tags): ?>
        <div class="post-tags">
            <span><i class="fa-solid fa-tags"></i></span>
            <?php $this->tags('', true, ''); ?>
        </div>
        <?php endif; ?>
    </div>
</article>

<!-- نظرات -->
<?php $this->need('comments.php'); ?>

<?php $this->need('footer.php'); ?>