/* global React */

// Shared backstage payloads — c (customer) + ops only; System column is driven entirely by PIPE below.
const BS_ENTRY = {
  type: { c: "Selected customer type", ops: "—" },
  intents: { c: "Picked goals (pillars + sub-intents)", ops: "—" },
  entity: { c: "Selected entity type and signatories", ops: "—" },
  reco: { c: "Viewed recommendation", ops: "—" },
  options: { c: "Selected product", ops: "—" },
};

const BS = {
  consent: {
    c: "Accepted Deposit Terms (FIND) · T&Cs · Data consent",
    ops: {
      target: "—",
      initial: ["Fulfilment task queue", "Email dispatch: ~5 min"],
    },
  },
  signature: { c: "Signed on canvas", ops: "—" },
  identity: { c: "Verified phone via OTP", ops: "—" },
  identityDetails: { c: "Entered full name, email, DOB, ID number", ops: "—" },
  idCapture: {
    c: "Captured ID image",
    ops: "—",
  },
  liveness: { c: "Completed liveness scan", ops: "—" },
  nuit: {
    c: {
      target: "NUIT prefetched from Tax Authority · Confirmed",
      initial: "Uploaded NUIT document",
    },
    ops: "—",
  },
  income: { c: "Entered income details", ops: "—" },
  business: {
    c: "Entered business info",
    ops: "—",
  },
  docsRequired: {
    c: "Uploaded Alvará · Certidão Comercial",
    ops: "—",
  },
  docsSupporting: {
    c: "Uploaded Modelo 11 · Business address proof",
    ops: "—",
  },
  proofAddress: {
    c: "Uploaded proof of address",
    ops: "—",
  },
  sourceOfFunds: { c: "Declared source of funds", ops: "—" },
  edd: { c: "Completed EDD questionnaire", ops: "—" },
  riskScoring: { c: "—", ops: "—" },
  accountCreated: { c: "Acknowledged account", ops: "—" },
  accountCreatedSme: { c: "Acknowledged business account", ops: "—" },
  pepUnderReview: {
    c: "Viewed under-review update",
    ops: ["AML EDD console", "SLA ~1 business day"],
  },
  txSetup: {
    c: "Chose channel preferences",
    ops: {
      target: "—",
      initial: [
        "Fulfilment task queue",
        "Channels (Digital + USSD): ~5 min each",
        "Card request: ~5 min",
      ],
    },
  },
  activation: {
    c: "Watching progress checklist",
    ops: {
      target: "—",
      initial: [
        "Fulfilment console",
        "Verify ID: ~5 min",
        "Verify supporting docs: ~5 min (personal) · ~15 min (business)",
        "Unlock account: after verifications",
        "Channels (Digital + USSD): ~5 min each",
        "Card request: ~5 min",
        "Archive to DMS: same-day",
        "Archive contents: consent, signature, FIND, T&Cs + ID, NUIT, address, biz docs",
      ],
    },
  },
  funding: { c: "Picked a funding option", ops: "—" },
  resumeVerify: { c: "Verified phone via OTP", ops: "—" },
  resumeStatus: { c: "Viewed saved progress", ops: "—" },
};

// ----- Pipeline definitions (system-column sequential viz) -----------------------
// Each node has an optional `actor` ("auto" default, or "fulfilment" / "aml"), a `label`,
// and an optional `flag` for pending/blocked styling.

