import type { CurrentUser, SiteSettings } from '../../env';
import { AdminLayout } from './layout';

export function AdminCommentsPage(props: {
  settings: SiteSettings;
  currentUser: CurrentUser;
  csrfToken: string;
  comments: Array<{ id: string; post_id: string; content: string; status: string; author_name: string; created_at: number }>;
}) {
  return (
    <AdminLayout title="评论管理" settings={props.settings} currentUser={props.currentUser} csrfToken={props.csrfToken} active="/admin/comments">
      <section class="admin-panel">
        <table class="admin-table">
          <thead><tr><th>作者</th><th>评论</th><th>状态</th><th>操作</th></tr></thead>
          <tbody>
            {props.comments.map((comment) => (
              <tr data-comment-id={comment.id}>
                <td>{comment.author_name}</td>
                <td><a href={`/p/${comment.post_id}`}>{comment.content}</a></td>
                <td>{comment.status}</td>
                <td>
                  <button data-admin-action="approve-comment">通过</button>
                  <button data-admin-action="trash-comment">删除</button>
                </td>
              </tr>
            ))}
          </tbody>
        </table>
      </section>
    </AdminLayout>
  );
}
