import React from 'react'

type ErrorStateProps = {
  message: string
  onBack?: () => void
}

/**
 * Error state component shown when something goes wrong
 */
export const ErrorState = React.memo<ErrorStateProps>(({ message, onBack }) => (
  <div className="messaging-error-state flex items-center justify-center h-full p-8">
    <div className="text-center max-w-sm">
      <div className="w-24 h-24 bg-danger-alt/20 rounded-full flex items-center justify-center mx-auto mb-6">
        <span className="text-4xl">⚠️</span>
      </div>

      <h2 className="font-semibold text-charcoal mb-2">Oops!</h2>

      <p className="text-stone text-sm mb-6">{message}</p>

      {onBack && (
        <button
          type="button"
          onClick={onBack}
          className="inline-flex items-center gap-2 px-4 py-2 text-sm font-medium text-white bg-[#7f22fe] hover:bg-primary-alt rounded-lg transition-colors focus-ring"
        >
          Go Back
        </button>
      )}
    </div>
  </div>
))
ErrorState.displayName = 'ErrorState'
