// Onboarding wizard step calculation. Given the current project state and
// setup flags, returns the step the wizard should display.
(function (root) {
  var WIZARD_STEPS = ['link', 'setup', 'verify', 'shipping', 'done'];

  // EN fallback labels — translation keys live in shared/i18n/locales/*.json
  // under the matching `wizard.step.<name>.label` paths. The renderer reads
  // STEP_LABEL_KEYS to feed t() (Req-F-036); STEP_LABELS stays for tests and
  // any caller that doesn't have a translator handy (the BE never displays
  // these — only BC + BDash do — so EN-only is fine as a fallback).
  var STEP_LABELS = {
    link: 'Connect your store',
    setup: 'Setup e-shop',
    verify: 'Verify ownership',
    shipping: 'Configure shipping methods',
    done: 'Setup complete'
  };

  var STEP_LABEL_KEYS = {
    link: 'wizard.step.link.label',
    setup: 'wizard.step.setup.label',
    verify: 'wizard.step.verify.label',
    shipping: 'wizard.step.shipping.label',
    done: 'wizard.step.done.label'
  };

  // project: { verification_status, np_api_key, ... } from Biatec BE, or null.
  // flags:   { setupDone, shippingConfigured } from local storage.
  //
  // Note: we intentionally do NOT gate on a local `widgetInstalled` flag.
  // That flag is only set by the admin's verify step, so an operator signing
  // in with an access token (project already verified server-side) would
  // never have it — and after restart the wizard would loop them back to
  // 'shipping' even when shipping was already configured. The server-side
  // `verification_status === 'verified'` already proves the widget snippet
  // is live in the e-shop HTML, so it's a sufficient signal on its own.
  function determineStep(project, flags) {
    flags = flags || {};
    if (!project) return 'link';
    if (project.verification_status !== 'verified' && !flags.setupDone) return 'setup';
    if (project.verification_status !== 'verified') return 'verify';
    if (!flags.shippingConfigured) return 'shipping';
    return 'done';
  }

  var api = {
    WIZARD_STEPS: WIZARD_STEPS,
    STEP_LABELS: STEP_LABELS,
    STEP_LABEL_KEYS: STEP_LABEL_KEYS,
    determineStep: determineStep
  };
  if (typeof module !== 'undefined' && module.exports) module.exports = api;
  else { root.NP = root.NP || {}; root.NP.wizard = api; }
})(typeof self !== 'undefined' ? self : this);
