import { useState } from "react";
import { useTranslation } from "react-i18next";
import { useNavigate } from "react-router-dom";
import { previewRecord } from "@/record-management/services/api/userRecordService";
import { CreateOrEditLetter } from "../userRecords/common/formSchema";
import { toast } from "sonner";
import { HeaderFooterResponseDto } from "@/user-management/services/api/headerFooterService";
import { OrganizationsPositions } from "@/record-management/services/api/departmentService";
import { EmployeeWithUnitDto } from "@/user-management/dto/employees/employees";

export const useRecordPreview = () => {
  const { t } = useTranslation();
  const navigate = useNavigate();
  const [isLoading, setIsLoading] = useState(false);

  const generatePreview = (
    formData: CreateOrEditLetter,
    files: File[] = [],
    headers: HeaderFooterResponseDto[] = [],
    footers: HeaderFooterResponseDto[] = [],
    positionsData: OrganizationsPositions[] = [],
    employeesData: EmployeeWithUnitDto[] = []
  ) => {
    // Navigate to preview page with state, replace current history entry for instant back navigation
    // navigate("/record-management/userRecords/record-preview", {
    //   state: {
    //     formData,
    //     files,
    //     headers,
    //     footers,
    //     positionsData,
    //     employeesData,
    //   },
    //   replace: false, // Don't replace so back button works properly
    // });
  };

  return {
    isLoading,
    generatePreview,
  };
};
