import type { ComponentType, ReactNode } from "react" import type { ZodType } from "zod" import type { OrderFormWidgets } from "../forms/order/types" // ── Region config ─────────────────────────────────────────────────────────── // Shape must stay consistent with all src/config/regions/*/config.ts files. export interface RegionConfig { id: string locale: string currency: string dateFormat: string numberFormat: { decimal: string; thousands: string } features: { showDetailsTab: boolean showAnalyticsTab: boolean enableExport: boolean enableOrderForm: boolean } } // ── Components ────────────────────────────────────────────────────────────── export interface PricingWidgetProps { amount: number } export interface RegionalComponents { PricingWidget: ComponentType } // ── Logic ─────────────────────────────────────────────────────────────────── export interface RegionalLogic { /** Format a numeric amount as a display string (currency symbol, tax label etc.) */ formatAmount: (amount: number) => string /** Return true if the amount is valid for this region */ validateAmount: (amount: number) => boolean } /** * Each region's logic.ts exports a factory so region config is injected * at assembly time — not imported statically inside the function body. */ export type LogicFactory = (config: RegionConfig) => RegionalLogic // ── Add-ons ───────────────────────────────────────────────────────────────── export interface RegionalAddons { /** * Components that wrap the entire MFE (outermost first). * Applied as nested wrappers inside AppContainer. * Example: [GDPRConsentBanner] wraps the whole tab layout. */ wrappers: ComponentType<{ children: ReactNode }>[] } // ── Forms ──────────────────────────────────────────────────────────────────── // One named key per form. Each key holds Partial so regions // only declare the fields they override — missing keys fall back to defaults. // Adding a new form: add its key here and add its merge line in registry.ts. export interface RegionalForms { OrderForm: Partial } // ── Flows ───────────────────────────────────────────────────────────────── // Optional slot — only declare if this region injects steps into a flow. // Each key matches FlowDefinition.id. v1: add-only (no step removal). // Adding a new flow key here does NOT require changes to other regions. export type FlowExtraStep = { /** ID of the default step to inject after */ after: string /** Unique ID for this new step */ id: string /** Component to render for this step */ component: ComponentType } export type RegionalFlows = { [flowId: string]: { extraSteps?: FlowExtraStep[] } } // ── Validation ──────────────────────────────────────────────────────────── // Optional slot — inject region-specific Zod schema augmentations and/or // extra validate functions into createForm and createFlow. // Adding validators here does NOT require changes to other regions. export interface RegionalValidation { forms?: { [formId: string]: { /** Wrap the base Zod schema to add regional refinements. */ schema?: (base: ZodType) => ZodType /** Extra field-keyed errors merged on top of Zod errors. Regional errors take precedence. */ validate?: (data: unknown) => Record } } flows?: { [flowId: string]: { [stepId: string]: (data: unknown) => Record } } } // ── Registry ───────────────────────────────────────────────────────────────── // This is the single authoritative list of extension points. // Every region index.ts must export an object satisfying this interface. // Adding a field here will immediately surface compile errors in all regions. export interface RegionalRegistry { config: RegionConfig components: RegionalComponents forms: RegionalForms logic: RegionalLogic addons: RegionalAddons flows?: RegionalFlows validation?: RegionalValidation }