import 'package:flutter/material.dart';
import 'package:sizer/sizer.dart';

import '../../../../core/app_export.dart';

class NearbyLandmarksWidget extends StatelessWidget {
  final List<Map<String, dynamic>> landmarks;

  const NearbyLandmarksWidget({
    super.key,
    required this.landmarks,
  });

  Widget _buildLandmarkItem(
      BuildContext context, Map<String, dynamic> landmark) {
    final theme = Theme.of(context);
    final name = landmark['name'] as String? ?? '';
    final distance = landmark['distance'] as String? ?? '';
    final type = landmark['type'] as String? ?? '';

    String iconName = 'place';
    switch (type.toLowerCase()) {
      case 'restaurant':
        iconName = 'restaurant';
        break;
      case 'hospital':
        iconName = 'local_hospital';
        break;
      case 'school':
        iconName = 'school';
        break;
      case 'bank':
        iconName = 'account_balance';
        break;
      case 'store':
        iconName = 'store';
        break;
      case 'gas_station':
        iconName = 'local_gas_station';
        break;
      default:
        iconName = 'place';
    }

    return Container(
      margin: EdgeInsets.only(bottom: 2.h),
      padding: EdgeInsets.all(3.w),
      decoration: BoxDecoration(
        color: theme.colorScheme.surface.withValues(alpha: 0.5),
        borderRadius: BorderRadius.circular(8),
        border: Border.all(
          color: theme.colorScheme.outline.withValues(alpha: 0.2),
          width: 1,
        ),
      ),
      child: Row(
        children: [
          Container(
            width: 10.w,
            height: 5.h,
            decoration: BoxDecoration(
              color: AppTheme.primaryBlack.withValues(alpha: 0.1),
              borderRadius: BorderRadius.circular(6),
            ),
            child: Center(
              child: CustomIconWidget(
                iconName: iconName,
                color: AppTheme.primaryBlack,
                size: 20,
              ),
            ),
          ),
          SizedBox(width: 3.w),
          Expanded(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  name,
                  style: theme.textTheme.bodyMedium?.copyWith(
                    fontWeight: FontWeight.w500,
                    color: theme.colorScheme.onSurface,
                  ),
                  overflow: TextOverflow.ellipsis,
                ),
                SizedBox(height: 0.5.h),
                Text(
                  distance,
                  style: theme.textTheme.bodySmall?.copyWith(
                    color: theme.colorScheme.onSurface.withValues(alpha: 0.6),
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    final theme = Theme.of(context);

    if (landmarks.isEmpty) {
      return Container(
        width: double.infinity,
        padding: EdgeInsets.all(4.w),
        decoration: BoxDecoration(
          color: theme.colorScheme.surface,
          borderRadius: BorderRadius.circular(12),
          boxShadow: [
            BoxShadow(
              color: theme.shadowColor.withValues(alpha: 0.1),
              blurRadius: 8,
              offset: const Offset(0, 2),
            ),
          ],
        ),
        child: Column(
          children: [
            CustomIconWidget(
              iconName: 'location_off',
              color: theme.colorScheme.onSurface.withValues(alpha: 0.4),
              size: 32,
            ),
            SizedBox(height: 2.h),
            Text(
              'No hay puntos de referencia cercanos',
              style: theme.textTheme.bodyMedium?.copyWith(
                color: theme.colorScheme.onSurface.withValues(alpha: 0.6),
              ),
              textAlign: TextAlign.center,
            ),
          ],
        ),
      );
    }

    return Container(
      width: double.infinity,
      padding: EdgeInsets.all(4.w),
      decoration: BoxDecoration(
        color: theme.colorScheme.surface,
        borderRadius: BorderRadius.circular(12),
        boxShadow: [
          BoxShadow(
            color: theme.shadowColor.withValues(alpha: 0.1),
            blurRadius: 8,
            offset: const Offset(0, 2),
          ),
        ],
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(
            'Puntos de referencia cercanos',
            style: theme.textTheme.titleMedium?.copyWith(
              fontWeight: FontWeight.w600,
              color: theme.colorScheme.onSurface,
            ),
          ),
          SizedBox(height: 3.h),
          ...landmarks
              .map((landmark) => _buildLandmarkItem(context, landmark))
              .toList(),
        ],
      ),
    );
  }
}
