{"version":3,"sources":["webpack:///./src/components/global/Conditional/index.tsx","webpack:///./src/hooks/checkers/useScreenChecker.ts","webpack:///./src/hooks/checkers/useLocationChecker.ts"],"names":["useResolvedChecker","checker","_type","useState","met","setMet","query","breakPoint","controller","AbortController","React","useEffect","result","matchMedia","addEventListener","event","matches","signal","abort","useScreenChecker","useLocation","country","state","location","modules","setModules","options","filter","map","module","toLowerCase","push","nonMarket","find","option","matched","useLocationChecker","console","warn","Conditional","data","forceState","content","metModules","unmetModules","RenderModules","renderCheckerModules"],"mappings":"yLAuBMA,G,UAAqB,SAACC,GAC1B,MAAsB,kBAAlBA,EAAQC,MCjBC,SAACD,GAA2B,MACnBE,oBAAS,GAAxBC,EADkC,KAC7BC,EAD6B,KAEnCC,EAAQ,eAAeL,EAAQM,WAA1B,MACLC,EAAa,IAAIC,gBAiBvB,OAfAC,IAAMC,WAAU,WAKd,IAAMC,EAASC,WAAWP,GAK1B,OAHAM,EAAOE,iBAAiB,UANxB,SAAkBC,GAChBV,EAAOU,EAAMC,WAK6B,CAAEC,OAAQT,EAAWS,SACjEZ,EAAOO,EAAOI,SAEP,WACLR,EAAWU,WAEZ,CAACZ,IAEGF,EDFEe,CAAiBlB,GACG,oBAAlBA,EAAQC,MErBa,SAACD,GAGxB,MAC4BmB,cAA7BC,EADC,EACDA,QAASC,EADR,EACQA,MAAOC,EADf,EACeA,SADf,EAEqBpB,mBAAc,MAArCqB,EAFE,KAEOC,EAFP,KA0CT,OAtCAd,qBAAU,WACR,IAAMe,GAAWzB,EAAQyB,SAAW,IACjCC,QAAO,sBAAGJ,YACVK,KAAI,gBAAGL,EAAH,EAAGA,SAAUM,EAAb,EAAaA,OAAb,MAA2B,CAC9BN,SAAUA,EAASO,cACnBD,aAIJH,EAAQK,KAAK,CAAER,SAlBG,gBAkBsBM,OAAQ,OAOhD,IAAMG,EAAYN,EAAQO,MACxB,SAAAC,GAAM,MA1BU,kBA0BNA,EAAOX,YAMnB,GAAgB,OAAZF,EACFI,EAAWO,EAAUH,YAChB,CACL,IAAIM,EAAUT,EAAQO,MAAK,SAAAC,GAAM,OAAIA,EAAOX,WAAaA,KAGpDY,IACHA,EAAUT,EAAQO,MAAK,SAAAC,GAAM,OAAIA,EAAOX,WAAaD,MAGvDG,EAAWU,EAAUA,EAAQN,OAASG,EAAUH,WAGjD,CAAC5B,EAAQyB,QAASH,EAAUF,EAASC,IAEjCE,EFvBEY,CAAmBnC,QAG5BoC,QAAQC,KAAK,wBAAyBrC,EAAQC,SAiEjCqC,UAnCK,SAAC,GAA+B,IAA7BC,EAA6B,EAA7BA,KAA6B,EACdrC,mBAAS,YAAtCsC,EAD2C,KAE5CxC,GAF4C,KAElCuC,EAAKvC,QAAQ,IAEvByC,EAvBqB,SAC3BzC,EACAW,EACA+B,EACAC,GAEA,MAAsB,kBAAlB3C,EAAQC,MACHU,EACHiC,YAAcF,GAAc,IAC5BE,YAAcD,GAAgB,IACP,oBAAlB3C,EAAQC,MAGV2C,YAAcjC,GAGhB,KAOSkC,CACd7C,EAFeD,EAAmBC,GAIlCuC,EAAKG,WACLH,EAAKI,cAQP,OACE,qCALA,EAUkB,SAAfH,GACmB,kBAAlBxC,EAAQC,OACR2C,YAAcL,EAAKG,YAAc,IAEnB,UAAfF,GACmB,kBAAlBxC,EAAQC,OACR2C,YAAcL,EAAKI,cAAgB,IAErB,aAAfH,GAA6BC","file":"24-fd93735c417760973548.js","sourcesContent":["import React, { useState } from 'react'\nimport useScreenChecker from 'src/hooks/checkers/useScreenChecker'\nimport { useLocationChecker } from 'src/hooks/checkers/useLocationChecker'\nimport { RenderModules } from 'src/utils/renderModules'\nimport { ForceSelect } from 'src/components/ForceSelect'\n\nexport interface ConditionalProps {\n data: {\n name: string\n // Exactly one checker must be defined.\n checker: any[]\n // Only used when the checker is a screen checker.\n metModules?: []\n unmetModules?: []\n }\n}\n\n/**\n * Centralizes the resolution of a checker.\n * If it's a screenchecker, return a boolean.\n * If it's a locationchecker, return the module(s) corresponding to the user's location.\n */\n\nconst useResolvedChecker = (checker: any): boolean | any => {\n if (checker._type === 'screenchecker') {\n return useScreenChecker(checker)\n } else if (checker._type === 'locationchecker') {\n return useLocationChecker(checker)\n }\n\n console.warn('Unknown checker type:', checker._type)\n\n return undefined\n}\n\n/**\n * Renders modules based on the type and result of the checker.\n * For screencheckers, renders metModules if true or unmetModules if false.\n * For locationcheckers, always renders the module(s) from the hook result.\n */\n\nconst renderCheckerModules = (\n checker: any,\n result: boolean | any,\n metModules?: [],\n unmetModules?: []\n) => {\n if (checker._type === 'screenchecker') {\n return result\n ? RenderModules(metModules || [])\n : RenderModules(unmetModules || [])\n } else if (checker._type === 'locationchecker') {\n // For location checker, we're assuming the result always includes a valid module\n // (with the fallback \"Not In Market\" always defined in the schema).\n return RenderModules(result)\n }\n\n return null\n}\n\nconst Conditional = ({ data }: ConditionalProps) => {\n const [forceState, setForceState] = useState('no-force')\n const checker = data.checker[0]\n const resolved = useResolvedChecker(checker)\n const content = renderCheckerModules(\n checker,\n resolved,\n data.metModules,\n data.unmetModules\n )\n\n const shouldShowToggle =\n (process.env.GATSBY_ENVIRONMENT === 'local' ||\n process.env.GATSBY_ENVIRONMENT === 'staging') &&\n checker._type !== 'locationchecker'\n\n return (\n <>\n {shouldShowToggle && (\n \n )}\n\n {forceState === 'true' &&\n checker._type === 'screenchecker' &&\n RenderModules(data.metModules || [])}\n\n {forceState === 'false' &&\n checker._type === 'screenchecker' &&\n RenderModules(data.unmetModules || [])}\n\n {forceState === 'no-force' && content}\n >\n )\n}\n\nexport default Conditional\n","import React, { useState } from 'react'\n\nexport type ScreenChecker = {\n _type: 'screenchecker'\n breakPoint: number\n}\n\nexport default (checker: ScreenChecker) => {\n const [met, setMet] = useState(false)\n const query = `(max-width: ${checker.breakPoint}px)`\n const controller = new AbortController()\n\n React.useEffect(() => {\n function onChange(event: MediaQueryListEvent) {\n setMet(event.matches)\n }\n\n const result = matchMedia(query)\n\n result.addEventListener('change', onChange, { signal: controller.signal })\n setMet(result.matches)\n\n return () => {\n controller.abort()\n }\n }, [query])\n\n return met\n}\n","import { useState, useEffect } from 'react'\nimport { useLocation } from '../useLocation'\n\nconst NOT_IN_MARKET = 'not in market'\n\nexport const useLocationChecker = (checker: {\n _type: 'locationchecker'\n options: Array<{ location: string; module: any }>\n}): any => {\n const { country, state, location } = useLocation()\n const [modules, setModules] = useState(null)\n\n useEffect(() => {\n const options = (checker.options || [])\n .filter(({ location }) => !!location)\n .map(({ location, module }) => ({\n location: location.toLowerCase(),\n module,\n }))\n\n // Make sure there's always a non-market option\n options.push({ location: NOT_IN_MARKET, module: null })\n\n /**\n * Check for first non-market location \n * \n * (can be the one specified in the checker or the safity one added above)\n */\n const nonMarket = options.find(\n option => option.location === NOT_IN_MARKET\n ) as { location: string; module: any }\n\n /**\n * If the country is not US, return the non-market option\n */\n if (country !== 'US') {\n setModules(nonMarket.module)\n } else {\n let matched = options.find(option => option.location === location)\n\n // If not found, check for state\n if (!matched) {\n matched = options.find(option => option.location === state)\n }\n\n setModules(matched ? matched.module : nonMarket.module)\n }\n\n }, [checker.options, location, country, state])\n\n return modules\n}\n"],"sourceRoot":""}