import {
  AlertDialog,
  AlertDialogAction,
  AlertDialogCancel,
  AlertDialogContent,
  AlertDialogDescription,
  AlertDialogFooter,
  AlertDialogHeader,
  AlertDialogTitle,
  AlertDialogTrigger,
} from "@/shared/common/ui/alert-dialog";
import { Loader2 } from "lucide-react";

import { ReactNode } from "react";

interface OrganizationActivateOrDeactivationPopupProps {
  organizationName: string;
  isActive: boolean;
  onConfirm: () => void;
  isLoading: boolean;
  trigger: ReactNode;
}

export const OrganizationActivateOrDeactivationPopup = ({
  organizationName,
  isActive,
  onConfirm,
  isLoading,
  trigger,
}: OrganizationActivateOrDeactivationPopupProps) => {
  return (
    <AlertDialog>
      <AlertDialogTrigger asChild>{trigger}</AlertDialogTrigger>
      <AlertDialogContent>
        <AlertDialogHeader>
          <AlertDialogTitle>
            {isActive ? "Deactivate" : "Activate"} Organization
          </AlertDialogTitle>
          <AlertDialogDescription>
            Are you sure you want to {isActive ? "deactivate" : "activate"}{" "}
            <span className="font-medium">{organizationName}</span>? This action
            can be reversed later.
          </AlertDialogDescription>
        </AlertDialogHeader>
        <AlertDialogFooter>
          <AlertDialogCancel disabled={isLoading} className="cursor-pointer">
            Cancel
          </AlertDialogCancel>
          <AlertDialogAction
            onClick={onConfirm}
            disabled={isLoading}
            className={
              isActive ? "bg-red-600 hover:bg-red-700 cursor-pointer" : ""
            }
          >
            {isLoading && <Loader2 className="h-4 w-4 animate-spin" />}
            {isLoading
              ? isActive
                ? "Deactivating..."
                : "Activating..."
              : isActive
              ? "Deactivate"
              : "Activate"}
          </AlertDialogAction>
        </AlertDialogFooter>
      </AlertDialogContent>
    </AlertDialog>
  );
};
