| 1 |
import { computed } from 'vue' |
| 2 |
import { useProFeatures } from '@/composables/useProFeatures' |
| 3 |
|
| 4 |
type LicenseInfo = { |
| 5 |
status?: string |
| 6 |
plan?: string |
| 7 |
} |
| 8 |
|
| 9 |
export function useProAccess() { |
| 10 |
const pro = useProFeatures() |
| 11 |
|
| 12 |
const isLoaded = computed(() => pro.loaded.value) |
| 13 |
const isLitePlan = computed(() => pro.plan.value === 'lite') |
| 14 |
|
| 15 |
const isProInstalled = computed(() => { |
| 16 |
if (typeof window === 'undefined') { |
| 17 |
return false |
| 18 |
} |
| 19 |
|
| 20 |
const scriptsLoaded = |
| 21 |
(window as { ivyFormsProScripts?: Record<string, string> }).ivyFormsProScripts !== |
| 22 |
undefined || |
| 23 |
(window as { IvyFormsProScripts?: Record<string, string> }).IvyFormsProScripts !== undefined |
| 24 |
|
| 25 |
return scriptsLoaded && !!window.IvyForms?.pro |
| 26 |
}) |
| 27 |
|
| 28 |
const isLicenseActive = computed(() => { |
| 29 |
if (!isProInstalled.value) { |
| 30 |
return false |
| 31 |
} |
| 32 |
|
| 33 |
const license = pro.license.value as LicenseInfo | null |
| 34 |
if (!license) { |
| 35 |
return false |
| 36 |
} |
| 37 |
|
| 38 |
return license.status === 'valid' && license.plan !== 'lite' |
| 39 |
}) |
| 40 |
|
| 41 |
// Canonical Pro gate for feature access in the admin UI. |
| 42 |
const isProActivated = computed( |
| 43 |
() => isLoaded.value && isProInstalled.value && isLicenseActive.value && !isLitePlan.value, |
| 44 |
) |
| 45 |
|
| 46 |
const canUseFeature = (featureSlug: string) => { |
| 47 |
return isProActivated.value && pro.hasFeature(featureSlug) |
| 48 |
} |
| 49 |
|
| 50 |
return { |
| 51 |
isLoaded, |
| 52 |
isLitePlan, |
| 53 |
isProInstalled, |
| 54 |
isLicenseActive, |
| 55 |
isProActivated, |
| 56 |
canUseFeature, |
| 57 |
} |
| 58 |
} |
| 59 |
|