{error}
}\n >\n );\n } else {\n return (\n \n {formattedNumber}\n \n )\n }\n}\n\nexport default PhoneNumber;","import {\n Autocomplete, TextField, Button, Typography, Popover, Modal, Box, Dialog, DialogTitle\n} from '@mui/material'; //https://mui.com/material-ui/react-autocomplete/\nimport React, { useEffect, useMemo, useRef, useState } from 'react';\nimport { helpers, ladderHelper as lf, userHelper } from '../../../helpers/index';\nimport { GrCircleInformation } from 'react-icons/gr'\nimport debounce from 'lodash.debounce'\nimport { AiOutlineAim } from 'react-icons/ai';\n//import { playerAPI } from 'api/services';\n\nconst SelectWithFetch = ({ allowCreate = false, disabledItemList = [], disabled, selectedItem, initialItems, onItemSelect, fetchFunction, showLocationIcon = false, children, ...props }) => {\n\n const [newItem, setNewItem] = useState()\n const [showModal, setShowModal] = useState(false)\n const [options, setOptions] = useState(Array.from(initialItems))\n const [value, setValue] = useState(selectedItem || null)\n const [loading, setLoading] = useState(null)\n const [inputValue, setInputValue] = useState('')\n const [lngLat, setLngLat] = useState({lng: 0, lat: 0})\n let isFetch = typeof fetchFunction === 'function'\n const [fetchByLocation, setFetchByLocation] = useState(false)\n\n //console.log(options, initialItems, fetchFunction, props, isFetch)\n\n let createComponent\n if (!React.isValidElement(children))\n createComponent = 'no component to add'\n else\n createComponent = React.cloneElement(children, { newItem: newItem, callback: handleCreateCallback })\n\n function optionExists(searchInput) {\n return options.find(x => x.name === searchInput)\n }\n\n useEffect(() => {\n console.log('resetting options to initial')\n setValue(selectedItem || null)\n isFetch = typeof fetchFunction === 'function'\n setOptions(Array.from(initialItems))\n }, [initialItems, selectedItem])\n\n function handleCreateCallback(callbackValue) {\n console.log(callbackValue)\n setShowModal(false)\n setValue(callbackValue)\n addToOptions([callbackValue])\n onItemSelect(callbackValue)\n }\n\n function addToOptions(values) {\n let newOptions = [...options, ...values]\n .filter((x, i, self) => {\n const firstIndex = self.findIndex(obj => obj.id === x.id)\n return i === firstIndex\n }).sort((a, b) => {\n // Sort based on the name property\n return a.name.localeCompare(b.name);\n })\n console.log(newOptions)\n setOptions(newOptions)\n }\n\n const fetch = useMemo(\n () =>\n debounce((request, callback) => {\n const { input, point } = request\n let foundOption = optionExists(input)\n if (foundOption) {\n console.log('cached', foundOption)\n // If options for this input are already cached, return them\n callback([foundOption])\n } else {\n let radius = 25\n let filter = {\n ...point ? { geo: `${point.lat},${point.lng},${radius}` } : {},\n ...input ? { 'name': input } : {},\n }\n \n if (isFetch) {\n fetchFunction(filter).then((newOptions) => {\n console.log('fetch function results: ', newOptions)\n callback(newOptions)\n })\n }\n // no fetch function, use preloaded options only\n else {\n return []\n }\n }\n }, 200),\n [],\n )\n\n\n function handleSetItem(value) {\n onItemSelect(value)\n }\n\n useEffect(() => {\n let active = true\n\n isFetch = typeof fetchFunction === 'function'\n if (inputValue === '' && !fetchByLocation) {\n //setOptions(selectedItem ? [selectedItem] : (cachedOptions[''] ?? []));\n console.log('no input value -> return')\n return undefined;\n }\n\n if (isFetch) {\n fetch({ input: inputValue, point: lngLat.lat !== 0 ? lngLat : null }, (results) => {\n if (active) {\n let newOptions = [];\n\n if (value) {\n newOptions = [value]\n }\n\n if (results) {\n console.log(results)\n // add the results to the options\n // filter out duplicates\n newOptions =\n [...options, ...results]\n .filter((x, i, self) => {\n const firstIndex = self.findIndex(obj => obj.id === x.id)\n return i === firstIndex\n }).sort((a, b) => {\n // Sort based on the name property\n return a.name.localeCompare(b.name);\n })\n console.log(newOptions)\n setOptions(newOptions)\n document.getElementById(\"autocomplete_fetch_select\").focus()\n }\n }\n })\n }\n //else setOptions(initialItems)\n\n return () => {\n active = false\n setFetchByLocation(false)\n }\n }, [inputValue, lngLat])\n\n const handleAddItem = (e, val) => {\n setShowModal(true)\n setNewItem(val)\n }\n\n const getCurrentLocation = () => {\n return new Promise((resolve, reject) => {\n if (navigator.geolocation) {\n navigator.geolocation.getCurrentPosition(\n (position) => {\n resolve(position)\n },\n (error) => {\n reject(error)\n }\n );\n } else {\n reject(new Error('Geolocation is not supported by this browser.'));\n }\n })\n }\n\n const handleLocation = async () => {\n document.getElementById(\"autocomplete_fetch_select\").blur()\n setFetchByLocation(true)\n try {\n const position = await getCurrentLocation()\n console.log('Latitude:', position.coords.latitude)\n console.log('Longitude:', position.coords.longitude)\n setLngLat({lng:position.coords.longitude,lat:position.coords.latitude})\n \n } catch (error) {\n console.error('Error getting location:', error.message)\n }\n }\n\n return (\nVisible for testing.\n */\nfunction setAbortableTimeout(\n signal: AnalyticsAbortSignal,\n throttleEndTimeMillis: number\n): Promise AbortController's AbortSignal conveniently decouples fetch timeout logic from other aspects\n * of networking, such as retries. Firebase doesn't use AbortController enough to justify a\n * polyfill recommendation, like we do with the Fetch API, but this minimal shim can easily be\n * swapped out if/when we do.\n */\nexport class AnalyticsAbortSignal {\n listeners: Array<() => void> = [];\n addEventListener(listener: () => void): void {\n this.listeners.push(listener);\n }\n abort(): void {\n this.listeners.forEach(listener => listener());\n }\n}\n","/**\n * @license\n * Copyright 2019 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n AnalyticsCallOptions,\n CustomParams,\n ControlParams,\n EventParams,\n ConsentSettings\n} from './public-types';\nimport { Gtag } from './types';\nimport { GtagCommand } from './constants';\nimport { AnalyticsError, ERROR_FACTORY } from './errors';\n\n/**\n * Event parameters to set on 'gtag' during initialization.\n */\nexport let defaultEventParametersForInit: CustomParams | undefined;\n\n/**\n * Logs an analytics event through the Firebase SDK.\n *\n * @param gtagFunction Wrapped gtag function that waits for fid to be set before sending an event\n * @param eventName Google Analytics event name, choose from standard list or use a custom string.\n * @param eventParams Analytics event parameters.\n */\nexport async function logEvent(\n gtagFunction: Gtag,\n initializationPromise: Promise