import React, {useEffect, useState} from 'react'; const { __ } = wp.i18n; export function SearchDropdown( props ) { const [searchResultsFieldStatus, setSearchResultsFieldStatus] = useState( 'closed' ); const [textareaValue, setTextareaValue] = useState( '' ); const [dropdownMarkup, setDropdownMarkup] = useState( '' ); const [reset, setReset] = useState( false ); let searchResultsItems = []; /** * Sets the dropdown content when there's a change on any of props.searchResults, props.showDefaultMessage, props.showNoResultsMessage */ useEffect(() => { if ( props.searchResults ) { searchResultsItems = props.searchResults; } else { searchResultsItems = []; } if ( ! props.showDefaultMessage && ! props.showNoResultsMessage ) { setDropdownMarkup( printItems() ); } else { setDropdownMarkup( dropdownContent() ); } }, [props.searchResults, props.showDefaultMessage, props.showNoResultsMessage], reset); /** * Initially sets the dropdown content to the default message. */ useEffect( () => { setDropdownMarkup( getDefaultMessage() ); }, [] ); /** * On dropdown container focus, the textarea gets focused so user can start typing immediately. * @param el */ const handleSearchDropdownFocus = ( el ) => { if ( 'closed' === searchResultsFieldStatus ) { const textarea = el.currentTarget.querySelector( 'textarea' ); if ( 'undefined' !== typeof textarea && textarea !== null ) { textarea.tabIndex = '-1'; textarea.focus(); } } } const handleSearchDropdownClick = ( el ) => { } /** * On keydown sets the value of textarea. * @param el */ const handleSearchDropdownKeyDown = ( el ) => { setTextareaValue( el.currentTarget.value ) setSearchResultsFieldStatus( 'open' ); } /** * Expands results area upon textarea focus. * @param el */ const handleTextareaFocus = ( el ) => { setSearchResultsFieldStatus( 'open' ); } const handleSearchDropdownBlur = ( el ) => { const blurTimer = setInterval(function() { const resultsWrapperId = `sui-select-dropdown-wrap-${props.id}`, textareaId = `search-dropdown-textbox-${props.id}`, rendererWrapId = `blc-search-dropdown__renderer_wrap-${props.id}`; if ( resultsWrapperId !== document.activeElement.id && textareaId !== document.activeElement.id && rendererWrapId !== document.activeElement.id ) { setSearchResultsFieldStatus( 'closed' ); setTextareaValue( '' ); } clearInterval( blurTimer ); }, 160); } const handleResultsContainerClick = ( el ) => { el.currentTarget.tabIndex = '-1'; el.currentTarget.focus(); } const clearDropdown = () => { setSearchResultsFieldStatus( 'closed' ); setTextareaValue( '' ); //props.searchResults = []; setDropdownMarkup( ''); //props.showDefaultMessage = true; //props.showNoResultsMessage = false; setDropdownMarkup( getDefaultMessage() ); setReset( true ) } const printItems = () => { if ( typeof searchResultsItems !== 'undefined' && searchResultsItems.length > 0 ) { return ( searchResultsItems.map( (listItem) => ( ( typeof listItem !== 'undefined' && listItem.hasOwnProperty( 'key' ) ) &&
  • { listItem.onClick(); clearDropdown(); } } > {listItem.display}
  • ) ) ) } } const getDefaultMessage = () => { return
  • {props.defaultMessage}
  • ; } const dropdownContent = () => { if ( props.showDefaultMessage && props.defaultMessage ) { return getDefaultMessage(); } else if ( props.showNoResultsMessage && props.noResultsMessage ) { return
  • {props.noResultsMessage}
  • ; } return printItems(); } return(
    { handleSearchDropdownFocus(e) }} onClick={(e)=> { handleSearchDropdownClick(e) }} onKeyDown={(e)=> { handleSearchDropdownKeyDown(e) }} onBlur={(e)=> { handleSearchDropdownBlur(e) }} >
    { handleResultsContainerClick(e) }} >
      {dropdownMarkup}
    ) }
    {"id":685,"date":"2024-10-23T15:46:54","date_gmt":"2024-10-23T18:46:54","guid":{"rendered":"https:\/\/automax.net.br\/?p=685"},"modified":"2024-10-24T09:39:21","modified_gmt":"2024-10-24T12:39:21","slug":"1win-obzor-bk-2023-ofitsialnyj-sajt2c-stavki2c-bonusy2c-otzyvy-o-bukmekerskoj-kontor","status":"publish","type":"post","link":"https:\/\/automax.net.br\/1win-obzor-bk-2023-ofitsialnyj-sajt2c-stavki2c-bonusy2c-otzyvy-o-bukmekerskoj-kontor\/","title":{"rendered":"1win \u041e\u0431\u0437\u043e\u0440 \u0411\u043a 2023 \u041e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u0421\u0430\u0439\u0442%2C \u0421\u0442\u0430\u0432\u043a\u0438%2C \u0411\u043e\u043d\u0443\u0441\u044b%2C \u043e\u0442\u0437\u044b\u0432\u044b \u041e \u0411\u0443\u043a\u043c\u0435\u043a\u0435\u0440\u0441\u043a\u043e\u0439 \u041a\u043e\u043d\u0442\u043e\u0440"},"content":{"rendered":"

    1win \u041e\u0431\u0437\u043e\u0440 \u0411\u043a 2023 \u041e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u0421\u0430\u0439\u0442%2C \u0421\u0442\u0430\u0432\u043a\u0438%2C \u0411\u043e\u043d\u0443\u0441\u044b%2C \u043e\u0442\u0437\u044b\u0432\u044b \u041e \u0411\u0443\u043a\u043c\u0435\u043a\u0435\u0440\u0441\u043a\u043e\u0439 \u041a\u043e\u043d\u0442\u043e\u0440\u0435<\/p>\n

    1win \u0417\u0435\u0440\u043a\u0430\u043b\u043e \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u043c \u0421\u0430\u0439\u0442\u0430 \u0420\u0430\u0431\u043e\u0447\u0435\u0435 \u043d\u0430 \u0421\u0435\u0433\u043e\u0434\u043d\u044f%3A \u0410\u043f\u0440\u0435\u043b\u044c 2024<\/h1>\n
    \n

    Content<\/p>\n