<div class="gallery-container">
    <div class="gallery-header">
        <h1>My Images</h1>
        <div class="gallery-actions">
            <a href="<?php echo Config::get('URL'); ?>gallery/index" class="gallery-btn gallery-btn-secondary">Public Gallery</a>
            <a href="<?php echo Config::get('URL'); ?>gallery/upload" class="gallery-btn gallery-btn-primary">Upload Image</a>
        </div>
    </div>

    <?php if (empty($this->images)): ?>
        <div class="gallery-empty">
            <div class="gallery-empty-icon">
                <svg width="64" height="64" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
                    <rect x="3" y="3" width="18" height="18" rx="2" ry="2"></rect>
                    <circle cx="8.5" cy="8.5" r="1.5"></circle>
                    <polyline points="21 15 16 10 5 21"></polyline>
                </svg>
            </div>
            <h3>No images uploaded</h3>
            <p>Upload your first image to get started.</p>
            <a href="<?php echo Config::get('URL'); ?>gallery/upload" class="gallery-btn gallery-btn-primary" style="margin-top: 16px;">Upload Image</a>
        </div>
    <?php else: ?>
        <div class="gallery-grid">
            <?php foreach ($this->images as $image): ?>
                <div class="gallery-item gallery-item-owned">
                    <a href="<?php echo Config::get('URL'); ?>gallery/view/<?php echo $image->id; ?>">
                        <img src="<?php echo Config::get('URL'); ?>gallery/image/<?php echo $image->id; ?>/thumb"
                             alt="<?php echo htmlspecialchars($image->title); ?>"
                             loading="lazy">
                    </a>
                    <div class="gallery-item-overlay">
                        <span class="gallery-item-title"><?php echo htmlspecialchars($image->title); ?></span>
                        <span class="gallery-item-visibility <?php echo $image->is_public ? 'public' : 'private'; ?>">
                            <?php echo $image->is_public ? 'Public' : 'Private'; ?>
                        </span>
                    </div>
                    <div class="gallery-item-actions">
                        <a href="<?php echo Config::get('URL'); ?>gallery/edit/<?php echo $image->id; ?>" class="gallery-btn-icon" title="Edit">
                            <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                                <path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"></path>
                                <path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"></path>
                            </svg>
                        </a>
                        <a href="<?php echo Config::get('URL'); ?>gallery/delete/<?php echo $image->id; ?>"
                           class="gallery-btn-icon gallery-btn-danger"
                           title="Delete"
                           onclick="return confirm('Delete this image?');">
                            <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                                <polyline points="3 6 5 6 21 6"></polyline>
                                <path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path>
                            </svg>
                        </a>
                    </div>
                </div>
            <?php endforeach; ?>
        </div>

        <?php
        $total_pages = ceil($this->total_images / $this->per_page);
        if ($total_pages > 1):
        ?>
            <div class="gallery-pagination">
                <?php if ($this->current_page > 1): ?>
                    <a href="<?php echo Config::get('URL'); ?>gallery/my/<?php echo $this->current_page - 1; ?>" class="gallery-btn gallery-btn-secondary">Previous</a>
                <?php endif; ?>

                <span class="gallery-pagination-info">Page <?php echo $this->current_page; ?> of <?php echo $total_pages; ?></span>

                <?php if ($this->current_page < $total_pages): ?>
                    <a href="<?php echo Config::get('URL'); ?>gallery/my/<?php echo $this->current_page + 1; ?>" class="gallery-btn gallery-btn-secondary">Next</a>
                <?php endif; ?>
            </div>
        <?php endif; ?>
    <?php endif; ?>
</div>
