import { Product } from "@/shared/types/product";
import { Button } from "@/shared/ui/button";
import {
  Dialog,
  DialogContent,
  DialogTrigger,
} from "@/shared/ui/dialog";
import { Tabs, TabsList, TabsTrigger } from "@/shared/ui/tabs";
import React, { useState } from "react";
import PhysicalTab from "./physicalTab";
import LegalTab from "./legalTab";
import { useTranslations } from "next-intl";

interface Props {
  product: Product;
}

const BuyForm = ({ product }: Props) => {
  const t = useTranslations("")
  const [isDialogOpen, setIsDialogOpen] = useState(false);

  return (
    <Dialog open={isDialogOpen} onOpenChange={setIsDialogOpen}>
      <DialogTrigger asChild>
        <Button className="mt-8 px-16" onClick={() => setIsDialogOpen(true)}>
          {t("Sotib olish")}
        </Button>
      </DialogTrigger>
      <DialogContent className="sm:max-w-6/12 max-h-[90vh] overflow-y-auto">
        <Tabs defaultValue="physical" className="w-full mt-4">
          <TabsList className="grid w-full grid-cols-2">
            <TabsTrigger value="physical">{t("Jismoniy shaxs")}</TabsTrigger>
            <TabsTrigger value="legal">{t("Yuridik shaxs")}</TabsTrigger>
          </TabsList>

          {/* Physical */}
          <PhysicalTab product={product} setIsDialogOpen={setIsDialogOpen} />

          {/* Legal */}
          <LegalTab product={product} setIsDialogOpen={setIsDialogOpen} />
        </Tabs>
      </DialogContent>
    </Dialog>
  );
};

export default BuyForm;
