1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[35076],{35076:(t,e,a)=>{a.d(e,{X:()=>h});var c=a(10254),o=a(88738),s=a(80883),r=a(87055);async function i(t){try{let i;for(let n of(await (0,c.GG)((0,c.P)((0,c.rJ)(s.db,"matchSubmissions"),(0,c._M)("userId","==",t)))).docs){var e,a,o,r;let t=n.data(),c=null===(a=t.submittedAt)||void 0===a?void 0:null===(e=a.toDate)||void 0===e?void 0:e.call(a),s=null==i?void 0:null===(r=i.submittedAt)||void 0===r?void 0:null===(o=r.toDate)||void 0===o?void 0:o.call(r);(!i||c&&s&&c>s)&&(i=t)}return(null==i?void 0:i.level)==="masters"||(null==i?void 0:i.level)==="phd"?"/scholarships":"/results"}catch(t){return"/results"}}async function n(t){let e;try{return await Promise.race([o.O.getLatestMatchedSchools(t),new Promise(t=>{e=setTimeout(()=>t(null),8e3)})])}finally{e&&clearTimeout(e)}}let l=new Map;function h(t){let e=l.get(t);if(e)return e;let a=d(t).then(t=>((0,r.Wc)(t),t)).finally(()=>l.delete(t));return l.set(t,a),a}async function d(t){try{var e,a,c,s;let r=await o.O.getCachedMatchedSchools(t);if(r&&(null===(e=r.data)||void 0===e?void 0:e.success)&&(null===(c=r.data)||void 0===c?void 0:null===(a=c.data)||void 0===a?void 0:a.matchedSchools)&&r.data.data.matchedSchools.length>0)return o.O.getLatestMatchedSchools(t).then(async e=>{var a,c;e.success&&(null===(c=e.data)||void 0===c?void 0:null===(a=c.matchedSchools)||void 0===a?void 0:a.length)>0&&await o.O.cacheMatchedSchools(t,e)}).catch(()=>{}),i(t);try{let e=await n(t);if(e&&e.success&&(null===(s=e.data)||void 0===s?void 0:s.matchedSchools)&&e.data.matchedSchools.length>0)return await o.O.cacheMatchedSchools(t,e),await i(t)}catch(t){}return"/match"}catch(t){return"/match"}}},88738:(t,e,a)=>{a.d(e,{C:()=>r,O:()=>i}),a(76097);var c=a(19475);function o(t){if("string"==typeof t)return t;if(t&&"object"==typeof t&&"_seconds"in t){let e=t._seconds;if("number"==typeof e)return new Date(1e3*e).toISOString().split("T")[0]}}function s(t){return{...t,apply_date:o(t.apply_date),start_date:o(t.start_date)}}class r extends Error{constructor(t,e,a=!1,c){super(t),this.name="LatestMatchRequestError",this.status=e,this.needsRegeneration=a,this.submissionId=c}}class i{static get API_URL(){return"".concat((0,c.fr)().functionsUrl,"/getMatchedSchools")}static get LATEST_API_URL(){return"".concat((0,c.fr)().functionsUrl,"/getLatestMatchedSchools")}static get SCHOOL_BY_ID_URL(){return"".concat((0,c.fr)().functionsUrl,"/getSchoolById")}static async fetchWithTimeout(t){let e=await (0,c.fr)().getIdToken();if(!e)throw Error("Authentication required");let a=new AbortController,o=setTimeout(()=>a.abort(),this.FETCH_TIMEOUT_MS);return(0,c.fr)().fetchImpl(t,{signal:a.signal,headers:{Authorization:"Bearer ".concat(e)},cache:"no-store"}).finally(()=>clearTimeout(o))}static async getMatchedSchools(t){try{var e;let a=await this.fetchWithTimeout("".concat(this.API_URL,"?userId=").concat(encodeURIComponent(t)));if(!a.ok)throw Error("HTTP error! status: ".concat(a.status));let c=await a.json();if(!c.success)throw Error("API returned unsuccessful response");return(null===(e=c.data)||void 0===e?void 0:e.matchedSchools)&&(c.data.matchedSchools=c.data.matchedSchools.map(s)),c}catch(t){if((null==t?void 0:t.name)==="AbortError")throw Error("Request timed out. Please check your connection and try again.");throw Error("Failed to fetch matched schools. Please try again.")}}static async getLatestMatchedSchools(t){try{var e;let a=await this.fetchWithTimeout("".concat(this.LATEST_API_URL,"?userId=").concat(encodeURIComponent(t)));if(!a.ok){let t={};try{t=await a.json()}catch(t){}throw new r(t.error||"Unable to load the latest school match (status ".concat(a.status,")."),a.status,!0===t.needsRegeneration,t.submissionId)}let c=await a.json();if(!c.success)throw Error("API returned unsuccessful response");return(null===(e=c.data)||void 0===e?void 0:e.matchedSchools)&&(c.data.matchedSchools=c.data.matchedSchools.map(s)),c}catch(t){if((null==t?void 0:t.name)==="AbortError")throw Error("Request timed out. Please check your connection and try again.");if(t instanceof r)throw t;throw Error("Failed to fetch latest matched schools. Please try again.")}}static async getSchoolDetails(t,e){try{var a,c,o;let s=await this.getMatchedSchoolsWithCache(t),r=s.success?null===(c=s.data)||void 0===c?void 0:null===(a=c.matchedSchools)||void 0===a?void 0:a.find(t=>String(t.id)===String(e)):void 0;if(r)return{school:r,fromLatestMatch:!0,gapInfo:null===(o=s.data)||void 0===o?void 0:o.gapInfo}}catch(t){}let s=await this.fetchWithTimeout("".concat(this.SCHOOL_BY_ID_URL,"?schoolId=").concat(encodeURIComponent(String(e)))
1);if(!s.ok)return null;let r=await s.json().catch(()=>null);return(null==r?void 0:r.success)&&r.data?{school:{...r.data,matchScore:0,matchPercentage:0},fromLatestMatch:!1}:null}static async getMatchedSchoolsWithCache(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];try{var a;let c,o=await i.getCachedMatchedSchools(t);if(!e&&o&&this.isCacheValid(o))return this.checkForNewerData(t,o).catch(()=>{}),o.data;try{c=await this.getLatestMatchedSchools(t)}catch(e){if(e instanceof r&&e.needsRegeneration){if(!e.submissionId)throw Error("Create your school match first to see your results.");return await this.recoverIncompleteMatch(t)}throw e}if(c.success&&Array.isArray(null===(a=c.data)||void 0===a?void 0:a.matchedSchools))return await this.cacheMatchedSchools(t,c),c;if(o&&this.isCacheValid(o))return o.data;return c}catch(a){let e=await i.getCachedMatchedSchools(t);if(e&&this.isCacheValid(e))return e.data;throw a}}static recoverIncompleteMatch(t){let e=this.recoveryRequests.get(t);if(e)return e;let a=this.getMatchedSchools(t).then(async e=>{var a,c;return e.success&&(null===(c=e.data)||void 0===c?void 0:null===(a=c.matchedSchools)||void 0===a?void 0:a.length)>0&&await this.cacheMatchedSchools(t,e),e}).finally(()=>{this.recoveryRequests.delete(t)});return this.recoveryRequests.set(t,a),a}static async checkForNewerData(t,e){try{var a,o,s,r,i;let n=await this.getLatestMatchedSchools(t);if(!n.success||!(null===(o=n.data)||void 0===o?void 0:null===(a=o.matchedSchools)||void 0===a?void 0:a.length))return;let l=(null===(s=n.data.generatedAt)||void 0===s?void 0:s._seconds)?1e3*n.data.generatedAt._seconds:0,h=e.timestamp;l>h&&(await this.cacheMatchedSchools(t,n),null===(r=(i=(0,c.fr)()).emitEvent)||void 0===r||r.call(i,"schoolDataUpdated",{hasNewerData:!0}))}catch(t){}}static async getCachedMatchedSchools(t){try{var e;return await (null===(e=(0,c.fr)().matchCache)||void 0===e?void 0:e.get(t))||null}catch(t){return null}}static async cacheMatchedSchools(t,e){try{var a,o;let s=(null===(a=e.data.generatedAt)||void 0===a?void 0:a._seconds)?1e3*e.data.generatedAt._seconds:Date.now(),r={data:e,timestamp:s,userId:t,submissionId:e.data.submissionId,version:this.CACHE_VERSION};await (null===(o=(0,c.fr)().matchCache)||void 0===o?void 0:o.put(t,r))}catch(t){}}static isCacheValid(t){return t.version===this.CACHE_VERSION&&Date.now()-t.timestamp<this.CACHE_DURATION}static async clearCache(t){try{var e;await (null===(e=(0,c.fr)().matchCache)||void 0===e?void 0:e.delete(t))}catch(t){}}static async getCacheAge(t){try{let e=await i.getCachedMatchedSchools(t);if(!e)return null;return Date.now()-e.timestamp}catch(t){return null}}static async shouldRefresh(t){let e=await this.getCacheAge(t);return null===e||e>=this.CACHE_DURATION}}i.CACHE_DURATION=18e6,i.CACHE_VERSION=4,i.FETCH_TIMEOUT_MS=9e4,i.recoveryRequests=new Map}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.