{"version":3,"file":"JobsCountOverride.BiRGPNlI.mjs","names":["useRef","__esmMin","init_npm_react_18_3_1","de","window","init_ssg_sandbox_shims","init_jsx_runtime","J","ce","init_framer_BkYB2Gqq","RenderTarget","readCache","raw","CACHE_KEY","CACHE_TTL","writeCache","fetchCount","res","SEARCH_URL","json","XML_URL","m","cards","getJobsCount","cached","pending","n","injectCount","walker","el","nodes","node","count","withJobsCount","anchorRef","cancelled","timers","apply","t","Component","props","init_JobsCountOverride"],"sources":["https:/framerusercontent.com/modules/v0CI0BFOHMScmageZ6a3/zafkZqh4yIvQLkVnIVIo/JobsCountOverride.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import{forwardRef,useEffect,useRef}from\"react\";import{RenderTarget}from\"framer\";// Live count of open positions, read from the public Personio feed - the\n// same source the Personio Sync CMS plugin syncs from. Because it is a\n// plain HTTPS fetch, it works on ANY page of the site, even where the\n// Job Board component is not present.\nconst SEARCH_URL=\"https://astrafy.jobs.personio.de/search.json\";const XML_URL=\"https://astrafy.jobs.personio.de/xml\";const CACHE_KEY=\"astrafy-jobs-count\";const CACHE_TTL=10*60*1e3// 10 minutes\n;// One in-flight request shared by every layer using the override.\nlet pending=null;function readCache(){try{const raw=window.sessionStorage.getItem(CACHE_KEY);if(!raw)return null;const{t,n}=JSON.parse(raw);if(typeof n!==\"number\"||Date.now()-t>CACHE_TTL)return null;return n;}catch(_){return null;}}function writeCache(n){try{window.sessionStorage.setItem(CACHE_KEY,JSON.stringify({t:Date.now(),n}));}catch(_){}}async function fetchCount(){// Primary: the JSON search endpoint (an array, one entry per job).\ntry{const res=await fetch(SEARCH_URL);if(res.ok){const json=await res.json();if(Array.isArray(json))return json.length;}}catch(_){}// Fallback: the XML feed (one <position> element per job).\ntry{const res=await fetch(XML_URL);if(res.ok){const xml=await res.text();const m=xml.match(/<position>/g);if(m)return m.length;}}catch(_){}// Last resort: count the Job Board cards if one is on the page.\nconst cards=document.querySelectorAll(\"[data-job-card]\");return cards.length>0?cards.length:null;}function getJobsCount(){const cached=readCache();if(cached!==null)return Promise.resolve(cached);if(!pending){pending=fetchCount().then(n=>{pending=null;if(n!==null)writeCache(n);return n;});}return pending;}// Replace \"{n}\" (checked first) or the first run of digits found in the\n// layer's text nodes. Only the text node DATA is touched, so the layer\n// keeps its text style, spans and line breaks exactly as designed.\nfunction injectCount(el,count){const walker=document.createTreeWalker(el,NodeFilter.SHOW_TEXT);const nodes=[];while(walker.nextNode())nodes.push(walker.currentNode);for(const node of nodes){if(node.data.indexOf(\"{n}\")!==-1){node.data=node.data.split(\"{n}\").join(String(count));return true;}}for(const node of nodes){if(/\\d+/.test(node.data)){node.data=node.data.replace(/\\d+/,String(count));return true;}}return false;}/**\n * withJobsCount\n *\n * Apply to any TEXT layer, on any page. On the live site the first number\n * in the text (or a \"{n}\" token, which wins if present) is replaced by the\n * current number of open positions on Personio. Write a realistic number\n * in the design (e.g. \"8 open positions\") so nothing flashes before the\n * live value arrives. On the canvas the text is never touched.\n */export function withJobsCount(Component){return /*#__PURE__*/forwardRef(function WithJobsCount(props,ref){const anchorRef=useRef(null);useEffect(()=>{if(RenderTarget.current()===RenderTarget.canvas)return;let cancelled=false;const timers=[];const apply=count=>{if(cancelled||!anchorRef.current)return;const done=injectCount(anchorRef.current,count);// The text can mount/hydrate a beat later than the effect,\n// retry briefly instead of giving up.\nif(!done&&timers.length<3){timers.push(window.setTimeout(()=>apply(count),250*(timers.length+1)));}};getJobsCount().then(count=>{if(count!==null)apply(count);});return()=>{cancelled=true;timers.forEach(t=>window.clearTimeout(t));};},[]);// display:contents wrapper = a guaranteed DOM anchor around the text\n// layer without affecting layout (refs are not reliably forwarded to\n// the DOM by Framer text primitives).\nreturn /*#__PURE__*/_jsx(\"span\",{ref:anchorRef,style:{display:\"contents\"},children:/*#__PURE__*/_jsx(Component,{...props,ref:ref})});});}\nexport const __FramerMetadata__ = {\"exports\":{\"withJobsCount\":{\"type\":\"reactHoc\",\"name\":\"withJobsCount\",\"annotations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