const PIPE = {
  entryPlain: {
    initial: [{ label: "Capture selection" }],
    target: [{ label: "Capture selection" }],
  },
  consent: {
    initial: [
      { label: "Capture consent flags" },
      { label: "Store in onboarding session" },
      { label: "Queue Fulfilment task: email copy to customer" },
    ],
    target: [
      { label: "Capture consent flags" },
      { label: "Persist to DMS" },
      { label: "Email copy to customer (Email service)" },
    ],
  },
  signature: {
    initial: [
      { label: "Capture signature" },
      { label: "Store in onboarding session" },
    ],
    target: [
      { label: "Capture signature" },
      { label: "Persist to DMS" },
    ],
  },
  identity: {
    initial: [{ label: "Send OTP (SMS gateway)" }, { label: "Verify OTP" }],
    target: [{ label: "Send OTP (SMS gateway)" }, { label: "Verify OTP" }],
  },
  identityDetails: {
    initial: [
      { label: "Validate field formats" },
      { label: "Store in onboarding session" },
    ],
    target: [
      { label: "Validate field formats" },
      { label: "Store in onboarding session" },
    ],
  },
  idCapture: {
    initial: [
      { label: "Capture ID image" },
      { label: "Store in onboarding session" },
    ],
    target: [
      { label: "Extract fields (OCR)" },
      { label: "Verify ID (Gov Database service)" },
      {
        actor: "failback",
        label: "Verify via AI agent review (if Gov service unavailable)",
      },
      { label: "Retrieve NUIT (Tax Authority)" },
      { label: "Store in onboarding session" },
    ],
  },
  liveness: {
    initial: [
      { label: "Run liveness check (Liveness service)" },
      { label: "Match face against ID photo" },
      { label: "Return confidence score" },
    ],
    target: [
      { label: "Run liveness check (Liveness service)" },
      { label: "Match face against ID photo" },
      { label: "Return confidence score" },
    ],
  },
  nuit: {
    initial: [
      { label: "Capture NUIT document" },
      { label: "Store in onboarding session" },
    ],
    target: [
      { label: "Confirm prefetched NUIT" },
      {
        actor: "failback",
        label: "Upload NUIT document (if prefetch unavailable)",
      },
      { label: "Store in onboarding session" },
    ],
  },
  income: {
    initial: [
      { label: "Capture income details" },
      { label: "Feed to AML risk engine" },
    ],
    target: [
      { label: "Capture income details" },
      { label: "Feed to AML risk engine" },
    ],
  },
  proofAddress: {
    initial: [
      { label: "Capture document" },
      { label: "Store in onboarding session" },
    ],
    target: [
      { label: "Store document (DMS)" },
      { label: "Validate via AI agent (date, address match)" },
      { label: "Feed risk profile" },
    ],
  },
  sourceOfFunds: {
    initial: [
      { label: "Capture selections" },
      { label: "Store in onboarding session" },
    ],
    target: [
      { label: "Capture selections" },
      { label: "Persist to EDD profile" },
      { label: "Flag for EDD review" },
    ],
  },
  edd: {
    initial: [
      { label: "Capture answers" },
      { label: "Store in onboarding session" },
    ],
    target: [{ label: "Capture answers" }, { label: "Compile EDD profile" }],
  },
  business: {
    initial: [
      { label: "Capture business info" },
      { label: "Store in onboarding session" },
    ],
    target: [
      { label: "Capture business info" },
      { label: "Verify business NUIT (Tax Authority)" },
      { label: "Match name (Commercial Registry)" },
      {
        actor: "failback",
        label:
          "Verify via AI agent review (if Tax Authority / Registry unavailable)",
      },
    ],
  },
  docsRequired: {
    initial: [
      { label: "Capture documents" },
      { label: "Store in onboarding session" },
    ],
    target: [
      { label: "Store documents (DMS)" },
      { label: "Cross-check Certidão (Commercial Registry)" },
      {
        actor: "failback",
        label: "Validate via AI agent review (if Registry unavailable)",
      },
      { label: "Validate Alvará via AI agent" },
      { label: "Feed risk engine" },
    ],
  },
  docsSupporting: {
    initial: [
      { label: "Capture documents" },
      { label: "Store in onboarding session" },
    ],
    target: [
      { label: "Store documents (DMS)" },
      { label: "Corroborate Modelo 11 (Tax Authority)" },
      {
        actor: "failback",
        label: "Validate via AI agent review (if Tax Authority unavailable)",
      },
      { label: "Validate address proof via AI agent" },
      { label: "Feed risk engine" },
    ],
  },
  riskScoring: {
    initial: [
      { label: "Gather inputs (ID, NUIT, screening, income, biz docs)" },
      { label: "Run AML engine" },
      { label: "Return risk tier" },
      { label: "Route next step" },
    ],
    target: [
      { label: "Gather inputs (ID, NUIT, screening, income, biz docs)" },
      { label: "Run AML engine" },
      { label: "Return risk tier" },
      { label: "Route next step" },
    ],
  },
  accountCreated: {
    initial: [{ label: "Send welcome notification (SMS/push)" }],
    target: [{ label: "Send welcome notification (SMS/push)" }],
  },
  accountCreatedSme: {
    initial: [{ label: "Send welcome notification (SMS/push)" }],
    target: [{ label: "Send welcome notification (SMS/push)" }],
  },
  pepUnderReview: {
    initial: [{ actor: "aml", flag: true, label: "EDD review in progress" }],
    target: [{ actor: "aml", flag: true, label: "EDD review in progress" }],
  },
  txSetup: {
    initial: [
      { label: "Capture preferences" },
      { label: "Queue Fulfilment task: Digital channel provisioning" },
      { label: "Queue Fulfilment task: USSD channel provisioning" },
      { label: "Queue Fulfilment task: Card request" },
    ],
    target: [
      { label: "Capture preferences" },
      { label: "Activate channel (Digital service)" },
      { label: "Activate channel (USSD service)" },
      { label: "Request card (Card Management service)" },
    ],
  },
  activation: {
    initial: [
      { actor: "fulfilment", flag: true, label: "Verify ID" },
      {
        actor: "fulfilment",
        flag: true,
        label: "Verify supporting documents (NUIT, address, biz docs)",
      },
      { actor: "fulfilment", flag: true, label: "Unlock account" },
      { actor: "fulfilment", flag: true, label: "Provision USSD channel" },
      { actor: "fulfilment", flag: true, label: "Provision Digital channel" },
      { actor: "fulfilment", flag: true, label: "Raise card request" },
      {
        actor: "fulfilment",
        flag: true,
        label: "Archive to DMS: onboarding pack + customer uploads",
      },
    ],
    // No target pipeline: in Optimal, all activation work was completed upstream.
    // backstage.jsx falls through to systemText ("—") when the per-state pipeline is undefined.
  },
  funding: {
    initial: [{ label: "Surface account details + per-method instructions" }],
    target: [{ label: "Surface account details + per-method instructions" }],
  },
  resumeVerify: {
    initial: [
      { label: "Verify OTP" },
      { label: "Lookup session by phone" },
      { label: "Restore held data (partial)" },
    ],
    target: [
      { label: "Verify OTP" },
      { label: "Lookup session by phone" },
      { label: "Rehydrate state (onboarding store)" },
      { label: "Pre-fill next pending step" },
    ],
  },
  resumeStatus: {
    initial: [
      { label: "Compute completed steps from held data" },
      { label: "Surface remaining steps to customer" },
    ],
    target: [
      { label: "Compute completed steps from rehydrated state" },
      { label: "Surface remaining steps with deep-links" },
    ],
  },
};

