import re
import json
from typing import List, Dict

def _parse_appointment_slots(html: str) -> List[Dict]:
    slots = []
    pattern = r'"availableAppointments\\":\s*(\[.*\]),\\"showFlexiAppointment'
    match = re.search(pattern, html, re.DOTALL)
    
    if match:
        json_str = match.group(1).replace(r'\"', '"')
        print(f'json_str={json_str}') 
        data = json.loads(json_str)
        for day in data:
            d_str = day.get('day')
            for s in day.get('slots', []):
                labels = s.get('labels', [])
                lbl = ""
                stype = ""
                cost = ""
                
                if 'pta' in labels:
                    lbl = 'pta'
                    stype = "Prime"
                elif 'ptaw' in labels:
                    lbl = 'ptaw'
                    stype = "Prime Weekend"
                elif '' in labels:
                    lbl = ''
                    stype = "Standard"
                
                if lbl or not labels: 
                        slots.append({
                            'date': d_str,
                            'time': s.get('time'),
                            'label': lbl,
                            'type': stype,
                            'cost': cost
                        })
        return slots
    else:
        print('Parsed appointment slot page, but not found availableAppointments')
    return slots

f = open('../debug_pages/Tls_Query_Slot_Page_20260110_221803.html', 'r')
html_content = f.read()

f.close()

slots = _parse_appointment_slots(html_content)
print(slots)