'use client';

import { useRouter, useParams } from 'next/navigation';
import { useState, useEffect } from 'react';
import { BoardForm } from '@/components/board/BoardManagement/BoardForm';
import { ContentLoadingSpinner } from '@/components/ui/loading-spinner';
import type { Board, BoardFormData } from '@/components/board/BoardManagement/types';

// TODO: 실제 API에서 데이터 가져오기
const mockBoard: Board = {
  id: '1',
  target: 'all',
  boardName: '공지사항',
  status: 'active',
  authorId: 'u1',
  authorName: '홍길동',
  createdAt: '2025-09-09T12:20:00Z',
  updatedAt: '2025-09-09T12:20:00Z',
};

export default function BoardEditPage() {
  const router = useRouter();
  const params = useParams();
  const [board, setBoard] = useState<Board | null>(null);

  useEffect(() => {
    // TODO: API 연동
    // const id = params.id;
    setBoard(mockBoard);
  }, [params.id]);

  const handleSubmit = (data: BoardFormData) => {
    // TODO: API 연동
    console.log('Update board:', params.id, data);
    router.push(`/ko/board/board-management/${params.id}`);
  };

  if (!board) {
    return <ContentLoadingSpinner text="게시판 정보를 불러오는 중..." />;
  }

  return (
    <BoardForm
      mode="edit"
      board={board}
      onSubmit={handleSubmit}
    />
  );
}