import { useCoreFetcher } from "@/lib/features/useCoreFetcher";
import { Button } from "@mantine/core";
import { IconRefresh } from "@tabler/icons-react";
import { toast } from "sonner";

const SyncProfile: React.FC<{
  profileID: string;
  accountId: string;
  contactId: string;
}> = ({ profileID, accountId, contactId }) => {
  const { trigger, isLoading } = useCoreFetcher("sync-member-profile", "put", {
    onSuccess: () => {
      toast.success("Successfully Synced Member Profile");
    },
    onError: (err) => {
      toast.error((err as Error).message ?? "Failed to sync profile");
    },
  });
  const syncProfile = async () => {
    await trigger({ profileID, accountId, contactId });
  };
  return (
    <Button
      variant="light"
      onClick={syncProfile}
      loaderProps={{ type: "dots" }}
      loading={isLoading}
    >
      <IconRefresh size={12} style={{ marginRight: "10px" }} />
      Sync Profile
    </Button>
  );
};

export default SyncProfile;
