"use client";

import { useState, ReactNode } from "react";
import ClientModal from "./client-modal"; // The modal shell

interface TriggerModalButtonProps {
  children: ReactNode; // This will be the <ProductDetailsServer />
  buttonText?: string;
  modalTitle?: string;
}

export default function TriggerModalButton({
  children,
  buttonText = "Open Product Details",
  modalTitle,
}: TriggerModalButtonProps) {
  const [isModalOpen, setIsModalOpen] = useState(false);

  return (
    <>
      <button
        onClick={() => setIsModalOpen(true)}
        className="px-4 py-2 font-semibold text-white bg-indigo-600 rounded-md hover:bg-indigo-700"
      >
        {buttonText}
      </button>

      <ClientModal
        isOpen={isModalOpen}
        onClose={() => setIsModalOpen(false)}
        title={modalTitle || ""}
      >
        {children} {/* Pass the Server Component content here */}
      </ClientModal>
    </>
  );
}
