import { FunctionComponent } from "preact";
import Button from "./Button";

interface DialogProps {
  isOpen: boolean;
  setIsOpen: (isOpen: boolean) => void;
  title: string;
  content: string;
  onConfirm: () => void;
  confirmText?: string;
  cancelText?: string;
}

const Dialog: FunctionComponent<DialogProps> = ({
  isOpen,
  setIsOpen,
  title,
  content,
  onConfirm,
  confirmText = "Подтвердить",
  cancelText = "Отмена",
}) => {
  if (!isOpen) return null;

  return (
    <div class="fixed inset-0 z-50 flex items-center justify-center bg-black/50">
      <div class="w-full max-w-md rounded-[4rem] bg-white p-6 shadow-lg">
        <h2 class="mb-4 text-xl font-semibold">{title}</h2>
        <p class="mb-6">{content}</p>
        <div class="flex justify-end gap-4">
          <Button
            onClick={() => setIsOpen(false)}
            className="bg-gray-200 text-gray-800 hover:bg-gray-300"
          >
            {cancelText}
          </Button>
          <Button
            onClick={() => {
              onConfirm();
              setIsOpen(false);
            }}
            color="red"
          >
            {confirmText}
          </Button>
        </div>
      </div>
    </div>
  );
};

export default Dialog; 