
    sojE                        d dl mZ d dlmZ d dlmZ d dlZd dlm	Z	 d dl
mZ d dlmZ d dlmZ d dlmZ d d	lmZmZmZ d d
lmZ d dlmZ d dlmZ d dlmZ d dlmZ dede de!e         fdZ"dede fdZ#dedede!e         e e e e e gfdZ$	 	 	 	 	 	 	 	 	 d2dedededede%de%dej&        dedede'de%de(e%e!e!e                  f         fd Z)ded!e%de'fd"Z*dej&        d!e%dede%fd#Z+dededej&        dede!e         f
d$Z,dedefd%Z-ej.        ddej/        ddddd&df
d'e%d(e0d)e!e%         d*e d+e!e%e z           d,e'd-e d.e d/e d0e%e z  de!e!e                  fd1Z1dS )3    )StrEnum)Update)ContextTypesN)	BaseModel)User)ContextDataKey)Emoji)ListPage
ListFilterListFilterType)ReservedKeyboardKeys)Screen)NavigationLimitReachedException)Keyboard)determine_articleinbound_keyboardcurrent_pagereturnc                     g }| | j         nd}t          j        |dz
  i}|                    t	          t
          j        ||                     t          j        |dz   i}|                    t	          t
          j        ||                     |S )z
    Returns the navigation buttons for the crew member list
    :param inbound_keyboard: The inbound keyboard
    :param current_page: The current page
    :return: The navigation buttons
    N   )infoinbound_info)r   r   PAGEappendr   phrasesPVT_KEY_PREVIOUS_PAGEPVT_KEY_NEXT_PAGE)r   r   keyboard_liner   previous_page_button_infonext_page_button_infos          /app/src/service/list_service.pyget_navigation_buttonsr"      s     %'M,<,H#((dL "6!:L1<L M)*%	
 	
 	
   26q8HI%&%	
 	
 	
       c                     | dS t           j        | j        v r-| j        t           j                 }|dk     rt                      |S dS )z
    Get the page number. Raises a NavigationLimitReachedException if the page is less than 1
    :param inbound_keyboard: The inbound keyboard
    :return: The page number
    Nr   )r   r   r   r   )r   pages     r!   get_pager&   6   sS     q  $4$999$%9%>?!8813331r#   	list_pagec                 L   t          |           }|                    |          }t          |          dk    r|dk    rt                      |dz
  t          j        z  dz   }|t          |          z   dz
  }|                                }|                                }||||||fS )a"  
    Get the items, page, start number, end number, total number of items
    and all items without filter count

    :param inbound_keyboard: The inbound keyboard
    :param list_page: The list page object
    :return: The items, start number, end number and the total number of items
    r   r   )r&   	get_itemslenr   cSTANDARD_LIST_SIZEget_total_items_countget_total_items_no_filter_count)r   r'   r%   itemsstart_number
end_numbertotal_itemsall_items_counts           r!   get_items_paginater4   K   s     $%%D %%E 5zzQ4!88-/// Q%99A=L"SZZ/!3J !6688K %DDFFO$j+NNr#   Fitem_detail_keyitem_detail_screentext_fill_intext_overviewcontextuserupdateallow_string_filterempty_list_textc                                                      |	r| "|                    |t          j        |            n=	 |                    |t          j                  } | d| _        n# t          $ r d} Y nw xY w	 | t          | dd          st          |j	        j
        _        |                    |t          j        j                                                   nH# t          $ r; |                    |t          j                                                  _        Y nw xY wt          | ||          }|_        t#          |           \  }}}}}}g }d}|dk    r-|
