'use client';

import { motion } from 'framer-motion';
import { AlertTriangle, RefreshCw, WifiOff } from 'lucide-react';
import { Button } from '@/components/ui/button';
import { cn } from '@/lib/utils';

interface ErrorStateProps {
  title?: string;
  description?: string;
  onRetry?: () => void;
  isOffline?: boolean;
  className?: string;
}

export function ErrorState({
  title,
  description,
  onRetry,
  isOffline,
  className,
}: ErrorStateProps) {
  const Icon = isOffline ? WifiOff : AlertTriangle;
  const defaultTitle = isOffline ? 'Tidak Ada Koneksi' : 'Terjadi Kesalahan';
  const defaultDesc = isOffline
    ? 'Periksa koneksi internet Anda dan coba lagi.'
    : 'Terjadi kesalahan saat memuat data. Silakan coba lagi.';

  return (
    <motion.div
      initial={{ opacity: 0, y: 10 }}
      animate={{ opacity: 1, y: 0 }}
      className={cn(
        'flex flex-col items-center justify-center py-16 px-6 text-center',
        className
      )}
    >
      <div className="mb-4 flex h-16 w-16 items-center justify-center rounded-2xl bg-destructive/10">
        <Icon className="h-8 w-8 text-destructive" />
      </div>
      <h3 className="font-heading text-lg font-semibold text-foreground">
        {title || defaultTitle}
      </h3>
      <p className="mt-1.5 max-w-sm text-sm text-muted-foreground">
        {description || defaultDesc}
      </p>
      {onRetry && (
        <Button
          onClick={onRetry}
          variant="outline"
          className="mt-4 rounded-xl gap-2"
          size="sm"
        >
          <RefreshCw className="h-4 w-4" />
          Coba Lagi
        </Button>
      )}
    </motion.div>
  );
}
