"use client";

import { Webhook } from "lucide-react";
import { useState } from "react";
import { useTranslation } from "react-i18next";
import { TSurvey } from "@formbricks/types/surveys/types";
import { Button } from "@/modules/ui/components/button";
import { AddWebhookModal } from "./add-webhook-modal";

interface AddWebhookButtonProps {
  workspaceId: string;
  surveys: TSurvey[];
  allowInternalUrls: boolean;
  surveyVisibilityEnabled: boolean;
}

export const AddWebhookButton = ({
  workspaceId,
  surveys,
  allowInternalUrls,
  surveyVisibilityEnabled,
}: Readonly<AddWebhookButtonProps>) => {
  const { t } = useTranslation();
  const [isAddWebhookModalOpen, setAddWebhookModalOpen] = useState(false);
  return (
    <>
      <Button
        size="sm"
        onClick={() => {
          setAddWebhookModalOpen(true);
        }}>
        <Webhook className="mr-2 size-5 text-white" />
        {t("workspace.integrations.webhooks.add_webhook")}
      </Button>
      <AddWebhookModal
        workspaceId={workspaceId}
        surveys={surveys}
        open={isAddWebhookModalOpen}
        setOpen={setAddWebhookModalOpen}
        allowInternalUrls={allowInternalUrls}
        surveyVisibilityEnabled={surveyVisibilityEnabled}
      />
    </>
  );
};
