{"version":3,"file":"Search-CnBtGB11.js","sources":["../../../frontend/src/Components/Dashboard/Tables/Search.tsx"],"sourcesContent":["import React, { useEffect, useRef, useState } from 'react';\nimport { IconButton, InputAdornment, TextField } from '@mui/material';\nimport { styled } from '@mui/material/styles';\nimport ClearIcon from '@mui/icons-material/Clear';\nimport SearchIcon from '@mui/icons-material/Search';\nimport { useIntl } from 'react-intl';\nimport { useSearchParams } from 'react-router-dom';\nimport useMediaQuery from '@mui/material/useMediaQuery';\nimport { useTheme } from '@mui/material/styles';\n\ninterface SearchProps {\n queryStringKey?: string;\n expandable?: boolean;\n}\n\n// Styled component for the TextField\nconst StyledTextField = styled(TextField, {\n shouldForwardProp: (prop: string) =>\n !['$expandable', '$focused', '$hasValue', '$isLg'].includes(prop),\n})<{\n $expandable: boolean;\n $focused: boolean;\n $hasValue: boolean;\n $isLg: boolean;\n}>(({ $expandable, $focused, $hasValue, $isLg }) => ({\n width: $isLg && $expandable ? ($focused || $hasValue ? '100%' : '28%') : 'auto',\n transition: 'width 0.3s ease',\n}));\n\nfunction Search({ queryStringKey = 'q', expandable = false }: SearchProps) {\n const intl = useIntl();\n const [searchParams, setSearchParams] = useSearchParams();\n const search = searchParams.get(queryStringKey);\n const [focused, setFocused] = useState(false);\n const value = search || '';\n const inputRef = useRef(null);\n\n const theme = useTheme();\n const isMd = useMediaQuery(theme.breakpoints.up('md'));\n\n const setValue = (event: React.ChangeEvent) => {\n if (!event.target.value) {\n searchParams.delete(queryStringKey);\n } else {\n searchParams.set(queryStringKey, event.target.value);\n }\n setSearchParams(searchParams);\n };\n\n useEffect(() => {\n if (focused) {\n inputRef.current?.focus();\n }\n }, [focused]);\n\n const clear = (\n {\n setValue({ target: { value: '' } } as React.ChangeEvent);\n inputRef.current?.focus();\n }}\n size=\"large\"\n sx={{ visibility: value ? 'visible' : 'hidden' }}\n >\n \n \n );\n\n return (\n setFocused(true)}\n onClick={() => setFocused(true)}\n onBlur={() => setFocused(false)}\n $expandable={expandable}\n $focused={focused}\n $hasValue={!!value}\n $isLg={isMd}\n InputProps={{\n startAdornment: (\n \n \n \n ),\n endAdornment: {clear},\n }}\n inputProps={{\n 'aria-label': 'search',\n }}\n />\n );\n}\n\nexport default Search;\n"],"names":["StyledTextField","styled","TextField","shouldForwardProp","prop","includes","_ref","$expandable","$focused","$hasValue","$isLg","width","transition","Search","_ref2","_ref2$queryStringKey","queryStringKey","_ref2$expandable","expandable","intl","useIntl","_useSearchParams","useSearchParams","_useSearchParams2","_slicedToArray","searchParams","setSearchParams","search","get","_useState","useState","_useState2","focused","setFocused","value","inputRef","useRef","theme","useTheme","isMd","useMediaQuery","breakpoints","up","setValue","event","target","set","useEffect","_inputRef$current","current","focus","clear","createElement","IconButton","onClick","_inputRef$current2","size","sx","visibility","ClearIcon","color","React","variant","onChange","placeholder","formatMessage","id","onFocus","onBlur","InputProps","startAdornment","InputAdornment","position","SearchIcon","endAdornment","inputProps"],"mappings":";u1BAgBA,IAAMA,EAAkBC,EAAOC,EAAW,CACxCC,kBAAmB,SAACC,EAAY,CAC9B,MAAA,CAAC,CAAC,cAAe,WAAY,YAAa,OAAO,EAAEC,SAASD,CAAI,CAAA,CACpE,CAAC,EAKE,SAAAE,EAAA,CAAGC,IAAAA,EAAWD,EAAXC,YAAaC,EAAQF,EAARE,SAAUC,EAASH,EAATG,UAAWC,EAAKJ,EAALI,MAAa,MAAA,CACnDC,MAAOD,GAASH,EAAeC,GAAYC,EAAY,OAAS,MAAS,OACzEG,WAAY,iBACd,CAAC,CAAC,EAEF,SAASC,EAAMC,EAA4D,CAAA,IAAAC,EAAAD,EAAzDE,eAAAA,EAAcD,IAAG,OAAA,IAAGA,EAAAE,EAAAH,EAAEI,WAAAA,EAAUD,IAAG,OAAA,GAAKA,EAClDE,EAAOC,EAAQ,EACrBC,EAAwCC,EAAAA,EAAiBC,EAAAC,EAAAH,EAAA,CAAA,EAAlDI,EAAYF,EAAA,CAAA,EAAEG,EAAeH,EAAA,CAAA,EAC9BI,EAASF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