import re

# Read the file
with open('quotation.html', 'r', encoding='utf-8') as f:
    content = f.read()

# Find and replace the pickup location field - make it simpler
new_pickup_field = '''            <div class="form-group">
              <label for="pickup">Pickup Location</label>
              <select id="pickup" name="pickup" required disabled>
                <option value="">First select pickup type...</option>
              </select>
              <input type="text" id="pickupAddress" name="pickupAddress" placeholder="Enter full pickup address with postcode" style="display: none;" class="address-input" />
              <small id="pickupAddressNote" style="display: none; color: #64748b; font-size: 13px; margin-top: 5px;">
                <i class="fas fa-info-circle"></i> Enter your complete pickup address including postcode (e.g., 123 Main St, Manchester, M1 1AE)
              </small>
            </div>'''

# Find the pickup field pattern and replace
pickup_pattern = r'            <div class="form-group">\s*<label for="pickup">Pickup Location</label>.*?</div>'
content = re.sub(pickup_pattern, new_pickup_field, content, flags=re.DOTALL, count=1)

# Same for dropoff
new_dropoff_field = '''            <div class="form-group">
              <label for="dropoff">Dropoff Location</label>
              <select id="dropoff" name="dropoff" required disabled>
                <option value="">First select dropoff type...</option>
              </select>
              <input type="text" id="dropoffAddress" name="dropoffAddress" placeholder="Enter full dropoff address with postcode" style="display: none;" class="address-input" />
              <small id="dropoffAddressNote" style="display: none; color: #64748b; font-size: 13px; margin-top: 5px;">
                <i class="fas fa-info-circle"></i> Enter your complete dropoff address including postcode (e.g., 456 High St, Liverpool, L1 1AA)
              </small>
            </div>'''

# Find and replace dropoff field
dropoff_pattern = r'            <div class="form-group">\s*<label for="dropoff">Dropoff Location</label>.*?</div>'
# Find the second occurrence (dropoff)
matches = list(re.finditer(dropoff_pattern, content, flags=re.DOTALL))
if len(matches) >= 2:
    second_match = matches[1]
    content = content[:second_match.start()] + new_dropoff_field + content[second_match.end():]
else:
    print("⚠️ Could not find second form-group (dropoff)")

# Add CSS for address input
address_input_css = '''
    .address-input {
      width: 100%;
      padding: 12px;
      border: 2px solid #e2e8f0;
      border-radius: 8px;
      font-size: 15px;
      transition: all 0.3s;
      font-family: 'Poppins', sans-serif;
    }
    
    .address-input:focus {
      outline: none;
      border-color: var(--primary-blue);
      box-shadow: 0 0 0 3px rgba(30, 64, 175, 0.1);
    }
    
    .address-input::placeholder {
      color: #94a3b8;
    }
'''

# Add CSS before closing </style>
content = re.sub(r'(\s*)(</style>)', address_input_css + r'\n    \2', content, count=1)

# Write back
with open('quotation.html', 'w', encoding='utf-8') as f:
    f.write(content)

print("✅ Updated pickup/dropoff fields with address inputs")
print("✅ Added CSS styling for address inputs")
print("✅ Simplified form structure")
