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' ) ) &&
\u0420\u0435\u0439\u0442\u0438\u043d\u0433 \u041d\u0430\u0434\u0435\u0436\u043d\u044b\u0445 \u041e\u043d\u043b\u0430\u0439\u043d \u041a\u0430\u0437\u0438\u043d\u043e \u041b\u0443\u0447\u0448\u0438\u0435 \u0422\u043e\u043f \u041a\u043b\u0443\u0431\u044b \u0420\u043e\u0441\u0441\u0438\u0438<\/p>\n
Content<\/p>\n
\u041e\u043d\u043b\u0430\u0439\u043d \u043a\u0430\u0437\u0438\u043d\u043e \u041f\u0438\u043d\u0430\u043f \u043d\u0430\u0447\u0430\u043b\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0432 2016 \u043d\u0435\u0434\u0430\u0432\u043d\u043e \u0438 \u0437\u0430 \u0434\u0432\u0430 \u0433\u043e\u0434\u0430 \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u0434\u043e\u0431\u0430\u0432\u0438\u043b \u0432 \u043a\u0430\u0442\u0430\u043b\u043e\u0433 \u0430\u0437\u0430\u0440\u0442\u043d\u044b\u0445 \u0438\u0433\u0440 \u0431\u043e\u043b\u0435\u0435 600 \u043c\u043e\u0434\u0435\u043b\u0435\u0439. \u0417\u0434\u0435\u0441\u044c \u043d\u0435\u043b\u044c\u0437\u044f \u043d\u0430\u0439\u0442\u0438 \u0430\u043f\u043f\u0430\u0440\u0430\u0442\u044b \u043e\u0442 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u043e\u0432 \u0432\u0440\u043e\u0434\u0435 NetEnt%2C Yggdrasil%2C Thunderkick%2C NYX%2C Amatic \u0436\u0435 \u0434\u0440\u0443\u0433\u0438\u0445. \u0412\u0441\u0435 \u0438\u0433\u0440\u044b \u0441 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0435\u043c \u0447\u0435\u0441\u0442\u0438 \u0438 \u043e\u0431\u043b\u0430\u0434\u0430\u044e\u0442 \u043b\u0443\u0447\u0448\u0435\u0439 \u043e\u0442\u0434\u0430\u0447\u0435\u0439%2C \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0434\u043d\u044f\u0442\u044c \u0434\u0435\u043d\u0435\u0433 \u0441\u043c\u043e\u0433 \u0440\u0430\u0437 \u043f\u043e\u0441\u0435\u0442\u0438\u0442\u0435\u043b\u044c \u043a\u043b\u0443\u0431\u0430. \u0422\u0430\u043a \u0437\u0430\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043e \u0436\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0443\u0435\u0442 \u043f\u043e\u0434 \u0441\u0442\u0440\u043e\u0433\u0438\u043c \u043d\u0430\u0434\u0437\u043e\u0440\u043e\u043c \u0443\u0432\u0430\u0436\u0430\u0435\u043c\u043e\u0433\u043e \u0440\u0435\u0433\u0443\u043b\u044f\u0442\u043e\u0440\u0430 Gaming Curacao%2C \u0438\u043c\u0435\u044f \u043b\u0438\u0446\u0435\u043d\u0437\u0438\u044e \u2116365%2FJAZ \u043e\u0442 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438 Traflow Media N. V. Starda Casino \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u0435\u0431\u0435 \u0441\u043e\u0440\u0432\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0433\u0435\u043c\u0431\u043b\u0438\u043d\u0433 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0443%2C \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432 \u043a\u0440\u0430\u0442\u0447\u0430\u0439\u0448\u0438\u0435 \u0441\u0440\u043e\u043a\u0438 \u043f\u0440\u043e\u0431\u0438\u043b\u0430\u0441\u044c \u0432 \u0432\u0435\u0440\u0448\u0438\u043d\u044b \u043c\u0438\u0440\u043e\u0432\u043e\u0439 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u043e\u0441\u0442\u0438.<\/p>\n