Ë
    ±bj{&  ã                   ó    — d Z ddlmZ ddlmZ ddlmZ dedefd„Zdede	fd„Z
dedefd	„Zded
edefd„Zddedede	dz  fd„Zdededefd„Zy)zOCancel / back for the exchange wizard (classic footer + Football smooth-modal).é    )ÚPage)Úhuman_delay)Úclose_hudl_popupsÚpageÚreturnc              ƒ   ó‚   K  — 	 | j                  d«      j                  «       ƒ d {  –—† dkD  S 7 Œ# t        $ r Y yw xY w­w)Nz7.smooth-modal, .smooth-modal-overlay, .multi-step-modalr   F)ÚlocatorÚcountÚ	Exception)r   s    úG/var/www/html/sergio/sergio-backend/app/automation/tasks/cancel_back.pyÚ_modal_openr      sM   è ø€ ðà—,‘,ØIóç‰e‹g÷ð ñð	
ðùô
 ò Ùðüs(   ‚?„"0 ¦.§0 ­?®0 °	<¹?»<¼?c              ƒ   óª   K  — 	 | j                  d«      ƒ d{  –—† }t        |xs d«      S 7 Œ# t        $ r t        | «      ƒ d{  –—†7  rY yY yw xY w­w)zW
    Where the Football multi-step modal (or classic wizard) is after Back/Cancel.
    a’  () => {
              const modal = document.querySelector(
                '.smooth-modal, .smooth-modal-overlay, .multi-step-modal'
              );
              if (!modal) {
                // Classic exchange list without modal.
                if (document.querySelector('#events-container, .ex-team-block, [class*="ex-team"]')) {
                  return 'exchange_list';
                }
                return 'closed';
              }
              const text = (modal.innerText || '').slice(0, 2500);
              if (/choose playlist/i.test(text) || /no playlists/i.test(text)) {
                return 'playlists';
              }
              if (
                /choose a game to exchange/i.test(text) ||
                modal.querySelector('section.step-2, .multi-step-modal-inner.step-2-active')
              ) {
                return 'games';
              }
              if (
                /two-way|one-way|request video|exchange type/i.test(text) ||
                modal.querySelector('section.step-1, .multi-step-modal-inner.step-1-active')
              ) {
                return 'type';
              }
              if (/include.*stats|game stats|team stats/i.test(text)) return 'stats';
              if (/add a note|optional message|notes/i.test(text)) return 'notes';
              if (/confirm|review|send your/i.test(text)) return 'confirm';
              return 'modal';
            }NÚmodalÚclosed)ÚevaluateÚstrr   r   )r   Úinfos     r   Ú_detect_wizard_stepr      s`   è ø€ ð'Ø—]‘]ðó!
÷ !
ˆôD �4’?˜7Ó#Ð#ðE!
ùôF ò Ü˜TÓ"×"Ñ"ÙÙðüs=   ‚A„. ˜,™. «A¬. ®AÁAÁAÁAÁAÁAc              ƒ   ól  K  — d}|D ]�  }| j                  |«      j                  }	 |j                  «       ƒ d{  –—† dkD  rH|j                  «       ƒ d{  –—† r0|j	                  d¬«      ƒ d{  –—†  t        dd«      ƒ d{  –—†   yŒƒ 	 t        | «      ƒ d{  –—† rc| j                  j                  d	«      ƒ d{  –—†  t        d
d«      ƒ d{  –—†  t        | «      ƒ d{  –—† syt        | «      ƒ d{  –—† }|dv ryy7 ŒÉ7 Œ°7 Œ˜7 Œ†# t        $ r Y �Œw xY w7 Œ€7 Œ_7 ŒM7 Œ<7 Œ*# t        $ r Y yw xY w­w)uª   
    Close the Football multi-step exchange wizard and return to suggested teams.
    Prefer Cancel / close controls inside .smooth-modal â€” do not reload the page.
    )
z'.smooth-modal button:has-text('Cancel')z..smooth-modal footer button:has-text('Cancel')z+.multi-step-modal button:has-text('Cancel')z(.smooth-modal-overlay button.uni-dismissz .smooth-modal button.uni-dismissz".smooth-modal [aria-label='Close']z".smooth-modal [aria-label='close']z!.smooth-modal .smooth-modal-closez.smooth-modal .uni-closezbutton:has-text('Cancel')Nr   éˆ  ©Útimeoutgš™™™™™é?gffffffö?TÚEscapeç333333ã?ç      ð?)r   Úexchange_listF)r	   Úfirstr
   Ú
is_visibleÚclickr   r   r   ÚkeyboardÚpressr   )r   Ú	selectorsÚselectorÚbtnÚsteps        r   Ú_close_smooth_modal_wizardr&   B   s2  è ø€ ð
€Ió ˆØ�l‰l˜8Ó$×*Ñ*ˆð	Ø—Y‘Y“[×  1Ò$¨s¯~©~Ó/?×)?Ð)?Ø—i‘i¨�iÓ-×-Ð-Ü! # sÓ+×+Ð+Ùøð ð
Ü˜TÓ"×"Ð"Ø—-‘-×%Ñ% hÓ/×/Ð/Ü˜c 3Ó'×'Ð'Ü$ TÓ*×*Ð*ØÜ,¨TÓ2×2ˆDØÐ2Ñ2Øð ð) !øÐ)?øØ-øØ+ùäò 	Úð	úð
 #øØ/øØ'øØ*øà2ùô ò Øàðüsø   ‚#D4¦D¹DºDÁDÁDÁ.DÁ/DÂD	ÂDÂD4ÂD% ÂDÂ"D% Â=DÂ>D% ÃDÃD% Ã$D!Ã%D% Ã)D4Ã*D% Ã8D#Ã9D% ÄD4ÄDÄDÄDÄ	DÄ	DÄD4ÄDÄD4ÄD% ÄD% ÄD% Ä!D% Ä#D% Ä%	D1Ä.D4Ä0D1Ä1D4Ú
step_indexc           	   ƒ   óF  K  — t        dd«      ƒ d{  –—†  t        | «      ƒ d{  –—† r9t        | «      ƒ d{  –—† }|r$dd| j                  dt	        | «      ƒ d{  –—† ddœS 	 d	|› d
�}| j                  |«      j                  }|j                  dd¬«      ƒ d{  –—†  |j                  «       ƒ d{  –—†  t        dd«      ƒ d{  –—†  dd| j                  dt	        | «      ƒ d{  –—† d|› d�dœS 7 Œá7 ŒÐ7 Œ¿7 Œž7 Œ`7 ŒJ7 Œ87 Œ# t        $ r‘}t        | «      ƒ d{  –—†7   	 | j                  j                  d«      ƒ d{  –—†7   t        dd«      ƒ d{  –—†7   n# t        $ r Y nw xY wdd| j                  dt	        | «      ƒ d{  –—†7  d|› d�dœcY d}~S d}~ww xY w­w)z®
    POST /exchange/cancel
    Close the wizard and land back on the suggested-teams exchange page
    (no full Hudl reload when the smooth-modal Cancel/X is available).
    ç333333Ó?r   NÚokÚcancel_exchangeÚsmooth_modal_closeu9   Closed exchange wizard modal â€” back on suggested teams.)ÚstatusÚactionÚurlÚmethodÚwizard_stepÚmessagezxpath=(//footer/button[1])[Ú]Úvisiblei@  ©Ústater   r   çÍÌÌÌÌÌü?Úfooter_cancelzClicked cancel button at index Ú.r   ÚfallbackzCancel fallback used (z).)r   r   r&   r/   r   r	   r   Úwait_forr   r   r   r    r!   )r   r'   r   r#   r$   Ú
footer_errs         r   r+   r+   m   sª  è ø€ ô �c˜3Ó
×Ðô ˜Ó×ÐÜ1°$Ó7×7ˆÙàØ+Ø—x‘xØ.Ü%8¸Ó%>×>ØVñð ð
Ø0°°¸AÐ>ˆØ�l‰l˜8Ó$×*Ñ*ˆØ�l‰l °DˆlÓ9×9Ð9Ø�i‰i‹k×ÐÜ˜#˜sÓ#×#Ð#àØ'Ø—8‘8Ø%Ü!4°TÓ!:×:Ø8¸¸ÀAÐFñ
ð 	
ð-  øð øØ7øð  ?øð 	:øØøØ#øð ;ùô ò 
ä Ó%×%Ñ%ð	Ø—-‘-×%Ñ% hÓ/×/Ñ/Ü˜c 3Ó'×'Ò'øÜò 	Ùð	úð Ø'Ø—8‘8Ø Ü!4°TÓ!:×:Ð:Ø/°
¨|¸2Ð>ñ
õ 	
ûð
üs  ‚F!’C4“F!¥C6¦F!¸C8¹"F!ÁC:ÁF!Á$7D ÂC<ÂD Â3C>Â4D ÃD Ã D Ã(DÃ)
D Ã3F!Ã6F!Ã8F!Ã:F!Ã<D Ã>D Ä D ÄD Ä	FÄFÄDÄFÄ"EÅ EÅEÅEÅEÅFÅ	E(Å%FÅ'E(Å(FÆF
ÆFÆFÆF!ÆFÆF!Ú
back_indexNc              ƒ   ó  K  — ddddddt        d|«      › d�d	d
ddddddf}|D ]„  }| j                  |«      j                  }	 |j                  «       ƒ d{  –—† dk(  rŒ;|j	                  «       ƒ d{  –—† sŒT|j                  d¬«      ƒ d{  –—†  t        dd«      ƒ d{  –—†  |c S  	 | j                  d«      ƒ d{  –—† }|rt        dd«      ƒ d{  –—†  y	 y7 Œ‡7 Œm7 ŒT7 ŒB# t        $ r Y ŒÍw xY w7 Œ47 Œ # t        $ r Y yw xY w­w)zGClick the Hudl wizard Back control. Returns the selector used, or None.z(.smooth-modal .smooth-modal-back:visiblez,.multi-step-modal .smooth-modal-back:visiblez'.smooth-modal-header .smooth-modal-backz .smooth-modal .smooth-modal-backz$.multi-step-modal .smooth-modal-backz4xpath=(//div[contains(@class,"smooth-modal-back")])[é   r3   z%.smooth-modal button:has-text('Back')z).multi-step-modal button:has-text('Back')z!.smooth-modal [aria-label='Back']z%.multi-step-modal [aria-label='Back']z$.smooth-modal [aria-label='Go back']z.smooth-modal header buttonz.multi-step-modal header buttonzKxpath=(//footer//button[contains(., 'Back') or contains(@class,'back')])[1]Nr   r   r   gÍÌÌÌÌÌì?g      ø?uê  () => {
              const root = document.querySelector(
                '.smooth-modal, .multi-step-modal, .smooth-modal-overlay'
              ) || document.body;
              const candidates = Array.from(
                root.querySelectorAll(
                  '.smooth-modal-back, [aria-label*="ack" i], [class*="back"], button, a, div'
                )
              );
              const el = candidates.find((n) => {
                const cls = (n.className || '').toString().toLowerCase();
                const label = (n.getAttribute('aria-label') || '').toLowerCase();
                const text = (n.innerText || '').trim().toLowerCase();
                if (cls.includes('smooth-modal-back')) return true;
                if (label.includes('back')) return true;
                if (text === 'back' || text === 'â†�') return true;
                return false;
              });
              if (!el) return false;
              el.click();
              return true;
            }zjs:back)	Úmaxr	   r   r
   r   r   r   r   r   )r   r=   Úmodal_back_selectorsr#   r$   Úclickeds         r   Ú_click_visible_backrC   £   sC  è ø€ ð 	3Ø6Ø1Ø*Ø.Ø
>¼sÀ1ÀjÓ?QÐ>RÐRSÐTØ/Ø3Ø+Ø/Ø.Ø%Ø)àUðÐó" )ˆØ�l‰l˜8Ó$×*Ñ*ˆð		Ø—Y‘Y“[×  AÒ%ØØŸ™Ó)×)Ð)ØØ—)‘) D�)Ó)×)Ð)Ü˜c 3Ó'×'Ð'ØŠOð )ðØŸ™ðó
÷ 
ˆñ0 Ü˜c 3Ó'×'Ð'Øð ð ðU !øà)øà)øØ'ùäò 	Ùð	úð

øð2 (ùäò Øàðüs×   ‚?DÁC%ÁCÁC%ÁDÁC%Á1CÁ2C%Á6DÁ7C%ÂC!ÂC%Â C#Â!C%Â&DÂ+C8 Â?C4Ã C8 ÃC6ÃC8 ÃDÃDÃC%ÃC%Ã!C%Ã#C%Ã%	C1Ã.DÃ0C1Ã1DÃ4C8 Ã6C8 Ã8	DÄDÄDÄDc              ƒ   óh  K  — t        dd«      ƒ d{  –—†  t        | «      ƒ d{  –—† }t        | |¬«      ƒ d{  –—† }|stdt        d|«      › d�}| j	                  |«      j
                  }|j                  dd	¬
«      ƒ d{  –—†  |j                  «       ƒ d{  –—†  t        dd«      ƒ d{  –—†  |}t        | «      ƒ d{  –—† }|dk(  r6|dk(  r1t        | d¬«      ƒ d{  –—† }|r|› d|› �}t        | «      ƒ d{  –—† }dd| j                  ||||d|› d|› d�dœS 7 �Œ7 Œü7 Œé7 Œ£7 Œ�7 Œ{7 Œh7 ŒK7 Œ1­w)zµ
    POST /exchange/back
    Clicks the back control in the wizard (smooth-modal-back or step back)
    and reports which wizard step Hudl landed on so the FE can stay in sync.
    r)   r   N)r=   z*xpath=(//div[@class="smooth-modal-back"])[r?   r3   r4   i'  r5   r   r7   Ú	playlistsz + r*   Úgo_backzClicked back (u   ) â†’ r9   )r-   r.   r/   r=   Úselector_usedÚwizard_step_beforer1   r2   )	r   r   rC   r@   r	   r   r;   r   r/   )r   r=   ÚbeforeÚusedr#   r$   ÚafterÚagains           r   Úgo_back_exchangerM   æ   sK  è ø€ ô �c˜3Ó
×ÐÜ& tÓ,×,€Fä$ T°jÔA×A€DÙà?ÄÀAÀzÓ@RÐ?SÐSTÐUˆØ�l‰l˜8Ó$×*Ñ*ˆØ�l‰l °EˆlÓ:×:Ð:Ø�i‰i‹k×ÐÜ˜#˜sÓ#×#Ð#Øˆä% dÓ+×+€Eà�Ò ¨+Ò!5Ü)¨$¸1Ô=×=ˆÙØ�V˜3˜u˜gÐ&ˆDÜ-¨dÓ3×3ˆEð ØØ�x‰xØ ØØ$ØØ# D 6¨°¨w°aÐ8ñ	ð 	ð+  ùØ,øàAøð
 	;øØøØ#øð ,øð >øð 4úsœ   ‚D2’D“D2¥D"¦D2ºD$»AD2ÂD&ÂD2ÂD(ÂD2Â.D*Â/D2ÃD,ÃD2Ã"D.Ã#D2Ã>D0Ã?!D2Ä"D2Ä$D2Ä&D2Ä(D2Ä*D2Ä,D2Ä.D2Ä0D2)r?   )Ú__doc__Úplaywright.async_apir   Úapp.automation.helpersr   Úapp.automation.tasks.popupr   Úboolr   r   r   r&   ÚintÚdictr+   rC   rM   © ó    r   Ú<module>rW      s¤   ðÙ UÝ %å .Ý 8ð	˜Dð 	 Tó 	ð+ Dð +¨Só +ð\(¨4ð (°Dó (ðV3
 ð 3
°#ð 3
¸$ó 3
ñl@ Dð @°cð @À#ÈÁ*ó @ðF$ ð $°3ð $¸4ô $rV   