import{compute_string as e}from"./hashing";const t=()=>new Error("Invalid License");export const GENERIC_APP_NAME="GenericAdaptableApp";export const fieldsToLicenseDetails=e=>{const r=e.reduce(((e,t)=>(e.set(t.name,t.value),e)),new Map),a={start:new Date(r.get("StartDate")),end:new Date(r.get("EndDate")),owner:r.get("Owner"),appName:r.get("AppName")||GENERIC_APP_NAME,timestamp:r.get("TS")?Number(r.get("TS")):0,trial:"true"===r.get("Trial"),ref:r.get("Ref")??""};if(!(a.start&&a.end&&a.owner&&"boolean"==typeof a.trial&&a.ref))throw t();return a};export const decode=r=>{let a="",n=r.split("|").map((e=>{let[t,r]=e.split("=");return"C"===t&&(a=r),{name:t,value:r}}));if(!a)throw t();const o=a.split(",").reverse(),s=o.pop();o.forEach(((r,a)=>{const o=n[a];if(e(o.value)!==r)throw t()}));const p=[...n];p.pop();const i=p.map((e=>`${e.name}=${e.value}`)).join("|");if(e(i)!==s)throw t();return n=n.map((e=>({...e,value:decodeURI(e.value)}))),fieldsToLicenseDetails(n)};