import re

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

# Find the pickup location field and modify it to add postcode option
pickup_field_html = '''            <div class="form-group">
              <label for="pickup">Pickup Location</label>
              <select id="pickupMethod" name="pickupMethod" style="margin-bottom: 10px;" disabled>
                <option value="select">Select from list</option>
                <option value="postcode">Enter postcode</option>
              </select>
              <select id="pickup" name="pickup" required disabled style="display: block;">
                <option value="">First select pickup type...</option>
              </select>
              <input type="text" id="pickupPostcode" name="pickupPostcode" placeholder="Enter your postcode (e.g., M1 1AE)" style="display: none;" />
              <small id="pickupPostcodeNote" style="display: none; color: #64748b; font-size: 13px; margin-top: 5px;">
                <i class="fas fa-info-circle"></i> We only serve Greater Manchester, Chester, and Liverpool areas
              </small>
            </div>'''

# Replace pickup field
content = re.sub(
    r'            <div class="form-group">\n              <label for="pickup">Pickup Location</label>\n              <select id="pickup" name="pickup" required disabled>\n                <option value="">First select pickup type...</option>\n              </select>\n            </div>',
    pickup_field_html,
    content
)

# Similar for dropoff
dropoff_field_html = '''            <div class="form-group">
              <label for="dropoff">Dropoff Location</label>
              <select id="dropoffMethod" name="dropoffMethod" style="margin-bottom: 10px;" disabled>
                <option value="select">Select from list</option>
                <option value="postcode">Enter postcode</option>
              </select>
              <select id="dropoff" name="dropoff" required disabled style="display: block;">
                <option value="">First select dropoff type...</option>
              </select>
              <input type="text" id="dropoffPostcode" name="dropoffPostcode" placeholder="Enter your postcode (e.g., L1 1AA)" style="display: none;" />
              <small id="dropoffPostcodeNote" style="display: none; color: #64748b; font-size: 13px; margin-top: 5px;">
                <i class="fas fa-info-circle"></i> We only serve Greater Manchester, Chester, and Liverpool areas
              </small>
            </div>'''

# Replace dropoff field
content = re.sub(
    r'            <div class="form-group">\n              <label for="dropoff">Dropoff Location</label>\n              <select id="dropoff" name="dropoff" required disabled>\n                <option value="">First select dropoff type...</option>\n              </select>\n            </div>',
    dropoff_field_html,
    content
)

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

print("✅ Added postcode input option for service areas")
print("✅ Added method selector (select from list / enter postcode)")
