import { PLAN_LIMITS } from '~/app/utils/planLimits'
import type { PlanTier } from '~/app/utils/planLimits'

export const useSubscription = () => {
  const orgStore = useOrg()

  const plan = computed<PlanTier>(() => (orgStore.plan as PlanTier) || 'free')
  const limits = computed(() => PLAN_LIMITS[plan.value])

  const canAddEmployee = (currentCount: number) => {
    const limit = limits.value.employee_limit
    return limit === Infinity || currentCount < limit
  }

  const canExportPDF = computed(() => limits.value.pdf_export)
  const canExportExcel = computed(() => limits.value.excel_export)
  const isFreePlan = computed(() => plan.value === 'free')

  return { plan, limits, canAddEmployee, canExportPDF, canExportExcel, isFreePlan }
}
