import { useCallback } from "react";
import useHttpRequest from "../../../hooks/useHttpRequest";
import { get } from "../../../utils/axios";

const cdn = process.env.REACT_APP_CDN_URL;
const endpoints = {
  mimeTypes: `${cdn}/admin/mime-types`,
  resourceCategories: `${cdn}/admin/resource-categories`
};

const useDictionariesApi = () => {
  const { exec } = useHttpRequest();

  const getMimeTypes = useCallback(
    (options) => {
      const promise = exec(() => get(endpoints.mimeTypes), options);
      return promise;
    },
    [exec]
  );

  const getResourceCategories = useCallback(
    (options) => {
      const promise = exec(() => get(endpoints.resourceCategories), options);
      return promise;
    },
    [exec]
  );

  return {
    getMimeTypes,
    getResourceCategories
  };
};

export default useDictionariesApi;
