import React, { useCallback } from "react";
import CacheSettingsComponent from "./CacheSettingsComponent";
import { useTranslation } from "react-i18next";
import { endpoints } from "utils/api";
import { blip } from "utils";
import { useGuardedMutation, mutationFetcher, Key, NetworkError } from "units/swr";

const CacheSettingsContainer: React.FC = () => {
  const { t } = useTranslation();

  const { trigger } = useGuardedMutation<void, NetworkError, Key, void>(
    endpoints.system.resetCache,
    mutationFetcher<void>,
    {
      onSuccess: () => blip.info(t("Settings.Cache.ResetInfo"))
    }
  );

  const handleResetCache = useCallback(() => trigger(), [trigger]);

  return <CacheSettingsComponent onResetCache={handleResetCache} />;
};

export default CacheSettingsContainer;