// PEP-specific overrides — defer activations from Tx-setup until the account is approved
PIPE.txSetupPep = {
  initial: [{ label: "Capture preferences (held pending EDD)" }],
  target: [{ label: "Capture preferences (held pending EDD)" }],
};
PIPE.activationPep = {
  initial: PIPE.activation.initial,
  target: [
    { label: "Activate channel (USSD service)" },
    { label: "Activate channel (Digital service)" },
    { label: "Request card (Card Management service)" },
    { label: "Send ready-to-transact notification (Push service)" },
  ],
};

const RISK_CAPTION =
  "All risk assessment happens in the background. Customers only see the outcome — the next step adapts to their risk profile.";

// Sequential pipeline for decisioning / account-creation step
const DECISIONING_PIPE = {
  target: [
    { label: "Create entity (Core Banking)" },
    { label: "Auto-clear AML via rules" },
    { label: "Fetch NUIB (Central Bank)" },
    { label: "Create account record" },
  ],
  initial: [
    { label: "Create entity (Core Banking)" },
    { actor: "aml", flag: true, label: "Review & clear AML block" },
    { label: "Fetch NUIB (Central Bank)" },
    { label: "Create account record" },
    { label: "Queue Fulfilment task: Verify ID" },
    { label: "Queue Fulfilment task: Verify supporting documents" },
    { label: "Queue Fulfilment task: DMS archive" },
  ],
};
const decisioningStep = (screen = "Decisioning", label = "Decisioning") => ({
  key: "decisioning",
  label,
  screen,
  bs: {
    c: "Submitted for review",
    ops: {
      target: "—",
      initial: [
        "AML console",
        "Fulfilment task queue",
        "AML unblock: ~10 min",
      ],
    },
  },
  pipeline: DECISIONING_PIPE,
  pipelineCaption:
    "Final submission. In Optimal, this pipeline runs end-to-end automatically. In Initial, an AML block may pause the pipeline until the AML team clears it — and on completion, the Fulfilment team receives the case with doc verification and DMS archive tasks queued for Activation.",
});

