import sys,re
def wrap_filter(s, label, cond='canAgencyFilter'):
    L=s.split('\n')
    i=[k for k,l in enumerate(L) if l.strip()==f'label: "{label}",' and any("concat(agency" in x for x in L[k:k+9])]
    assert len(i)==1,(label,i)
    i=i[0]
    start=i-1
    assert L[start].strip()=='{',L[start]
    ind=L[start][:len(L[start])-len(L[start].lstrip())]
    end=next(k for k in range(i,len(L)) if L[k]==ind+'},')
    body=['    '+l if l else l for l in L[start:end+1]]
    body=[re.sub(r'^(\s*name: "[^"]+")(,)$', r'\1 as const\2', l) for l in body]
    new=[ind+f'...({cond}',ind+'  ? ['] + ['  '+l for l in body] + [ind+'    ]',ind+'  : []),']
    # body indent: original ind + 4 → want ind+6 relative? keep consistent with FcPage: object at ind+4
    return '\n'.join(L[:start]+new+L[end+1:])
