/* ═══════════════════════════════════════════════════════════════════
   MigData.jsx — sample data for the Migrations surface. v1.0.0
   Ported verbatim from the Claude Design v2 package
   (_CLAUDE-DESIGN/_2026-06-12-v2-SaaS-Redesign/migrations-data.jsx).
   Sample data only; no persistence — the surface runs on this design
   sample dataset until the migrations API lands; the SA-only launch
   gate covers that window. Host names are environment context, not
   WPSiteBeam competitors. Statuses use the WORKFLOW axis (not gating).
   Load order: FIRST of the five Mig modules (data → charts → page →
   wizard → surface — matches the design package's index.html order).
   Registers: window.WPSB.MigData = { MIG_STATUS, MIG_STEPS, ACTIVE,
   MIG_LOG, MIG_LOG_FAIL, MIG_RECENT, CONNECT_METHODS, SOURCE_STACK,
   PREFLIGHT, ROLLBACK }.
   ═══════════════════════════════════════════════════════════════════ */
(function () {

const tx = (k, v, f) => (window.WPSB && window.WPSB.t) ? window.WPSB.t(k, v, f) : (f != null ? f : k);

/* migration status meta — WORKFLOW-status axis. Color never the sole signal:
   each is paired with an icon + label. */
const MIG_STATUS = {
  queued:    { c: 'var(--muted)', cf: 'var(--muted)',       icon: 'clock',        label: tx('page.migration.data.status.queued', null, 'Queued') },
  scheduled: { c: 'var(--muted)', cf: 'var(--muted)',       icon: 'calendar',     label: tx('page.migration.data.status.scheduled', null, 'Scheduled') },
  running:   { c: 'var(--beam)',  cf: 'var(--beam)',        icon: 'activity',     label: tx('page.migration.data.status.running', null, 'Running'), pulse: true },
  paused:    { c: 'var(--warn)',  cf: 'var(--v-warn-fill)', icon: 'pause',        label: tx('page.migration.data.status.paused', null, 'Paused') },
  completed: { c: 'var(--green)', cf: 'var(--v-good-fill)', icon: 'check-circle', label: tx('page.migration.data.status.completed', null, 'Completed') },
  failed:    { c: 'var(--red)',   cf: 'var(--v-poor-fill)', icon: 'x-circle',     label: tx('page.migration.data.status.failed', null, 'Failed') },
};

/* the 9-stage migration pipeline (host → host). `short` for the rail. */
const MIG_STEPS = [
  { key: 'connect',  title: tx('page.migration.data.steps.connect.title', null, 'Connect source'),      short: tx('page.migration.data.steps.connect.short', null, 'Connect') },
  { key: 'snapshot', title: tx('page.migration.data.steps.snapshot.title', null, 'Snapshot & backup'),   short: tx('page.migration.data.steps.snapshot.short', null, 'Snapshot') },
  { key: 'files',    title: tx('page.migration.data.steps.files.title', null, 'Transfer files'),      short: tx('page.migration.data.steps.files.short', null, 'Files') },
  { key: 'database', title: tx('page.migration.data.steps.database.title', null, 'Transfer database'),   short: tx('page.migration.data.label.database', null, 'Database') },
  { key: 'rewrite',  title: tx('page.migration.data.steps.rewrite.title', null, 'Rewrite URLs & paths'), short: tx('page.migration.data.steps.rewrite.short', null, 'URLs') },
  { key: 'media',    title: tx('page.migration.data.steps.media.title', null, 'Media & uploads'),     short: tx('page.migration.data.label.media', null, 'Media') },
  { key: 'plugins',  title: tx('page.migration.data.steps.plugins.title', null, 'Plugins & themes'),     short: tx('page.migration.data.label.plugins', null, 'Plugins') },
  { key: 'redirects',title: tx('page.migration.data.steps.redirects.title', null, 'Redirects & DNS'),     short: tx('page.migration.data.steps.redirects.short', null, 'Redirects') },
  { key: 'verify',   title: tx('page.migration.data.steps.verify.title', null, 'Verify & go live'),     short: tx('page.migration.data.steps.verify.short', null, 'Go-live') },
];

/* the active (in-progress) migration */
const ACTIVE = {
  id: 'mig_8f2a',
  site: 'maplewood.co',
  source: { host: 'SiteGround', env: 'production', label: 'maplewood.co' },
  dest:   { host: 'WP Engine',  env: 'production', label: 'maplewood.co' },
  current: 4,            // 0-indexed → "Rewrite URLs & paths"
  eta: tx('page.migration.data.active.eta', null, '~6 min left'),
  started: '14:02',
  throughput: [4, 7, 9, 8, 12, 15, 14, 18, 16, 20, 19, 22],
  counters: [
    { key: 'db',      icon: 'database', label: tx('page.migration.data.counters.db', null, 'DB rows'),     value: '184,200', color: 'var(--viz-2)' },
    { key: 'media',   icon: 'image',    label: tx('page.migration.data.counters.media', null, 'Media files'), value: '8,140',   color: 'var(--viz-3)' },
    { key: 'plugins', icon: 'layers',   label: tx('page.migration.data.label.plugins', null, 'Plugins'),     value: '37',      color: 'var(--viz-5)' },
    { key: 'r404',    icon: 'git-branch', label: tx('page.migration.data.counters.r404', null, '404s caught'), value: '12',     color: 'var(--warn)', warn: true },
  ],
};

/* live log feed — level drives --term-* color AND a text tag (never color alone) */
const MIG_LOG = [
  { t: '14:02:11', lv: 'info', msg: tx('page.migration.data.log.source_connected', null, 'Source connected · SiteGround (PHP 8.2, WP 6.5)') },
  { t: '14:02:18', lv: 'ok',   msg: tx('page.migration.data.log.snapshot_created', null, 'Snapshot created · DB 2.4 GB · media 8.1 GB') },
  { t: '14:03:40', lv: 'ok',   msg: tx('page.migration.data.log.files_transferred', null, 'Files transferred · 8,140 objects') },
  { t: '14:05:02', lv: 'info', msg: tx('page.migration.data.log.importing_db', null, 'Importing database · 184,200 rows') },
  { t: '14:06:20', lv: 'ok',   msg: tx('page.migration.data.log.db_imported', null, 'Database imported · 42 tables') },
  { t: '14:06:21', lv: 'info', msg: tx('page.migration.data.log.rewriting_urls', null, 'Rewriting URLs · siteground → wpengine') },
  { t: '14:06:48', lv: 'warn', msg: tx('page.migration.data.log.hardcoded_urls', null, '12 hardcoded URLs in wp_options · queued for redirect') },
  { t: '14:06:55', lv: 'info', msg: tx('page.migration.data.log.search_replace', null, 'search-replace · 3,910 rows updated') },
  { t: '14:07:10', lv: 'info', msg: tx('page.migration.data.log.rewriting_serialized', null, 'Rewriting serialized data · acf, elementor') },
  { t: '14:07:24', lv: 'ok',   msg: tx('page.migration.data.log.postmeta_rewritten', null, 'wp_postmeta rewritten · 28,540 rows') },
];

/* the failed-run variant of the log (ends in an error + auto-rollback) */
const MIG_LOG_FAIL = [
  { t: '14:06:21', lv: 'info', msg: tx('page.migration.data.log.rewriting_urls', null, 'Rewriting URLs · siteground → wpengine') },
  { t: '14:06:48', lv: 'warn', msg: tx('page.migration.data.log.hardcoded_urls', null, '12 hardcoded URLs in wp_options · queued for redirect') },
  { t: '14:07:55', lv: 'err',  msg: tx('page.migration.data.log.media_sync_failed', null, 'Media sync failed · destination disk quota exceeded') },
  { t: '14:07:56', lv: 'warn', msg: tx('page.migration.data.log.halting', null, 'Halting migration · destination left unchanged') },
  { t: '14:07:58', lv: 'info', msg: tx('page.migration.data.log.restoring_backup', null, 'Restoring pre-commit backup · WP Engine') },
  { t: '14:08:12', lv: 'ok',   msg: tx('page.migration.data.log.rollback_complete', null, 'Rollback complete · both sides at pre-migration state') },
];

/* recent migrations (zebra table) */
const MIG_RECENT = [
  { site: 'Maple & Birch',   from: 'SiteGround', to: 'WP Engine', dur: '14m 22s', files: '9,210',  status: 'completed', date: 'Jun 9' },
  { site: 'Lumen Co.',       from: 'Kinsta',     to: 'WP Engine', dur: '21m 03s', files: '14,540', status: 'completed', date: 'Jun 7' },
  { site: 'Atlas (staging)', from: 'WP Engine',  to: 'WP Engine', dur: '6m 41s',  files: '3,120',  status: 'completed', date: 'Jun 6' },
  { site: 'Northwind Studio',from: 'Bluehost',   to: 'Cloudways', dur: '—',   files: '—', status: 'failed',    date: 'Jun 4' },
  { site: 'Harbor & Co.',    from: 'SiteGround', to: 'Kinsta',    dur: '18m 55s', files: '11,030', status: 'completed', date: 'Jun 2' },
];

/* ── wizard data ──────────────────────────────────────────────────── */
const CONNECT_METHODS = [
  { key: 'plugin', label: tx('page.migration.data.connect.plugin.label', null, 'WPSiteBeam plugin'), qualifier: tx('page.migration.data.connect.plugin.qualifier', null, '1-click · recommended'), detail: tx('page.migration.data.connect.plugin.detail', null, 'Already installed on the source site. Fastest and most reliable.') },
  { key: 'sftp',   label: tx('page.migration.data.connect.sftp.label', null, 'SFTP + database'),   qualifier: tx('page.migration.data.connect.sftp.qualifier', null, 'host + credentials'),          detail: tx('page.migration.data.connect.sftp.detail', null, 'Connect with SSH/SFTP and a database dump for hosts without the plugin.') },
  { key: 'url',    label: tx('page.migration.data.connect.url.label', null, 'Full-site URL'),     qualifier: tx('page.migration.data.connect.url.qualifier', null, 'we crawl & package'),           detail: tx('page.migration.data.connect.url.detail', null, 'No access needed — we package a static + DB snapshot from the live URL.'), locked: { tag: tx('page.migration.data.connect.url.locked_tag', null, 'Pro+') } },
];

const SOURCE_STACK = [
  { label: tx('page.migration.data.stack.wordpress', null, 'WordPress'), value: '6.5.2' },
  { label: tx('page.migration.data.stack.php', null, 'PHP'), value: '8.2' },
  { label: tx('page.migration.data.label.database', null, 'Database'), value: '2.4 GB' },
  { label: tx('page.migration.data.label.media', null, 'Media'), value: '8.1 GB' },
];

/* preflight checks for the Verify step — pass / warn (shape + label + color) */
const PREFLIGHT = [
  { v: 'pass', label: tx('page.migration.data.preflight.php.label', null, 'PHP version compatible'), detail: tx('page.migration.data.preflight.php.detail', null, 'Source 8.2 → destination 8.2') },
  { v: 'pass', label: tx('page.migration.data.preflight.disk.label', null, 'Disk space at destination'), detail: tx('page.migration.data.preflight.disk.detail', null, '12 GB free · 10.5 GB needed') },
  { v: 'pass', label: tx('page.migration.data.preflight.db.label', null, 'Database within plan limits'), detail: tx('page.migration.data.preflight.db.detail', null, '2.4 GB · Pro allows 10 GB') },
  { v: 'warn', label: tx('page.migration.data.preflight.media.label', null, 'Large media library'), detail: tx('page.migration.data.preflight.media.detail', null, '8.1 GB · will extend transfer time') },
  { v: 'warn', label: tx('page.migration.data.preflight.existing.label', null, 'Destination has an existing site'), detail: tx('page.migration.data.preflight.existing.detail', null, 'Will be backed up, then replaced') },
  { v: 'pass', label: tx('page.migration.data.preflight.ssl.label', null, 'SSL certificate present'), detail: tx('page.migration.data.preflight.ssl.detail', null, 'Valid cert on destination domain') },
];

/* dual-side rollback manifest (paused / failed states) */
const ROLLBACK = [
  { side: tx('page.migration.data.rollback.side.source', null, 'Source'), host: 'SiteGround', point: tx('page.migration.data.rollback.point.snapshot', null, 'Pre-migration snapshot'), size: '2.4 GB', at: '14:02' },
  { side: tx('page.migration.data.rollback.side.destination', null, 'Destination'), host: 'WP Engine', point: tx('page.migration.data.rollback.point.backup', null, 'Pre-commit backup'), size: '2.1 GB', at: '14:06' },
];

window.WPSB = window.WPSB || {};
window.WPSB.MigData = { MIG_STATUS, MIG_STEPS, ACTIVE, MIG_LOG, MIG_LOG_FAIL, MIG_RECENT, CONNECT_METHODS, SOURCE_STACK, PREFLIGHT, ROLLBACK };
console.log('[WPSB] MigData v1.0.0 loaded (sample dataset)');
})();