const riskScoringStep = (label = "Risk scoring") => ({
  key: "risk-scoring",
  label,
  screen: "RiskScoring",
  bs: BS.riskScoring,
  pipeline: PIPE.riskScoring,
  pipelineCaption: RISK_CAPTION,
});

const consentSignatureSteps = [
  {
    key: "consent",
    label: "Review & accept",
    screen: "Consent",
    bs: BS.consent,
    pipeline: PIPE.consent,
  },
  {
    key: "signature",
    label: "Digital signature",
    screen: "Signature",
    bs: BS.signature,
    pipeline: PIPE.signature,
  },
];

const identitySteps = [
  {
    key: "identity",
    label: "Verify your number",
    screen: "Identity",
    bs: BS.identity,
    pipeline: PIPE.identity,
  },
  {
    key: "identity-details",
    label: "Your details",
    screen: "IdentityDetails",
    bs: BS.identityDetails,
    pipeline: PIPE.identityDetails,
  },
  {
    key: "id-capture",
    label: "ID capture",
    screen: "IdCapture",
    bs: BS.idCapture,
    pipeline: PIPE.idCapture,
  },
];

// ----- Journeys ------------------------------------------------------------------

const JOURNEYS = {
  entry: {
    key: "entry",
    name: "Entry flow",
    subtitle: "Landing journey",
    steps: [
      {
        key: "entry-type",
        label: "Customer type",
        screen: "EntryType",
        bs: BS_ENTRY.type,
        pipeline: PIPE.entryPlain,
      },
      {
        key: "entry-business-entity",
        label: "Business entity type",
        screen: "BusinessEntityType",
        bs: BS_ENTRY.entity,
        pipeline: {
          initial: [
            { label: "Capture entity type" },
            { label: "Capture signatory count" },
          ],
          target: [
            { label: "Capture entity type" },
            { label: "Capture signatory count" },
          ],
        },
        when: (ctx) => ctx.customerType === "business",
      },
      {
        key: "entry-intents",
        label: "Intents",
        screen: "EntryIntents",
        bs: BS_ENTRY.intents,
        pipeline: PIPE.entryPlain,
      },
      {
        key: "entry-reco",
        label: "Account recommendation",
        screen: "EntryReco",
        bs: BS_ENTRY.reco,
        pipeline: PIPE.entryPlain,
      },
      {
        key: "entry-options",
        label: "All options",
        screen: "EntryOptions",
        bs: BS_ENTRY.options,
        pipeline: PIPE.entryPlain,
      },
    ],
  },

  wallet: {
    key: "wallet",
    name: "Wallet",
    subtitle: "Individual · Digital-only",
    steps: [
      ...consentSignatureSteps,
      ...identitySteps,
      riskScoringStep(),
      decisioningStep(),
      {
        key: "account-created",
        label: "Wallet created",
        screen: "AccountCreated",
        bs: BS.accountCreated,
        pipeline: PIPE.accountCreated,
      },
      {
        key: "tx-setup",
        label: "Transaction setup",
        screen: "TxSetupDigital",
        bs: BS.txSetup,
        pipeline: PIPE.txSetup,
      },
      {
        key: "activation",
        label: "Activation",
        screen: "Activation",
        bs: BS.activation,
        pipeline: PIPE.activation,
        pipelineCaption:
          "In Optimal, all activation work (document validation, channel activation, card request) was already completed upstream — this screen just lets the customer watch the ready state. In Initial, Fulfilment verifies ID first (~5 min), then supporting documents (~5 min personal / ~15 min business), unlocks the account, provisions channels, and raises the card request.",
      },
      {
        key: "funding",
        label: "First funding",
        screen: "FirstFunding",
        bs: BS.funding,
        pipeline: PIPE.funding,
      },
    ],
  },

  basic: {
    key: "basic",
    name: "Basic",
    subtitle: "Individual · Card eligible",
    steps: [
      ...consentSignatureSteps,
      ...identitySteps,
      {
        key: "liveness",
        label: "Liveness check",
        screen: "Liveness",
        bs: BS.liveness,
        pipeline: PIPE.liveness,
      },
      {
        key: "nuit",
        label: "NUIT capture",
        screen: "Nuit",
        bs: BS.nuit,
        pipeline: PIPE.nuit,
      },
      riskScoringStep(),
      decisioningStep(),
      {
        key: "account-created",
        label: "Account created",
        screen: "AccountCreated",
        bs: BS.accountCreated,
        pipeline: PIPE.accountCreated,
      },
      {
        key: "tx-setup",
        label: "Transaction setup",
        screen: "TxSetupCard",
        bs: BS.txSetup,
        pipeline: PIPE.txSetup,
      },
      {
        key: "activation",
        label: "Activation",
        screen: "Activation",
        bs: BS.activation,
        pipeline: PIPE.activation,
        pipelineCaption:
          "In Optimal, all activation work (document validation, channel activation, card request) was already completed upstream — this screen just lets the customer watch the ready state. In Initial, Fulfilment verifies ID first (~5 min), then supporting documents (~5 min personal / ~15 min business), unlocks the account, provisions channels, and raises the card request.",
      },
      {
        key: "funding",
        label: "First funding",
        screen: "FirstFunding",
        bs: BS.funding,
        pipeline: PIPE.funding,
      },
    ],
  },

  "standard-low": {
    key: "standard-low",
    name: "Standard — Low risk",
    subtitle: "Adaptive KYC · Frictionless",
    steps: [
      ...consentSignatureSteps,
      ...identitySteps,
      {
        key: "liveness",
        label: "Liveness check",
        screen: "Liveness",
        bs: BS.liveness,
        pipeline: PIPE.liveness,
      },
      {
        key: "nuit",
        label: "NUIT capture",
        screen: "Nuit",
        bs: BS.nuit,
        pipeline: PIPE.nuit,
      },
      {
        key: "income",
        label: "Income & employment",
        screen: "Income",
        bs: BS.income,
        pipeline: PIPE.income,
      },
      riskScoringStep("Risk scoring · Low"),
      decisioningStep(),
      {
        key: "account-created",
        label: "Account created",
        screen: "AccountCreated",
        bs: BS.accountCreated,
        pipeline: PIPE.accountCreated,
      },
      {
        key: "tx-setup",
        label: "Transaction setup",
        screen: "TxSetupCard",
        bs: BS.txSetup,
        pipeline: PIPE.txSetup,
      },
      {
        key: "activation",
        label: "Activation",
        screen: "Activation",
        bs: BS.activation,
        pipeline: PIPE.activation,
        pipelineCaption:
          "In Optimal, all activation work (document validation, channel activation, card request) was already completed upstream — this screen just lets the customer watch the ready state. In Initial, Fulfilment verifies ID first (~5 min), then supporting documents (~5 min personal / ~15 min business), unlocks the account, provisions channels, and raises the card request.",
      },
      {
        key: "funding",
        label: "First funding",
        screen: "FirstFunding",
        bs: BS.funding,
        pipeline: PIPE.funding,
      },
    ],
  },

  "standard-medium": {
    key: "standard-medium",
    name: "Standard — Medium risk",
    subtitle: "Adaptive KYC · +Proof of address",
    steps: [
      ...consentSignatureSteps,
      ...identitySteps,
      {
        key: "liveness",
        label: "Liveness check",
        screen: "Liveness",
        bs: BS.liveness,
        pipeline: PIPE.liveness,
      },
      {
        key: "nuit",
        label: "NUIT capture",
        screen: "Nuit",
        bs: BS.nuit,
        pipeline: PIPE.nuit,
      },
      {
        key: "income",
        label: "Income & employment",
        screen: "Income",
        bs: BS.income,
        pipeline: PIPE.income,
      },
      riskScoringStep("Risk scoring · Medium"),
      {
        key: "proof-address",
        label: "Proof of address",
        screen: "ProofAddress",
        bs: BS.proofAddress,
        pipeline: PIPE.proofAddress,
      },
      decisioningStep(),
      {
        key: "account-created",
        label: "Account created",
        screen: "AccountCreated",
        bs: BS.accountCreated,
        pipeline: PIPE.accountCreated,
      },
      {
        key: "tx-setup",
        label: "Transaction setup",
        screen: "TxSetupCard",
        bs: BS.txSetup,
        pipeline: PIPE.txSetup,
      },
      {
        key: "activation",
        label: "Activation",
        screen: "Activation",
        bs: BS.activation,
        pipeline: PIPE.activation,
        pipelineCaption:
          "In Optimal, all activation work (document validation, channel activation, card request) was already completed upstream — this screen just lets the customer watch the ready state. In Initial, Fulfilment verifies ID first (~5 min), then supporting documents (~5 min personal / ~15 min business), unlocks the account, provisions channels, and raises the card request.",
      },
      {
        key: "funding",
        label: "First funding",
        screen: "FirstFunding",
        bs: BS.funding,
        pipeline: PIPE.funding,
      },
    ],
  },

  "standard-pep": {
    key: "standard-pep",
    name: "Standard — PEP",
    subtitle: "Enhanced Due Diligence",
    steps: [
      ...consentSignatureSteps,
      ...identitySteps,
      {
        key: "liveness",
        label: "Liveness check",
        screen: "Liveness",
        bs: BS.liveness,
        pipeline: PIPE.liveness,
      },
      {
        key: "nuit",
        label: "NUIT capture",
        screen: "Nuit",
        bs: BS.nuit,
        pipeline: PIPE.nuit,
      },
      {
        key: "income",
        label: "Income & employment",
        screen: "Income",
        bs: BS.income,
        pipeline: PIPE.income,
      },
      riskScoringStep("Risk scoring · PEP"),
      {
        key: "proof-address",
        label: "Proof of address",
        screen: "ProofAddress",
        bs: BS.proofAddress,
        pipeline: PIPE.proofAddress,
      },
      {
        key: "source-of-funds",
        label: "Source of funds",
        screen: "SourceOfFunds",
        bs: BS.sourceOfFunds,
        pipeline: PIPE.sourceOfFunds,
      },
      {
        key: "edd",
        label: "Enhanced Due Diligence",
        screen: "Edd",
        bs: BS.edd,
        pipeline: PIPE.edd,
      },
      decisioningStep("Decisioning", "Decisioning · Submitting for review"),
      {
        key: "tx-setup",
        label: "Transaction setup",
        screen: "TxSetupCard",
        bs: BS.txSetup,
        pipeline: PIPE.txSetupPep,
      },
      {
        key: "under-review",
        label: "Under review",
        screen: "DecisioningFinalPep",
        bs: BS.pepUnderReview,
        pipeline: PIPE.pepUnderReview,
      },
      {
        key: "account-ready",
        label: "Account ready",
        screen: "AccountCreated",
        bs: BS.accountCreated,
        pipeline: PIPE.accountCreated,
      },
      {
        key: "activation",
        label: "Activation",
        screen: "Activation",
        bs: BS.activation,
        pipeline: PIPE.activationPep,
        pipelineCaption:
          "For PEP, preferences captured on Tx-setup were held pending EDD. Now that the account is approved, Optimal activates channels and requests the card; Initial runs the same fulfilment tasks as other journeys.",
      },
      {
        key: "funding",
        label: "First funding",
        screen: "FirstFunding",
        bs: BS.funding,
        pipeline: PIPE.funding,
      },
    ],
  },

  sme: {
    key: "sme",
    name: "Business Lite",
    subtitle: "Business Lite · Single-signatory",
    steps: [
      ...consentSignatureSteps,
      {
        key: "identity",
        label: "Verify owner number",
        screen: "Identity",
        bs: BS.identity,
        pipeline: PIPE.identity,
      },
      {
        key: "identity-details",
        label: "Owner details",
        screen: "IdentityDetails",
        bs: BS.identityDetails,
        pipeline: PIPE.identityDetails,
      },
      {
        key: "id-capture",
        label: "ID capture (owner)",
        screen: "IdCapture",
        bs: BS.idCapture,
        pipeline: PIPE.idCapture,
      },
      {
        key: "liveness",
        label: "Liveness (owner)",
        screen: "Liveness",
        bs: BS.liveness,
        pipeline: PIPE.liveness,
      },
      {
        key: "nuit",
        label: "NUIT (owner)",
        screen: "Nuit",
        bs: BS.nuit,
        pipeline: PIPE.nuit,
      },
      {
        key: "business",
        label: "Business details",
        screen: "BusinessDetails",
        bs: BS.business,
        pipeline: PIPE.business,
      },
      {
        key: "docs-required",
        label: "Required documents",
        screen: "BusinessDocsRequired",
        bs: BS.docsRequired,
        pipeline: PIPE.docsRequired,
      },
      {
        key: "docs-supporting",
        label: "Supporting documents",
        screen: "BusinessDocsSupporting",
        bs: BS.docsSupporting,
        pipeline: PIPE.docsSupporting,
      },
      riskScoringStep(),
      decisioningStep(),
      {
        key: "account-created",
        label: "Business account created",
        screen: "AccountCreatedSme",
        bs: BS.accountCreatedSme,
        pipeline: PIPE.accountCreatedSme,
      },
      {
        key: "tx-setup",
        label: "Transaction setup",
        screen: "TxSetupSme",
        bs: BS.txSetup,
        pipeline: PIPE.txSetup,
      },
      {
        key: "activation",
        label: "Activation",
        screen: "Activation",
        bs: BS.activation,
        pipeline: PIPE.activation,
        pipelineCaption:
          "In Optimal, all activation work (document validation, channel activation, card request) was already completed upstream — this screen just lets the customer watch the ready state. In Initial, Fulfilment verifies ID first (~5 min), then supporting documents (~5 min personal / ~15 min business), unlocks the account, provisions channels, and raises the card request.",
      },
      {
        key: "funding",
        label: "First funding",
        screen: "FirstFundingSme",
        bs: BS.funding,
        pipeline: PIPE.funding,
      },
    ],
  },

  resume: {
    key: "resume",
    name: "Resume",
    subtitle: "Continue where you left off",
    steps: [
      {
        key: "resume-verify",
        label: "Verify it's you",
        screen: "ResumeVerify",
        bs: BS.resumeVerify,
        pipeline: PIPE.resumeVerify,
      },
      {
        key: "resume-status",
        label: "Welcome back",
        screen: "ResumeStatus",
        bs: BS.resumeStatus,
        pipeline: PIPE.resumeStatus,
      },
      {
        key: "resume-continue",
        label: "Pick up where you left off",
        screen: "Income",
        bs: BS.income,
        pipeline: PIPE.income,
      },
    ],
  },
};

const JOURNEY_ORDER = [
  "entry",
  "wallet",
  "basic",
  "standard-low",
  "standard-medium",
  "standard-pep",
  "sme",
  "resume",
];

function progressPercent(journey, stepIdx) {
  return Math.round(((stepIdx + 1) / journey.steps.length) * 100);
}

Object.assign(window, { JOURNEYS, JOURNEY_ORDER, progressPercent });
