import { useEffect } from "react";
import Paths from "../../lib/path";
import { createDir, exists } from "@tauri-apps/api/fs";

export const Initialization = () => {
  useEffect(() => {
    const initializePaths = async () => {
      try {
        await Paths.initialize();
      } catch (error) {
        console.error(`Failed to initialize paths: ${error}`);
      }
    };

    const createDirectories = async () => {
      const configDirectoryExists = await exists(Paths.getPath("configDirectory"));
      if (!configDirectoryExists) await createDir(Paths.getPath("configDirectory"));
    };

    initializePaths().then(() => createDirectories());
  });

  return null;
};
