import { useNavigate } from "react-router-dom";
import { useCallback } from "react";

import { useJsonRpc } from "@/hooks/useJsonRpc";
import { ConfirmDialog } from "@/components/ConfirmDialog";

export default function SettingsGeneralRebootRoute() {
  const navigate = useNavigate();
  const [send] = useJsonRpc();

  const onConfirmUpdate = useCallback(() => {
    // This is where we send the RPC to the golang binary
    send("reboot", {force: true});
  }, [send]);

  {
    /* TODO: Migrate to using URLs instead of the global state. To simplify the refactoring, we'll keep the global state for now. */
  }
  return (
    <ConfirmDialog
      open={true}
      onClose={() => navigate("..")}
      title="Reboot JetKVM"
      description="Do you want to proceed with rebooting the JetKVM?"
      variant="danger"
      onConfirm={onConfirmUpdate}
    />
  );
}