'use client';

interface TooltipProps {
  message: string;
  position?: 'top' | 'bottom' | 'left' | 'right';
}

/**
 * Tooltip component for showing disabled reason on hover
 */
export function Tooltip({ message, position = 'top' }: TooltipProps) {
  const positionClasses = {
    top: 'bottom-full mb-2',
    bottom: 'top-full mt-2',
    left: 'right-full mr-2',
    right: 'left-full ml-2',
  };

  const arrowClasses = {
    top: 'top-full -mt-1 left-1/2 -ml-1',
    bottom: 'bottom-full -mb-1 left-1/2 -ml-1 rotate-180',
    left: 'left-full -ml-1 top-1/2 -mt-1 -rotate-90',
    right: 'right-full -mr-1 top-1/2 -mt-1 rotate-90',
  };

  return (
    <div
      className={`absolute ${positionClasses[position]} right-0 w-64 px-3 py-2 bg-slate-800 text-white text-xs rounded-lg shadow-lg z-50 animate-fadeIn`}
    >
      {message}
      <div
        className={`absolute ${arrowClasses[position]} w-2 h-2 bg-slate-800 transform rotate-45`}
      ></div>
    </div>
  );
}

interface ToastProps {
  message: string;
}

/**
 * Toast notification component for showing disabled reason on click (mobile-friendly)
 */
export function Toast({ message }: ToastProps) {
  return (
    <div className="fixed bottom-4 right-4 left-4 md:left-auto md:w-96 bg-slate-800 text-white px-4 py-3 rounded-lg shadow-lg z-50 animate-fadeIn">
      <div className="flex items-start gap-3">
        <svg
          className="w-5 h-5 text-amber-400 flex-shrink-0 mt-0.5"
          fill="none"
          stroke="currentColor"
          viewBox="0 0 24 24"
        >
          <path
            strokeLinecap="round"
            strokeLinejoin="round"
            strokeWidth={2}
            d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"
          />
        </svg>
        <p className="text-sm flex-1">{message}</p>
      </div>
    </div>
  );
}

interface DisabledFeedbackProps {
  showTooltip: boolean;
  showToast: boolean;
  message: string | null;
  tooltipPosition?: 'top' | 'bottom' | 'left' | 'right';
}

/**
 * Combined component for showing disabled feedback (tooltip + toast)
 * Use with useDisabledFeedback hook
 */
export function DisabledFeedback({
  showTooltip,
  showToast,
  message,
  tooltipPosition = 'top',
}: DisabledFeedbackProps) {
  if (!message) return null;

  return (
    <>
      {showTooltip && <Tooltip message={message} position={tooltipPosition} />}
      {showToast && <Toast message={message} />}
    </>
  );
}
