import { useState } from 'react';

/**
 * Custom hook for managing modal states and configurations
 * @returns {object} - Modal management functions and state
 */
export const useModalManager = () => {
  const [modalOpen, setModalOpen] = useState(false);
  const [modalConfig, setModalConfig] = useState({
    isOpen: false,
    type: 'confirmation',
    title: '',
    message: '',
    onConfirm: () => {},
    confirmText: 'Confirm',
    declineText: 'Cancel',
    position: 'center'
  });

  const closeModal = () => {
    setModalConfig(prev => ({ ...prev, isOpen: false }));
  };

  const showToast = (title, message, type = 'success') => {
    setModalConfig({
      isOpen: true,
      type: 'toast',
      title,
      message,
      position: 'top-right',
      onConfirm: closeModal,
      confirmText: 'OK',
      declineText: 'Cancel'
    });
    setTimeout(closeModal, 3000);
  };

  const showPremiumModal = () => {
    setModalConfig({
      isOpen: true,
      type: 'premium',
      title: '🚀 Oops! This is a Premium Feature',
      message: 'Evaluate the features and select a bundle based on your needs.',
      onConfirm: () => {
        window.open('https://functiondeck.com/pricing/', '_blank');
        closeModal();
      },
      confirmText: 'Upgrade Now',
      declineText: 'Maybe Later'
    });
  };

  const showConfirmationModal = (title, message, onConfirm) => {
    setModalConfig({
      isOpen: true,
      type: 'confirmation',
      title,
      message,
      onConfirm: () => {
        onConfirm();
        closeModal();
      },
      confirmText: 'Confirm',
      declineText: 'Cancel'
    });
  };

  return {
    modalOpen,
    setModalOpen,
    modalConfig,
    closeModal,
    showToast,
    showPremiumModal,
    showConfirmationModal,
  };
};