t$          j                            |          n|
}|dk    r||fS g }t+          |          D ]\  }}||z   }                    |j                   |t$          j                            |                                          z  }|||j        i}t5          t7          |          ||| r| j        nd                                          }|                    |           |dz   t>          j         z  dk    r|dk    r|                    |           g }|(tC          |          dk    r|                    |           |t>          j"        k    r#|                    tG          | |                     d}d}d}$                                }d	 |D             }fd
|D             }d |D             } t+          $                                          D ]`\  }}!%                    |          }"|!j&        tN          j(        u r|r2tC          |           dk    rtS          | |"          }#|#s|sZ|#r| | j        *                    |"d           |+                    |t          j        |"           d}|!j,        |d         j,        k    rn|                    t5          t$          j-                            t$          j(                  | r| j.        nd|"dt^          j0        di| r| j        nd          g           #tC          j1        |!j2                           dk    rH|                    t5          |!j2        3                                t$          j4                            |!j,                  z   | r| j.        nd|"dt^          j0        di| r| j        nd          g           d}|!j&        tN          j5        u r~|!}tm          ||"|          }$|$i|                    t5          t$          j-                            |!j,                  | r| j.        nd|"dt^          j0        di| r| j        nd          g           btC          j7                  dk    rj8        r|9                                z  }|'|t$          j:                            |j,                  z  }tC          |          dk    rd}%|D ]}&|&j&        tN          j5        u r+t$          j;                            |&j,        |&j<                  }'n$t$          j=                            |&j,                  }'|%t$          j>                            |'          z  }%|t$          j?                            |%          z  }|dk    r|t>          j"        k    r$|t$          j@                            |||          z  }||nt$          jA        }(||(                    |          }n$|(                    t          |          ||          }||fS )a/  
    Get the items text and keyboard

    :param inbound_keyboard: The inbound keyboard
    :param list_page: The list page
    :param item_detail_key: The item detail keyboard key
    :param item_detail_screen: The item detail screen
    :param text_fill_in: The text fill in
    :param text_overview: The text overview
    :param context: The context
    :param user: The user
    :param update: The update
    :param allow_string_filter: Whether to allow string filter
    :param empty_list_text: The empty list text
    :return: The text and keyboard
    NTis_simulatedF r   )screenr   r   styler   c                 8    g | ]}|j         t          j        u |S  filter_typer   LEGEND.0fs     r!   
<listcomp>z+get_items_text_keyboard.<locals>.<listcomp>   s'    SSSAAM^=R,R,Ra,R,R,Rr#   c                 Z    g | ]'}t          j        |j                           d k    %|(S )r   )r*   legend_filter_resultslegend)rI   rJ   r'   s     r!   rK   z+get_items_text_keyboard.<locals>.<listcomp>   s=     ! ! !S)H)R%S%SVW%W%W%W%W%Wr#   c                 8    g | ]}|j         t          j        u |S rD   rE   rH   s     r!   rK   z+get_items_text_keyboard.<locals>.<listcomp>   s'    aaa1!->K`:`:`Q:`:`:`r#   	inner_key)rA   r   r   )Cinit_legend_filter_resultsset_context_datar   INBOUND_KEYBOARDget_context_datar?   	ExceptiongetattrAttributeErroreffective_messagetextstring_filterFILTERget_string_filter_keyget_context_data_or_noneget_active_filter_listfilter_list_activer4   r   LIST_OVERVIEW_NO_ITEMSformat	enumerate
set_objectidLIST_ITEM_TEXTget_item_textr   strr   get_item_button_styler   r+   STANDARD_LIST_KEYBOARD_ROW_SIZEr*   r,   r"   get_filter_listget_filter_keyrF   r   rG   get_legend_filter_valuepopremove_context_datadescriptionPVT_KEY_STRING_FILTER_REMOVErA   r   r   rM   rN   get_formatted	TEXT_ONLYSTRINGget_string_filter_valueemoji_legend_listshow_legend_listget_emoji_legend_list_textLIST_FILTER_SEND_PART_OF_STRINGLIST_FILTER_ITEM_CONTAINSvalueLIST_FILTER_ONLYLIST_FILTER_ITEMLIST_FILTER_ACTIVE_FILTERSLIST_FOOTERLIST_OVERVIEWr   ))r   r'   r5   r6   r7   r8   r9   r:   r;   r<   r=   active_filtersr/   r%   r0   r1   total_countall_items_no_filter_countinline_keyboard
items_textr   indexitemcurrent_numberbutton_infobuttonr\   add_legend_filterhas_added_legend_filterfilterslegend_filterslegend_filters_with_itemsactive_legend_filterslist_filterkeyfilter_valuecurrent_valueactive_filters_textactive_filter
inner_textlist_overviews)    `                                       r!   get_items_text_keyboardr   o   sh   : ((***   '!!'>+JL\]]]](#'#8#8.Ba#b#b #/48$1 ( ( (#'   (	'w7GY^/_/_'$$&,&>&CI#!!%'//11	     	 	 	&*&C&C.	0O0O0Q0Q' 'I###	 ,,<iRVWWN#1I  	+Y77 RE4z;8Q
 -/OJ a & *11,???  	 %))..$&M '' # #t%-TW%%%g,33NID[D[D]D]^^^
)*DG4KN##) 6FP-22D5577  F   ((( 	Q>>!CCQR

&&}555 "%}!!""=111 Q)))56FMMNNN (,M#''))GSSSSSN! ! ! !!! ! ! baaaa'	(A(A(C(CDD C C{&&u--"n&;;;&  ())A--67GMM# ,=    '3(-11#t<<<,,Wn6KWZ,[[[(,% #.2KB2O2[[['.. ($+$H$O$OPWP^$_$_FV+`+;+B+B\`*-u6J6OQR)SJZ1d1A1F1F`d	!" !" !"	 	 	  92;3EFGG1LL ""#*88::!+22;3JKKL:JT/66PT!4)=)BAF>N%X%5%:%:TX  
 
 
 '+##$(==='M!8#t!L!LM(&& #@GGH_``>N#X#3#:#:TX"%u.B.G!KBR)\)9)>)>X\	  	 	 	 9&''!++	0J+i::<<<
  g=DD]E^___
 >Q + 		O 		OM(N,AAA$>EE!-}/B 

 %5<<]=VWW
