<?php
/**
 * Admin galleries list template
 */

if (!defined('ABSPATH')) {
    exit;
}
?>

<div class="wrap">
    <h1 class="wp-heading-inline"><?php esc_html_e('BW Gallery', 'bw-gallery'); ?></h1>
    <a href="<?php echo esc_url(admin_url('admin.php?page=bw-gallery-new')); ?>" class="page-title-action">
        <?php esc_html_e('Add New', 'bw-gallery'); ?>
    </a>
    <a href="<?php echo esc_url(admin_url('admin.php?page=bw-gallery-tabs')); ?>" class="page-title-action">
        <?php esc_html_e('Manage Tabs', 'bw-gallery'); ?>
    </a>
    
    <?php if (empty($galleries)) : ?>
        <div class="bwg-no-galleries">
            <p><?php esc_html_e('No galleries found.', 'bw-gallery'); ?></p>
            <a href="<?php echo esc_url(admin_url('admin.php?page=bw-gallery-new')); ?>" class="button button-primary">
                <?php esc_html_e('Create Your First Gallery', 'bw-gallery'); ?>
            </a>
        </div>
    <?php else : ?>
        <table class="wp-list-table widefat fixed striped">
            <thead>
                <tr>
                    <th><?php esc_html_e('Name', 'bw-gallery'); ?></th>
                    <th><?php esc_html_e('Description', 'bw-gallery'); ?></th>
                    <th><?php esc_html_e('Shortcode', 'bw-gallery'); ?></th>
                    <th><?php esc_html_e('Created', 'bw-gallery'); ?></th>
                    <th><?php esc_html_e('Actions', 'bw-gallery'); ?></th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($galleries as $gallery) : ?>
                    <tr>
                        <td>
                            <strong>
                                <a href="<?php echo esc_url(admin_url('admin.php?page=bw-gallery-new&id=' . $gallery['id'])); ?>">
                                    <?php echo esc_html($gallery['name']); ?>
                                </a>
                            </strong>
                        </td>
                        <td><?php echo esc_html($gallery['description']); ?></td>
                        <td>
                            <code class="bwg-shortcode">[bw_gallery id="<?php echo esc_attr($gallery['id']); ?>"]</code>
                            <button class="button button-small bwg-copy-shortcode" data-shortcode='[bw_gallery id="<?php echo esc_attr($gallery['id']); ?>"]'>
                                <?php esc_html_e('Copy', 'bw-gallery'); ?>
                            </button>
                        </td>
                        <td><?php echo esc_html(date_i18n(get_option('date_format'), strtotime($gallery['created_at']))); ?></td>
                        <td>
                            <a href="<?php echo esc_url(admin_url('admin.php?page=bw-gallery-new&id=' . $gallery['id'])); ?>" class="button button-small">
                                <?php esc_html_e('Edit', 'bw-gallery'); ?>
                            </a>
                            <button class="button button-small bwg-delete-gallery" data-id="<?php echo esc_attr($gallery['id']); ?>">
                                <?php esc_html_e('Delete', 'bw-gallery'); ?>
                            </button>
                        </td>
                    </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
    <?php endif; ?>
</div>