import{xt as e}from"./De2yIhEs.js";import{t}from"./Cj9ecUMW.js";import{Y as n,ft as r}from"./DVD-VP-F.js";function i(e){return typeof e==`string`?e:e&&typeof e==`object`&&`display_name`in e?e.display_name??e.code??null:null}var a=typeof window>`u`?void 0:window.sentientFormsConfig,o=a?.license??{},s={loading:!1,status:o.status??`inactive`,licenseKeyMasked:o.licenseKeyMasked??``,proxyKeyPresent:o.proxyKeyPresent??!1,tier:i(o.tier),expiresAt:o.expiresAt??null,lastSynced:o.lastSynced??null,licenseId:o.licenseId??null,siteId:o.siteId??null,siteUrl:a?.siteUrl??``,error:null};function c(e){return{loading:!1,status:e.status,licenseKeyMasked:e.license_key_masked??``,proxyKeyPresent:!!e.proxy_key_present,tier:i(e.tier),expiresAt:e.expires_at??null,lastSynced:e.last_synced??null,licenseId:e.license_id??null,siteId:e.site_id??null,siteUrl:e.site_url??s.siteUrl,error:null}}const l=e({...s});var u=n(),d=t(()=>l);function f(e){Object.assign(l,e)}async function p(){let e=await u.getLicenseInfo({showNotifications:!1});return e.proxy_key_present?e:u.bootstrapLicense({showNotifications:!1})}async function m(){f({loading:!0,error:null});try{f(c(await p()))}catch(e){console.error(`Failed to load license info`,e),f({loading:!1,error:`load`})}}async function h(e){if(!e){r.error(a?.i18n?.errorOccurred??`License key required`);return}f({loading:!0,status:`activating`,error:null});try{let t=await u.activateLicense({licenseKey:e,siteUrl:a?.siteUrl??``,localSiteIdentifier:a?.localSiteIdentifier??``},{showNotifications:!0});r.success(t.message),await m()}catch(e){console.error(`License activation failed`,e),f({loading:!1,status:`error`,error:`activate`})}}async function g(){f({loading:!0,error:null});try{await u.deactivateLicense({showNotifications:!0}),r.success(`License deactivated`),await m()}catch(e){console.error(`License deactivation failed`,e),f({loading:!1,error:`deactivate`})}}const _={subscribe:d.subscribe,load:m,activate:h,deactivate:g,reset:()=>f(s)};export{_ as n,l as t};