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