'use client';

/**
 * 게시글 수정 페이지
 */

import { useParams } from 'next/navigation';
import { useMemo } from 'react';
import { format } from 'date-fns';
import { BoardForm } from '@/components/board/BoardForm';
import type { Post } from '@/components/board/types';
import { MOCK_BOARDS } from '@/components/board/types';

// Mock 데이터 생성 (실제로는 API에서 가져옴)
const generateMockPost = (id: string): Post => {
  const boards = MOCK_BOARDS.filter((b) => b.id !== 'all');
  const board = boards[0];

  return {
    id,
    boardId: board.id,
    boardName: board.name,
    title: '제목',
    content: `
      <p>게시글 내용입니다.</p>
      <p>이것은 <strong>테스트용</strong> 콘텐츠입니다.</p>
    `,
    authorId: 'user1',
    authorName: '홍길동',
    authorDepartment: '개발팀',
    authorPosition: '과장',
    isPinned: false,
    allowComments: true,
    viewCount: 123,
    attachments: [
      {
        id: 'file-1',
        fileName: 'abc.pdf',
        fileSize: 1024000,
        fileUrl: '/files/abc.pdf',
        mimeType: 'application/pdf',
      },
    ],
    createdAt: format(new Date(2025, 8, 9, 12, 20), "yyyy-MM-dd'T'HH:mm:ss"),
    updatedAt: format(new Date(2025, 8, 9, 12, 20), "yyyy-MM-dd'T'HH:mm:ss"),
  };
};

export default function BoardEditPage() {
  const params = useParams();
  const postId = params.id as string;

  // Mock 데이터 (실제로는 API에서 가져옴)
  const post = useMemo(() => generateMockPost(postId), [postId]);

  return <BoardForm mode="edit" initialData={post} />;
}