ó
    ÇÄŽj  ã                   ó4   • S r SSKrSSKJr  SrSrS rS	S jrg)
a%  
Cazana retail lookup (the platform is now branded Percayso).

Given a registration and mileage, BidBrain enters them on the Cazana trade home
page, runs the valuation, and reads back the headline Retail value, the figure
the buying brain uses. It deliberately reads the headline Retail, not the
franchise, independent or supermarket breakdowns and not the Trade value.

The page has no stable id, so the value is found by locating the Retail block,
which uniquely contains the words Retail franchise, and reading its amount.

If the value cannot be read with confidence, this returns None so the caller
holds the car back rather than pricing it on a guess. It never bids.

Also returns the real result page's own URL, so a card can deep link back
to the exact Cazana lookup BidBrain based its figure on.
é    Né   )Úbrowserz2https://trade.percayso-vehicle-intelligence.co.uk/a¾  
() => {
  const spans = [...document.querySelectorAll('p span')]
    .filter(s => s.textContent.trim() === 'Retail');
  for (const span of spans) {
    const row = span.closest('.columns');
    if (!row) continue;
    if (!/Retail franchise/i.test(row.textContent)) continue;
    const valCol = row.querySelector('.has-text-right');
    const p = valCol && valCol.querySelector('p');
    if (p) return p.textContent.trim();
  }
  return null;
}
c                 óè   • U (       d  g [         R                  " S[        U 5      5      nU(       d  g UR                  S5      R	                  SS5      nUR                  5       (       a  [        U5      $ S $ )Nz[\d,]+r   Ú,Ú )ÚreÚsearchÚstrÚgroupÚreplaceÚisdigitÚint)ÚtextÚmÚns      Ú8/Users/stevendouglas/BidBrain/bidbrain/readers/cazana.pyÚ_to_intr   *   sU   € ÞØÜ
�	Š	�)œS ›YÓ'€AÞØØ	�‰�‹
×Ñ˜3 Ó#€AØ—Y‘Y—[‘[Œ3ˆq‹6Ð* dÐ*ó    c                 ó²  • U(       a  Uc  g[         R                  " U SUS9n UR                  (       a  UR                  S   OUR                  5       nUR	                  [
        SSS9   UR                  SS	S
9  UR                  S[        U5      R                  SS5      5        UR                  S[        [        U5      5      5        UR                  SS5         UR                  SSS
9   UR!                  ["        S	S
9  UR%                  ["        5      nUb,  SSKJn  U" XdS   US   5      (       d   UR                  5         g[+        U5      UR,                  4UR                  5         $ ! [         a    [        S5      ef = f! [         a     UR                  5         gf = f! [         a     UR                  5         gf = f! UR                  5         f = f)a=  Return (value, url): the Cazana headline Retail value as whole
pounds, and the real page it was read from (Mark 2026-08-25: "add a
link on the card on the word Cazana to deep link to lookup page"), so
a card can link straight back to the exact result BidBrain looked at.
The url is a real, live https://trade.percayso-vehicle-intelligence.
co.uk/companion/search/<uuid> address, its own uuid generated by
Cazana per search and never guessable from the reg alone, so it can
only ever be captured here, at the moment of a real lookup, not
constructed after the fact.

Both are None if the value could not be read with confidence. expect
is an optional (make, model) pair; when given, the result page must
describe that car or (None, None) is returned (never a URL pointing
at the wrong car), used by the private plate fallback too.)NNÚcazana)Úheadlessr   Údomcontentloadedi@œ  )Ú
wait_untilÚtimeoutzinput[name="value"]i˜:  )r   zmCazana did not show the search box. The login may have expired. Run: python3 login.py cazana, then try again.Ú r   zinput[name="mileage"]ÚEnterz**/companion/search/**i0u  é   )Údetails_match)r   Úopen_reader_contextÚpagesÚnew_pageÚgotoÚHOMEÚwait_for_selectorÚ	ExceptionÚRuntimeErrorÚfillr
   r   r   ÚpressÚwait_for_urlÚcloseÚwait_for_functionÚ_EXTRACT_JSÚevaluateÚglassr   r   Úurl)	Ú
playwrightÚregÚmileager   ÚexpectÚctxÚpageÚ
value_textr   s	            r   Úlookupr7   4   s¬  € ö �'‘/Øä
×
%Ò
% j°(ÀXÑ
N€Cð$Ø"ŸyŸyˆs�y‰y˜Š|¨c¯l©l«nˆØ�	‰	”$Ð#5¸uˆ	ÑEð	Ø×"Ñ"Ð#8À%Ð"ÑHð 	�	‰	Ð'¬¨S«×)9Ñ)9¸#¸rÓ)BÔCØ�	‰	Ð)¬3¬s°7«|Ó+<Ô=à�
‰
Ð(¨'Ô2ð	Ø×ÑÐ6ÀÐÑFð
	Ø×"Ñ"¤;¸Ð"Ñ>ð —]‘]¤;Ó/ˆ
ØÑÝ,Ù  ¨a¡y°&¸±)×<Ñ<Ø!ð 	�	‰	�ô �zÓ" D§H¡HÐ,à�	‰	�øô= ó 	Üð@óð ð	ûô ó 	Øð 	�	‰	�ð!	ûô ó 	Øð 	�	‰	�ð	ûð 	�	‰	�úsm   £AG Á)E+ Á9A!G ÃF Ã,F$ Ä 2G ÅG Å+FÆG Æ
F!ÆG Æ F!Æ!G Æ$
GÆ.G Ç GÇG ÇG)TN)Ú__doc__r   r   r   r#   r,   r   r7   © r   r   Ú<module>r:      s(   ðñó$ 
Ý à;€ð€ò"+õ7r   