import os

filepath = 'src/app/map/MapUI.tsx'
with open(filepath, 'r') as f:
    content = f.read()

# I need to add Polyline to react-leaflet imports
if "Polyline" not in content:
    content = content.replace("const Marker = dynamic(() => import('react-leaflet').then(mod => mod.Marker), { ssr: false });", 
                              "const Marker = dynamic(() => import('react-leaflet').then(mod => mod.Marker), { ssr: false });\nconst Polyline = dynamic(() => import('react-leaflet').then(mod => mod.Polyline), { ssr: false });")

# I will add a dotted line from the user's location to the selected property
route_line_html = """
      {searchedLocation && selectedProperty && (
        <Polyline 
          positions={[searchedLocation, [selectedProperty.latitude, selectedProperty.longitude]]} 
          pathOptions={{ color: '#3b82f6', weight: 4, dashArray: '10, 10', opacity: 0.8 }} 
        />
      )}
"""

if "Polyline" not in content and "pathOptions" not in content:
    content = content.replace(
        '     </MapContainer>',
        route_line_html + '     </MapContainer>'
    )

with open(filepath, 'w') as f:
    f.write(content)
print("Directions line added.")
