"use client";

import TaskDetails from '@/shared/sections/details-task/task-details';
import { useState, useEffect } from 'react';
import { axiosInstance } from '@/utils/axios';
import { ITaskItem } from '@/contexts/types/tasks';
import { useBoolean, useRouter } from '@/hooks';
import { paths } from '@/routes/paths';

export default function TaskDetailsPage({ params }: { params: { id: string } }) {
  const [task, setTask] = useState<ITaskItem | null>(null);
  const openDetails = useBoolean(true);
  const router = useRouter();

  useEffect(() => {
    const fetchTask = async () => {
      const response = await axiosInstance.get(
        `${process.env.NEXT_PUBLIC_GATEWAY_API}/api/projects/api/tasks/${params.id}`
      );
      setTask(response.data);
    };
    fetchTask();
  }, [params.id]);

  if (!task) return null;

  return (
    <TaskDetails 
      task={task}
      openDetails={openDetails.value}
      onCloseDetails={() => {
        openDetails.onFalse();
        router.push(paths.dashboard.tasks.all_tasks);
      }}
      onUpdateTask={(updatedTask) => setTask(updatedTask)}
      onArchiveTask={() => {}}
      onDeleteTask={() => {}}
      onFavoriteTask={() => {}}
      onUnFavoriteTask={() => {}}
    />
  );
} 