import type { ModuleDefinition, ModuleStatus, TenantContext } from "../../types/src/index";

export function moduleStatusLabel(status: ModuleStatus): string {
  switch (status) {
    case "active":
      return "Disponibile";
    case "inactive":
      return "Su richiesta";
    case "in-development":
      return "In arrivo";
    default:
      return status;
  }
}

export function moduleStatusTone(status: ModuleStatus): string {
  switch (status) {
    case "active":
      return "is-active";
    case "inactive":
      return "is-inactive";
    case "in-development":
      return "is-development";
    default:
      return "is-inactive";
  }
}

export function isModuleEnabled(context: TenantContext, moduleKey: ModuleDefinition["key"]): boolean {
  const match = context.tenant_modules.find((entry) => entry.module_key === moduleKey);
  return Boolean(match?.enabled);
}

export function modulePlanName(context: TenantContext, moduleKey: ModuleDefinition["key"]): string {
  const match = context.tenant_modules.find((entry) => entry.module_key === moduleKey);
  return match?.plan_name ?? "Non assegnato";
}
