import re

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

# New simplified pickup field with "Enter Address" option
new_pickup_section = '''          <div class="form-grid">
            <div class="form-group">
              <label for="pickupType">Pickup Location Type</label>
              <select id="pickupType" name="pickupType" required>
                <option value="">Select pickup type...</option>
                <option value="service-area">Service Area (Select from list)</option>
                <option value="custom-address">Enter My Address</option>
                <option value="airport">UK Airport</option>
              </select>
            </div>

            <div class="form-group">
              <label for="pickup">Pickup Location</label>
              <select id="pickup" name="pickup" disabled>
                <option value="">First select pickup type...</option>
              </select>
              <input type="text" id="pickupAddress" name="pickupAddress" placeholder="Enter full address with postcode (e.g., 123 Main St, Manchester, M1 1AE)" style="display: none;" class="address-input" />
              <small id="pickupNote" style="display: none; color: #64748b; font-size: 13px; margin-top: 5px;">
                <i class="fas fa-info-circle"></i> We serve Greater Manchester, Chester, and Liverpool areas
              </small>
            </div>
          </div>

          <div class="form-grid">
            <div class="form-group">
              <label for="dropoffType">Dropoff Location Type</label>
              <select id="dropoffType" name="dropoffType" required>
                <option value="">Select dropoff type...</option>
                <option value="service-area">Service Area (Select from list)</option>
                <option value="custom-address">Enter My Address</option>
                <option value="airport">UK Airport</option>
              </select>
            </div>

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

# Find and replace the entire journey details form grids section
pattern = r'          <div class="form-grid">[\s\S]*?</div>\s*<div class="form-grid">[\s\S]*?</div>\s*</div>\s*<div class="form-grid">\s*<div class="form-group">\s*<label for="date">'

replacement = new_pickup_section + '\n\n          <div class="form-grid">\n            <div class="form-group">\n              <label for="date">'

content = re.sub(pattern, replacement, content, count=1)

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

print("✅ Completely rewrote location selection fields")
print("✅ Added 'Enter My Address' option")
print("✅ Simplified form structure")
print("✅ Three options: Service Area / Enter Address / Airport")
