"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=>{var r;const s=e.reduce((e,t)=>(e.set(t.name,t.value),e),new Map),o={start:new Date(s.get("StartDate")),end:new Date(s.get("EndDate")),owner:s.get("Owner"),appName:s.get("AppName")||exports.GENERIC_APP_NAME,timestamp:s.get("TS")?Number(s.get("TS")):0,trial:"true"===s.get("Trial"),ref:null!==(r=s.get("Ref"))&&void 0!==r?r:""};if(!(o.start&&o.end&&o.owner&&"boolean"==typeof o.trial&&o.ref))throw t();return o};exports.fieldsToLicenseDetails=r;const s=r=>{let s="",o=r.split("|").map(e=>{let[t,r]=e.split("=");return"C"===t&&(s=r),{name:t,value:r}});if(!s)throw t();const a=s.split(",").reverse(),n=a.pop();a.forEach((r,s)=>{const a=o[s];if((0,e.compute_string)(a.value)!==r)throw t()});const i=[...o];i.pop();const p=i.map(e=>`${e.name}=${e.value}`).join("|");if((0,e.compute_string)(p)!==n)throw t();return o=o.map(e=>Object.assign(Object.assign({},e),{value:decodeURI(e.value)})),(0,exports.fieldsToLicenseDetails)(o)};exports.decode=s;