import clsx from 'clsx';
import * as React from 'react';
import { useState } from 'react';
import { asSelectors, ClassNames } from '../../DomUtils/classNames';
import {
useAutoFocusSearchConfig,
useSearchDisabledConfig,
useSearchPlaceHolderConfig
} from '../../config/useConfig';
import { useCloseAllOpenToggles } from '../../hooks/useCloseAllOpenToggles';
import {
getNormalizedSearchTerm,
useClearSearch,
useFilter
} from '../../hooks/useFilter';
import { useIsSkinToneInSearch } from '../../hooks/useShouldShowSkinTonePicker';
import Flex from '../Layout/Flex';
import Relative from '../Layout/Relative';
import { Button } from '../atoms/Button';
import { useSearchInputRef } from '../context/ElementRefContext';
import './Search.css';
import { SkinTonePicker } from './SkinTonePicker';
export function SearchContainer() {
const searchDisabled = useSearchDisabledConfig();
const isSkinToneInSearch = useIsSkinToneInSearch();
if (searchDisabled) {
return null;
}
return (
{isSkinToneInSearch ? : null}
);
}
export function Search() {
const [inc, setInc] = useState(0);
const closeAllOpenToggles = useCloseAllOpenToggles();
const SearchInputRef = useSearchInputRef();
const clearSearch = useClearSearch();
const placeholder = useSearchPlaceHolderConfig();
const autoFocus = useAutoFocusSearchConfig();
const { onChange } = useFilter();
const input = SearchInputRef?.current;
const value = input?.value;
return (
{
setInc(inc + 1);
setTimeout(() => {
onChange(event?.target?.value ?? value);
});
}}
ref={SearchInputRef}
/>
);
}
const CSS_SEARCH_SELECTOR = `${asSelectors(
ClassNames.emojiPicker
)} ${asSelectors(ClassNames.emojiList)}`;
function CssSearch({ value }: { value: undefined | string }) {
if (!value) {
return null;
}
const searchQuery = `button[data-full-name*="${getNormalizedSearchTerm(
value
)}"]`;
return (
);
}