<div class="d-flex justify-content-between align-items-center mb-4">
    <h2>Strony WordPress</h2>
    <a href="/sites/create" class="btn btn-primary">
        <i class="bi bi-plus-lg me-1"></i>Dodaj stron&#281;
    </a>
</div>

<div class="card">
    <div class="card-body p-0">
        <table class="table table-hover mb-0">
            <thead>
                <tr>
                    <th>Nazwa</th>
                    <th>URL</th>
                    <th>Tematy</th>
                    <th>Opublikowane</th>
                    <th>Interwa&#322;</th>
                    <th>Ostatnia publikacja</th>
                    <th>Status</th>
                    <th>Akcje</th>
                </tr>
            </thead>
            <tbody>
                <?php if (empty($sites)): ?>
                    <tr><td colspan="8" class="text-center text-muted py-4">Brak stron. Dodaj pierwsz&#261; stron&#281; WordPress.</td></tr>
                <?php else: ?>
                    <?php foreach ($sites as $site): ?>
                        <tr>
                            <td>
                                <a href="/sites/<?= $site['id'] ?>/edit"><?= htmlspecialchars($site['name']) ?></a>
                                <?php if ($site['is_multisite']): ?>
                                    <span class="badge bg-info">Multi</span>
                                <?php endif; ?>
                            </td>
                            <td><a href="<?= htmlspecialchars($site['url']) ?>" target="_blank" class="text-muted small"><?= htmlspecialchars($site['url']) ?></a></td>
                            <td>
                                <a href="/sites/<?= $site['id'] ?>/topics" class="badge bg-secondary text-decoration-none">
                                    <?= $site['topic_count'] ?> temat&#243;w
                                </a>
                            </td>
                            <td>
                                <a href="/articles?site_id=<?= $site['id'] ?>" class="badge bg-primary text-decoration-none" title="Poka&#380; artyku&#322;y tej strony">
                                    <?= $site['published_article_count'] ?> opublikowanych
                                </a>
                            </td>
                            <td>co <?= $site['publish_interval_hours'] ?> h</td>
                            <td><?= $site['last_published_at'] ? date('d.m.Y H:i', strtotime($site['last_published_at'])) : '-' ?></td>
                            <td>
                                <?php if ($site['is_active']): ?>
                                    <span class="badge bg-success">Aktywna</span>
                                <?php else: ?>
                                    <span class="badge bg-secondary">Nieaktywna</span>
                                <?php endif; ?>
                            </td>
                            <td>
                                <div class="btn-group btn-group-sm">
                                    <a href="/sites/<?= $site['id'] ?>/edit" class="btn btn-outline-primary" title="Edytuj">
                                        <i class="bi bi-pencil"></i>
                                    </a>
                                    <a href="/sites/<?= $site['id'] ?>/dashboard" class="btn btn-outline-dark" title="WP Dashboard">
                                        <i class="bi bi-sliders"></i>
                                    </a>
                                    <a href="/sites/<?= $site['id'] ?>/seo" class="btn btn-outline-primary" title="SEO Panel">
                                        <i class="bi bi-graph-up"></i>
                                    </a>
                                    <a href="/sites/<?= $site['id'] ?>/topics" class="btn btn-outline-info" title="Tematy">
                                        <i class="bi bi-tags"></i>
                                    </a>
                                    <a href="/sites/<?= $site['id'] ?>/categories" class="btn btn-outline-warning" title="Kategorie">
                                        <i class="bi bi-folder"></i>
                                    </a>
                                    <button class="btn btn-outline-success btn-test-connection" data-site-id="<?= $site['id'] ?>" title="Test po&#322;&#261;czenia">
                                        <i class="bi bi-wifi"></i>
                                    </button>
                                    <form method="post" action="/sites/<?= $site['id'] ?>/delete" class="d-inline" data-confirm="Na pewno usunac te strone?">
                                        <button type="submit" class="btn btn-outline-danger" title="Usu&#324;">
                                            <i class="bi bi-trash"></i>
                                        </button>
                                    </form>
                                </div>
                            </td>
                        </tr>
                    <?php endforeach; ?>
                <?php endif; ?>
            </tbody>
        </table>
    </div>
</div>

