"use client";
import React from "react";
import { XIcon } from "lucide-react";
import { client, useSession } from "@/lib/auth/auth-client";
import { Button } from "@/components/ui/button";

export const StopImpersonatingButton: React.FC = () => {
    const {
        data,
        refetch,
        isPending,
        error
    } = useSession();

    const {
        session = null
    } = data || {};

    if(isPending || error || !session || !session.impersonatedBy) {
        return null;
    }

    return (
        <Button
          className="fixed top-0 right-0 z-1000"
          type="button"
          size="icon"
          variant="secondary"
          onClick={async () => {
            await client.admin.stopImpersonating();
            refetch();
          }}>
            <XIcon />
        </Button>
    );
};
