{"version":3,"file":"context-geolocation-DlHZrmaf.cjs","names":[],"sources":["../src/contexts/context-geolocation/context.tsx","../src/contexts/context-geolocation/context.hooks.ts"],"sourcesContent":["import { usePermission } from '@local/contexts/context-permission';\n\nimport { createContext, FC, useEffect, useState } from 'react';\n\nimport { IGeolocationContext, IGeolocationProvider } from './context.types';\n\nexport const GeolocationContext = createContext<IGeolocationContext | null>(null);\n\nexport const ProviderGeolocation: FC<IGeolocationProvider> = (props) => {\n  const { geolocationPermission, requestGeolocationPermission } = usePermission();\n\n  const [location, setLocation] = useState<GeolocationPosition | null>(null);\n  const [error, setError] = useState<GeolocationPositionError | null>(null);\n\n  // biome-ignore lint/correctness/useExhaustiveDependencies: <explanation>\n  useEffect(() => {\n    const handleSuccess = (position: GeolocationPosition) => {\n      setLocation(position);\n    };\n\n    const handleError = (error: GeolocationPositionError) => {\n      setError(error);\n    };\n\n    if (geolocationPermission === 'granted') {\n      navigator.geolocation.getCurrentPosition(handleSuccess, handleError);\n    }\n  }, [geolocationPermission, props.isAskEntrance, requestGeolocationPermission]);\n\n  useEffect(() => {\n    if (props.isAskEntrance) {\n      if (geolocationPermission !== 'granted') {\n        requestGeolocationPermission();\n      }\n    }\n  }, [geolocationPermission, props.isAskEntrance, requestGeolocationPermission]);\n  return (\n    <GeolocationContext.Provider\n      value={{\n        requestGeolocationPermission,\n        geolocationPermission,\n        location,\n        error,\n      }}\n    >\n      {props.children}\n    </GeolocationContext.Provider>\n  );\n};\n","import { useContext } from 'react';\n\nimport { GeolocationContext } from './context';\nimport { IGeolocationContext } from './context.types';\n\nexport const useGeolocation = (): IGeolocationContext => {\n  const context = useContext(GeolocationContext);\n  if (!context) {\n    throw new Error('useGeolocation must be used within an ProviderGeolocation');\n  }\n  return context;\n};\n"],"mappings":"6IAMA,IAAa,KAAA,EAAA,eAA+D,IAAA,EAE/D,EAAiD,GAAU,CACtE,KAAM,CAAE,sBAAA,EAAuB,6BAAA,CAAA,EAAiC,EAAA,cAAA,EAE1D,CAAC,EAAU,CAAA,KAAA,EAAA,UAAoD,IAAA,EAC/D,CAAC,EAAO,CAAA,KAAA,EAAA,UAAsD,IAAA,EAGpE,SAAA,EAAA,WAAA,IAAgB,CACd,MAAM,EAAiB,GAAkC,CACvD,EAAY,CAAA,GAGR,EAAe,GAAoC,CACvD,EAAS,CAAA,GAGP,IAA0B,WAC5B,UAAU,YAAY,mBAAmB,EAAe,CAAA,GAEzD,CAAC,EAAuB,EAAM,cAAe,EAA6B,KAE7E,EAAA,WAAA,IAAgB,CACV,EAAM,eACJ,IAA0B,WAC5B,EAAA,GAGH,CAAC,EAAuB,EAAM,cAAe,EAA6B,KAE3E,EAAA,KAAC,EAAmB,SAApB,CACE,MAAO,CACL,6BAAA,EACA,sBAAA,EACA,SAAA,EACA,MAAA,YAGD,EAAM,SACqB,GCzCrB,EAAA,IAA4C,CACvD,MAAM,KAAA,EAAA,YAAqB,CAAA,EAC3B,GAAI,CAAC,EACH,MAAM,IAAI,MAAM,2DAAA,EAElB,OAAO"}