
    Aw
i 	                     P    d Z ddlZddlZddlmZmZ ddlmZ  G d d          ZdS )z
Press Tab Primitive Operation

This module provides realistic Tab key press functionality for browser automation.
Simulates human-like key press with natural timing.
    N)DictAny)Pagec                   B    e Zd ZdZd Zddedededee	e
f         fd	Zd
S )PressTaba4  
    Press Tab Key with Human-like Timing

    Implements realistic Tab key press behavior:
    - Small pre-press delay (hesitation)
    - Natural key press duration
    - Post-press delay for UI response

    Usage:
        presser = PressTab()
        result = await presser.press(page, base_delay=50)
    c                 $    t          d           dS )z!Initialize the press tab handler.u   ⇥ PressTab initializedN)print)selfs    </home/byschii/byschiidev/penelope/lib/primitive/press_tab.py__init__zPressTab.__init__   s    ()))))    F2   page
with_shift
base_delayreturnc                 :  K   	 t          d           |t          j        dd          z  }t          j        |dz             d{V  |r!|j                            d           d{V  n |j                            d           d{V  |t          j        dd	          z  }t          j        |dz             d{V  d
|sdnd|j        d}t          d           |S # t          $ r0}dt          |          d}t          d|            |cY d}~S d}~ww xY w)a}  
        Press the Tab key to move focus to the next element.

        IMPORTANT: The page should be in a state where Tab navigation is expected.

        Args:
            page (Page): Playwright page to use
            base_delay (int): Base delay in milliseconds for timing (default: 50)

        Returns:
            Dict containing press result and timing information
        u   ⇥ Pressing Tab keyg      ?g      ?i  Nz	Shift+TabTabg      ?g       @T)successkeyurlu   ✅ Tab key pressedF)r   erroru   ❌ Tab key press failed: )
r	   randomuniformasynciosleepkeyboardpressr   	Exceptionstr)	r
   r   r   r   	pre_delay
post_delayresulteerror_results	            r   r   zPressTab.press!   s      	 ())) #V^C%=%==I-	D 0111111111  1m))+6666666666m))%000000000 $fnS#&>&>>J-
T 1222222222  $.?uuKx F '(((M 	  	  	  Q L 2q22333	 s   CC   
D*%DDDN)Fr   )__name__
__module____qualname____doc__r   r   boolintr   r    r   r    r   r   r   r      so         * * *-  -  -  - 3 - X\]`be]eXf -  -  -  -  -  - r   r   )	r)   r   r   typingr   r   patchright.async_apir   r   r,   r   r   <module>r/      s               % % % % % %?  ?  ?  ?  ?  ?  ?  ?  ?  ? r   