"use client";
import { IconButton, Tooltip, Badge } from "@mui/material";
import AutorenewIcon from "@mui/icons-material/Autorenew";
import useTableSetting from "@/lib/hooks/useTableSetting";
import useDataTable from "@/lib/hooks/useDataTable";

function ResetStorage({ user_id, page_name, table_name }) {
  const { resetAction } = useTableSetting();
  const { isAnyDirty } = useDataTable();
  const reset = () => {
    resetAction(user_id, page_name, table_name);
  };

  return (
    <Tooltip title="بازنشانی اطلاعات">
      <IconButton onClick={reset} aria-label="reset table data">
        {isAnyDirty ? (
          <Badge
            anchorOrigin={{
              vertical: "top",
              horizontal: "left",
            }}
            color="primary"
            variant="dot"
          >
            <AutorenewIcon />
          </Badge>
        ) : (
          <AutorenewIcon />
        )}
      </IconButton>
    </Tooltip>
  );
}

export default ResetStorage;