7#;#B#B:#N#NNg8??@STTT
Q---'-44\:{[[[J)6)BH]&--j99JJ&--!,//z J &&s%   )A( (A76A7;A$C   AD%$D%r   c                 6    | || j         v r| j         |         S dS )z
    Get the legend filter value from the inbound keyboard
    :param inbound_keyboard: The inbound keyboard
    :param key: The key
    :return: The list filter value
    NF)r   )r   r   s     r!   rn   rn   ]  s+     #/?/D(D(D$S))5r#   c                 F    |                     | t          j        |          S )z
    Get the string filter value from the context
    :param context: The context
    :param key: The key
    :param user: The user
    :return: The string filter value
    rP   )r_   r   r]   )r9   r   r:   s      r!   rv   rv   k  s#     ((.2GSV(WWWr#   c                    g }| t          | dd          st          |                                          D ]\  }}|                    |          }|| j        v rp| j        |         }|r$|                    |t          j        ||           V|                    |t          j        |           | j        	                    |           t          |                                          D ][\  }}|                    |          }|
                    |t          j        |          }|s?||_        |                    |           \|S )z
    Get the active filter list
    :param inbound_keyboard: The inbound keyboard
    :param list_page: The list page
    :param context: The context
    :param user: The user
    :return: The active filter list
    Nr?   FrP   )rX   rd   rl   rm   r   rT   r   r]   rp   ro   r_   r|   r   )	r   r'   r9   r:   active_filter_listr   r   r   r|   s	            r!   r`   r`   x  sq    ,.#G4DnV[,\,\#"+I,E,E,G,G"H"H 	 	E;**511C&+++(-c2 ))'>3H%[^)____ ,,Wn6KWZ,[[[$)--c222 , (	(A(A(C(CDD / /{&&u----g~7LX[-\\ 	!!!+....r#   c                 l    | | j         ni }d|t          j        <   t          t          j        |          S )zv
    Get the show list button
    :param inbound_keyboard: The inbound keyboard
    :return: The show list button
    NF)r   )r   r   DIRECT_ITEMr   r   PVT_KEY_SHOW_ALL)r   r   s     r!   get_show_list_buttonr     sE     %5$@  bD-2D		)*    r#   Tprimary_keyr   exclude_key_from_inbound_inforow_sizevaluesgenerate_numbersr0   r1   is_numeric_valuescurrent_selectedc
           	      &   |r7|d}|t          d          d}t          t          ||dz                       }g }
g }|D ]}| |rt          |          n|i}t	          |          }|	0t	          |          t	          |	          k    rt
          j         | }|                    t          ||||                     t          |          |k    r|
                    |           g }t          |          dk    r|
                    |           |
S )a   
    Get the options keyboard
    :param primary_key: The primary key
    :param inbound_info: The inbound info
    :param exclude_key_from_inbound_info: The exclude key from inbound info
    :param row_size: The row size
    :param values: The values
    :param generate_numbers: Whether to generate numbers
    :param start_number: The start number
    :param end_number: The end number
    :param is_numeric_values: Whether the values are numeric
    :param current_selected: The current selected value
    :return: The numeric keyboard
    Nr   z1End number must be set if auto generating numbersT)r   r   r   r   )

ValueErrorlistrangeintri   r	   RADIO_BUTTONr   r   r*   )r   r   r   r   r   r   r0   r1   r   r   numeric_keyboardline_keyboardir   r[   s                  r!   get_options_keyboardr     sP   6  ;LPQQQ eL*q.99::-/$&M  ".?$FCFFFQG1vv'CFFc:J6K6K,K,K(0$00D ).K	  	
 	
 	
 }))##M222M
=A...r#   )	NNNNNNNFN)2enumr   src.tg_compatr   src.tg_compat.extr   	constantsr+   resources.phrasesr   src.model.BaseModelr   src.model.Userr   src.model.enums.ContextDataKeyr   src.model.enums.Emojir	   src.model.enums.ListPager
   r   r   $src.model.enums.ReservedKeyboardKeysr   src.model.enums.Screenr   src.model.error.CustomExceptionr   src.model.pojo.Keyboardr   src.utils.english_phrase_utilsr   r   r   r"   r&   r4   ri   DEFAULT_TYPEbooltupler   rn   rv   r`   r   DEFAULT_PRIMARY_KEYrk   dictr   rD   r#   r!   <module>r      s                     * * * * * *     # # # # # # ) ) ) ) ) )       9 9 9 9 9 9 ' ' ' ' ' ' I I I I I I I I I I E E E E E E ) ) ) ) ) ) K K K K K K , , , , , , < < < < < <X S TRZ^    Dx C    *!O!O+3!O
9osCc3/!O !O !O !ON  $!%)- %k' k'k'k' k' 	k'
 k' k' &k' k' k' k' k' 3T(^$$%k' k' k' k'\h S T    
X\%> 
XS 
XPT 
XY\ 
X 
X 
X 
X''+3'>J>W'_c'	*' ' ' 'T8       ,?/35""!"&; ;;; $(9; 	;
 sO; ; ; ; ; Ci; 
$x.; ; ; ; ; ;r#   