import { FC, useState, useEffect } from "react"; import { usePathname, useRouter } from "next/navigation"; import { Grid, Box, TextField, Autocomplete } from "@mui/material"; import { searchAllAction } from "@/app/_actions/search"; import { colors } from "@link-stack/ui"; type SearchResultProps = { props: any; option: any; }; const SearchInput = (params: any) => ( ); const SearchResult: FC = ({ props, option }) => { const { lightGrey, mediumGray, black, white } = colors; return ( {option.title} {option.note} ); }; export const SearchBox: FC = () => { const [open, setOpen] = useState(false); const [searchResults, setSearchResults] = useState([]); const [selectedValue, setSelectedValue] = useState(null); const [searchTerms, setSearchTerms] = useState(""); const pathname = usePathname(); const router = useRouter(); useEffect(() => { const fetchSearchResults = async () => { const results = await searchAllAction(searchTerms ?? "", 50); setSearchResults(results); }; fetchSearchResults(); }, [searchTerms]); return ( setOpen(false)} inputValue={searchTerms} onChange={(_event, option, reason) => { if (!option) return; const url = `/tickets/${option.internalId}`; setSelectedValue(""); router.push(url); }} onInputChange={(_event, value) => { setSearchTerms(value); }} open={open} onOpen={() => setOpen(true)} noOptionsText="No results" options={searchResults ?? []} getOptionLabel={(option: any) => { if (option) { return option.title; } else { return ""; } }} renderOption={(props, option: any) => ( )} sx={{ width: "100%" }} renderInput={(params: any) => } /> ); };