import { MapPin, Edit } from 'lucide-react';
import { Address } from '@/lib/api';

interface ShippingAddressProps {
  address: Address | string | null | undefined;
  onEdit?: () => void;
}

export function ShippingAddress({ address, onEdit }: ShippingAddressProps) {
  return (
    <div className="bg-gray-50 p-4 rounded-lg shadow-sm">
      <div className="flex items-center justify-between mb-3">
        <div className="flex items-center">
          <MapPin className="h-5 w-5 text-indigo-500 mr-2" />
          <h3 className="text-sm font-medium text-gray-900">Адрес доставки</h3>
        </div>
        {onEdit && (
          <button 
            onClick={onEdit}
            className="text-gray-400 hover:text-indigo-600" 
            title="Редактировать адрес"
          >
            <Edit className="h-4 w-4" />
          </button>
        )}
      </div>
      
      <div className="text-sm text-gray-600 space-y-1">
        {typeof address === 'string' ? (
          <p>{address || '—'}</p>
        ) : address ? (
          <>
            <p><span className="text-gray-500">Адрес:</span> {address.address_line1 || '—'}</p>
            {address.address_line2 && (
              <p><span className="text-gray-500">Дополнительно:</span> {address.address_line2}</p>
            )}
            <p>
              <span className="text-gray-500">Город:</span> {address.city || '—'}
            </p>
            <p>
              <span className="text-gray-500">Индекс:</span> {address.postal_code || '—'}
            </p>
            <p>
              <span className="text-gray-500">Страна:</span> {address.country || '—'}
            </p>
          </>
        ) : (
          <p className="text-gray-400 italic">Адрес не указан</p>
        )}
      </div>
    </div>
  );
} 