/* eslint-disable */
// Mock data shared across all 3 personas

(function () {

// ---------- Workers ----------
// Each row carries the "shape" needed to render across all 3 audiences:
//   - SOW state: not-started / in-progress / signed / expiring / expired / pending-resign
//   - merge_values (the new DocumentMergeContent merge_values jsonb)
//   - history of DocumentMergeContent rows (for re-engagement timeline)
const today = new Date(2026, 4, 6); // May 6, 2026 — matches Onboardings.html

function dateStr(y, m, d) {
  return new Date(y, m - 1, d).toLocaleDateString("en-US", { month: "short", day: "numeric", year: "numeric" });
}
function daysFromNow(d) {
  return Math.round((d - today) / (1000 * 60 * 60 * 24));
}

const WORKERS = [
  {
    id: "w-maya",
    name: "Maya Chen",
    initials: "MC",
    email: "maya.chen@example.com",
    job: "Software Engineer",
    client: "Anthropic",
    employmentType: "1099 Contractor",
    payRate: "$92/hr",
    startDate: dateStr(2026, 5, 4),
    onboardingStatus: "Ready to Work",
    manager: "Scott Marinez",
    sow: {
      state: "expiring",            // 12 days out
      validFrom: dateStr(2026, 2, 4),
      validThru: dateStr(2026, 5, 18),
      validThruDate: new Date(2026, 4, 18),
      template: "Anthropic — SOW v3",
      hellosignTemplateId: "tpl_4f3a",
      signedAt: dateStr(2026, 2, 4),
      mergeValues: {
        worker_name: "Maya Chen",
        project_name: "Claude.ai growth surface — onboarding flows",
        start_date: "Feb 4, 2026",
        end_date: "May 18, 2026",
        pay_rate: "$92.00/hr",
        project_overview: "Build out the new-user onboarding surfaces for Claude.ai, including the personalized recommendation panel and the first-run checklist.",
        scope_of_work: "Frontend implementation in TypeScript + React. Daily standups with the growth pod. Code reviews on the relevant repos.",
        deliverables: "Shipped onboarding checklist, new-user hint surface, and a measurable +10% week-1 activation lift.",
        acceptance_criteria: "Code merged to main and shipped behind feature flag. Unit + e2e coverage at parity with the rest of the surface. Sign-off from the growth lead.",
      },
      history: [
        { signedAt: dateStr(2026, 2, 4), endDate: dateStr(2026, 5, 18), supersededAt: null, status: "active" },
      ],
    },
    badges: {
      handbook: { state: "signed", at: dateStr(2026, 2, 1) },
      codeOfEthics: { state: "signed", at: dateStr(2026, 2, 1) },
      fedW4: { state: "signed", at: dateStr(2026, 2, 2) },
      i9: { state: "signed", at: dateStr(2026, 2, 3) },
      paymentMethod: { state: "signed", at: dateStr(2026, 2, 2) },
      sow: { state: "signed", at: dateStr(2026, 2, 4) },
    },
  },
  {
    id: "w-felix",
    name: "Felix Becker",
    initials: "FB",
    email: "felix.becker@example.com",
    job: "Account Manager",
    client: "Anthropic",
    employmentType: "Int'l Independent Contractor",
    payRate: "$78/hr",
    startDate: dateStr(2026, 5, 4),
    onboardingStatus: "Ready to Work",
    manager: "Scott Marinez",
    sow: {
      state: "active",
      validFrom: dateStr(2026, 5, 4),
      validThru: dateStr(2026, 11, 4),
      validThruDate: new Date(2026, 10, 4),
      template: "Anthropic — SOW v3",
      hellosignTemplateId: "tpl_4f3a",
      signedAt: dateStr(2026, 5, 3),
      mergeValues: {
        worker_name: "Felix Becker",
        project_name: "Enterprise pipeline support",
        start_date: "May 4, 2026",
        end_date: "Nov 4, 2026",
        pay_rate: "$78.00/hr",
        project_overview: "Cover the West Coast pipeline for enterprise sales while the team scales the AE org.",
        scope_of_work: "Pipeline qualification, discovery calls, and account research handoffs to AEs.",
        deliverables: "",
        acceptance_criteria: "",
      },
      history: [
        { signedAt: dateStr(2026, 5, 3), endDate: dateStr(2026, 11, 4), supersededAt: null, status: "active" },
      ],
    },
    badges: {
      handbook: { state: "signed", at: dateStr(2026, 4, 28) },
      codeOfEthics: { state: "signed", at: dateStr(2026, 4, 28) },
      fedW4: { state: "signed", at: dateStr(2026, 4, 30) },
      i9: { state: "signed", at: dateStr(2026, 4, 30) },
      paymentMethod: { state: "signed", at: dateStr(2026, 5, 1) },
      sow: { state: "signed", at: dateStr(2026, 5, 3) },
    },
  },
  {
    id: "w-aisha",
    name: "Aisha Patel",
    initials: "AP",
    email: "aisha.patel@example.com",
    job: "Recruiter",
    client: "Anthropic",
    employmentType: "1099 Contractor",
    payRate: "$95/hr",
    startDate: dateStr(2026, 4, 4),
    onboardingStatus: "Ready to Work",
    manager: "Scott Marinez",
    sow: {
      state: "expired",
      validFrom: dateStr(2026, 1, 4),
      validThru: dateStr(2026, 5, 1),
      validThruDate: new Date(2026, 4, 1),
      template: "Anthropic — SOW v3",
      hellosignTemplateId: "tpl_4f3a",
      signedAt: dateStr(2026, 1, 3),
      mergeValues: {
        worker_name: "Aisha Patel",
        project_name: "Q1 sourcing sprint — research roles",
        start_date: "Jan 4, 2026",
        end_date: "May 1, 2026",
        pay_rate: "$95.00/hr",
        project_overview: "Source candidates for the research org — alignment, interpretability, and post-training teams.",
        scope_of_work: "Outbound sourcing, calibration with hiring managers, candidate intake screening.",
        deliverables: "20 qualified candidates per pod through final-round interviews.",
        acceptance_criteria: "Candidates meet team-defined bar; offer rate >25% on calibrated submissions.",
      },
      history: [
        { signedAt: dateStr(2026, 1, 3), endDate: dateStr(2026, 5, 1), supersededAt: null, status: "expired" },
      ],
    },
    badges: {
      handbook: { state: "signed", at: dateStr(2026, 1, 2) },
      codeOfEthics: { state: "signed", at: dateStr(2026, 1, 2) },
      fedW4: { state: "n/a" },
      i9: { state: "n/a" },
      paymentMethod: { state: "signed", at: dateStr(2026, 1, 3) },
      sow: { state: "expired", at: dateStr(2026, 1, 3) },
    },
  },
  {
    id: "w-jamal",
    name: "Jamal Williams",
    initials: "JW",
    email: "jamal.williams@example.com",
    job: "Sales Development Rep",
    client: "Anthropic",
    employmentType: "1099 Contractor",
    payRate: "$54/hr",
    startDate: dateStr(2026, 5, 11),
    onboardingStatus: "Enrollment Complete",
    manager: "Scott Marinez",
    sow: {
      state: "in-progress",
      validFrom: dateStr(2025, 11, 11),
      validThru: dateStr(2026, 5, 25),
      validThruDate: new Date(2026, 4, 25),
      template: "Anthropic — SOW v3",
      hellosignTemplateId: "tpl_4f3a",
      signedAt: null,
      mergeValues: {
        worker_name: "Jamal Williams",
        project_name: "SDR coverage — startup segment",
        start_date: "Nov 11, 2025",
        end_date: "May 25, 2026",
        pay_rate: "$54.00/hr",
        project_overview: "Cover inbound qualification for the startup segment of the pipeline.",
        scope_of_work: "Qualify inbound leads, hand off to AEs, run weekly pipeline reviews.",
        deliverables: "",
        acceptance_criteria: "",
      },
      history: [
        { signedAt: null, endDate: dateStr(2026, 5, 25), supersededAt: null, status: "pending-signature" },
      ],
    },
    badges: {
      handbook: { state: "signed", at: dateStr(2026, 5, 5) },
      codeOfEthics: { state: "signed", at: dateStr(2026, 5, 5) },
      fedW4: { state: "signed", at: dateStr(2026, 5, 5) },
      i9: { state: "in-progress" },
      paymentMethod: { state: "signed", at: dateStr(2026, 5, 5) },
      sow: { state: "not-started" },
    },
  },
  {
    id: "w-priya",
    name: "Priya Singh",
    initials: "PS",
    email: "priya.singh@example.com",
    job: "Operations Associate",
    client: "Anthropic",
    employmentType: "Int'l Independent Contractor",
    payRate: "$68/hr",
    startDate: dateStr(2026, 5, 12),
    onboardingStatus: "Offer Accepted",
    manager: "Scott Marinez",
    sow: {
      state: "expiring",
      validFrom: dateStr(2026, 5, 12),
      validThru: dateStr(2026, 5, 27),
      validThruDate: new Date(2026, 4, 27),
      template: "Anthropic — SOW v3",
      hellosignTemplateId: "tpl_4f3a",
      signedAt: dateStr(2026, 5, 1),
      mergeValues: {
        worker_name: "Priya Singh",
        project_name: "Ops — ATS migration project",
        start_date: "May 12, 2026",
        end_date: "May 27, 2026",
        pay_rate: "$68.00/hr",
        project_overview: "Lead the migration of the existing ATS data into the new platform — mapping, validation, cutover.",
        scope_of_work: "Data mapping, scripted migration runs, QA against production samples.",
        deliverables: "Clean migration of all open requisitions and historical data; runbook for the cutover; rollback plan.",
        acceptance_criteria: "All requisitions live in the new ATS with a 100% data match against source-of-truth.",
      },
      history: [
        { signedAt: dateStr(2026, 5, 1), endDate: dateStr(2026, 5, 27), supersededAt: null, status: "active" },
      ],
    },
    badges: {
      handbook: { state: "signed", at: dateStr(2026, 5, 1) },
      codeOfEthics: { state: "signed", at: dateStr(2026, 5, 1) },
      fedW4: { state: "signed", at: dateStr(2026, 5, 1) },
      i9: { state: "signed", at: dateStr(2026, 5, 1) },
      paymentMethod: { state: "signed", at: dateStr(2026, 5, 1) },
      sow: { state: "signed", at: dateStr(2026, 5, 1) },
    },
  },
  {
    id: "w-noah",
    name: "Noah Anderson",
    initials: "NA",
    email: "noah.anderson@example.com",
    job: "Project Coordinator",
    client: "Anthropic",
    employmentType: "1099 Contractor",
    payRate: "$62/hr",
    startDate: dateStr(2026, 5, 4),
    onboardingStatus: "Offer Accepted",
    manager: "Scott Marinez",
    sow: {
      state: "open-ended",
      validFrom: dateStr(2026, 5, 4),
      validThru: null,
      validThruDate: null,
      template: "Anthropic — SOW v3",
      hellosignTemplateId: "tpl_4f3a",
      signedAt: dateStr(2026, 5, 1),
      mergeValues: {
        worker_name: "Noah Anderson",
        project_name: "Long-term project coordination — research org",
        start_date: "May 4, 2026",
        end_date: "",
        pay_rate: "$62.00/hr",
        project_overview: "Ongoing coordination support for the research org — meeting cadences, project tracking, vendor management.",
        scope_of_work: "Cross-team scheduling, vendor coordination, monthly progress digests.",
        deliverables: "",
        acceptance_criteria: "",
      },
      history: [
        { signedAt: dateStr(2026, 5, 1), endDate: null, supersededAt: null, status: "active" },
      ],
    },
    badges: {
      handbook: { state: "signed", at: dateStr(2026, 5, 1) },
      codeOfEthics: { state: "signed", at: dateStr(2026, 5, 1) },
      fedW4: { state: "signed", at: dateStr(2026, 5, 1) },
      i9: { state: "signed", at: dateStr(2026, 5, 1) },
      paymentMethod: { state: "signed", at: dateStr(2026, 5, 1) },
      sow: { state: "signed", at: dateStr(2026, 5, 1) },
    },
  },
  {
    id: "w-lin",
    name: "Lin Zhao",
    initials: "LZ",
    email: "lin.zhao@example.com",
    job: "Technical Writer",
    client: "Anthropic",
    employmentType: "Int'l Independent Contractor",
    payRate: "$84/hr",
    startDate: dateStr(2026, 5, 13),
    onboardingStatus: "Offer Sent",
    manager: "Scott Marinez",
    sow: {
      state: "pending-signature",
      validFrom: dateStr(2025, 8, 13),
      validThru: dateStr(2026, 6, 3),
      validThruDate: new Date(2026, 5, 3),
      template: "Anthropic — SOW v3",
      hellosignTemplateId: "tpl_4f3a",
      signedAt: null,
      mergeValues: {
        worker_name: "Lin Zhao",
        project_name: "API documentation refresh",
        start_date: "Aug 13, 2025",
        end_date: "Jun 3, 2026",
        pay_rate: "$84.00/hr",
        project_overview: "Audit and rewrite the public API documentation set for the new platform release.",
        scope_of_work: "Doc audit, rewrites, code-sample validation, accessibility pass.",
        deliverables: "Refreshed docs site live for the API v2 launch. Editorial style guide updated.",
        acceptance_criteria: "All endpoints documented with working code samples in 3 languages. Reviewed by DevRel.",
      },
      history: [
        { signedAt: null, endDate: dateStr(2026, 6, 3), supersededAt: null, status: "pending-signature" },
      ],
    },
    badges: {
      handbook: { state: "not-started" },
      codeOfEthics: { state: "not-started" },
      fedW4: { state: "not-started" },
      i9: { state: "not-started" },
      paymentMethod: { state: "not-started" },
      sow: { state: "not-started" },
    },
  },
  {
    id: "w-sofia",
    name: "Sofia Rossi",
    initials: "SR",
    email: "sofia.rossi@example.com",
    job: "Product Designer",
    client: "Anthropic",
    employmentType: "1099 Contractor",
    payRate: "$120/hr",
    startDate: dateStr(2026, 5, 18),
    onboardingStatus: "Offer Sent",
    manager: "Scott Marinez",
    sow: {
      state: "expiring",
      validFrom: dateStr(2026, 2, 18),
      validThru: dateStr(2026, 5, 13),
      validThruDate: new Date(2026, 4, 13),
      template: "Anthropic — SOW v3",
      hellosignTemplateId: "tpl_4f3a",
      signedAt: dateStr(2026, 2, 17),
      mergeValues: {
        worker_name: "Sofia Rossi",
        project_name: "Brand refresh — marketing site",
        start_date: "Feb 18, 2026",
        end_date: "May 13, 2026",
        pay_rate: "$120.00/hr",
        project_overview: "Lead the visual rework of the marketing site, including a new illustration system and component library refresh.",
        scope_of_work: "Visual exploration, system docs, hand-off to web eng.",
        deliverables: "New brand guidelines, illustrated marketing pages live on the new system.",
        acceptance_criteria: "Sign-off from VP marketing and head of design.",
      },
      history: [
        { signedAt: dateStr(2026, 2, 17), endDate: dateStr(2026, 5, 13), supersededAt: null, status: "active" },
      ],
    },
    badges: {
      handbook: { state: "signed", at: dateStr(2026, 2, 16) },
      codeOfEthics: { state: "signed", at: dateStr(2026, 2, 16) },
      fedW4: { state: "n/a" },
      i9: { state: "n/a" },
      paymentMethod: { state: "signed", at: dateStr(2026, 2, 17) },
      sow: { state: "signed", at: dateStr(2026, 2, 17) },
    },
  },
];

// ---------- Dropbox Sign template merge fields ----------
// Mirrors what the Dropbox Sign API returns. Order matters; HireArt renders
// one input per merge field, labels auto-derived from snake_case names.
const SOW_TEMPLATE_FIELDS = [
  // System-supplied — read-only in the form, always sent at signing time.
  { name: "worker_name",        type: "text",     system: true,  numLines: 1, numCharsPerLine: 60 },
  { name: "project_name",       type: "text",     system: false, numLines: 1, numCharsPerLine: 60 },
  { name: "start_date",         type: "date",     system: true,  numLines: 1, numCharsPerLine: 20 },
  { name: "end_date",           type: "date",     system: false, numLines: 1, numCharsPerLine: 20 },
  { name: "pay_rate",           type: "text",     system: true,  numLines: 1, numCharsPerLine: 20 },
  { name: "project_overview",   type: "text",     system: false, numLines: 4, numCharsPerLine: 80, hint: "Free-form summary; appears at the top of the SOW." },
  { name: "scope_of_work",      type: "text",     system: false, numLines: 6, numCharsPerLine: 80 },
];

// ---------- Decomposed badge requirements (Epic 1) ----------
// What "Sign Documents" used to be a single badge for — now decomposed.
const ONBOARDING_DOC_REQUIREMENTS = [
  { key: "handbook",       label: "HireArt employee handbook",       category: "worker",     expirable: false, hellosign: true,  badgeReq: "BadgeRequirements::EmployeeHandbook" },
  { key: "codeOfEthics",   label: "Code of ethics",                  category: "worker",     expirable: false, hellosign: true,  badgeReq: "BadgeRequirements::CodeOfEthics" },
  { key: "fedW4",          label: "Federal W-4",                     category: "worker",     expirable: false, hellosign: true,  badgeReq: "BadgeRequirements::FederalW4" },
  { key: "i9",             label: "I-9 verification",                category: "worker",     expirable: false, hellosign: false, badgeReq: "BadgeRequirements::I9Verification" },
  { key: "paymentMethod",  label: "Payment method",                  category: "worker",     expirable: false, hellosign: false, badgeReq: "BadgeRequirements::PaymentMethod" },
  { key: "sow",            label: "Statement of Work",               category: "assignment", expirable: true,  hellosign: true,  badgeReq: "BadgeRequirements::StatementOfWork" },
];

// ---------- Activity / audit feed ----------
const ACTIVITY = [
  { ts: "Today 10:42",     who: "System",          what: "SOW expiration reminder sent",     worker: "Maya Chen",   detail: "T-12 days. Email + customer.io event fired." },
  { ts: "Today 09:15",     who: "Scott Marinez",   what: "Triggered re-engagement",           worker: "Aisha Patel", detail: "Drafted new SOW with end date Nov 4, 2026." },
  { ts: "Yesterday 16:22", who: "Jamal Williams",  what: "Began onboarding flow",             worker: "Jamal Williams", detail: "Reached SOW signing step." },
  { ts: "Yesterday 11:03", who: "System",          what: "SOW expired",                        worker: "Aisha Patel", detail: "Status flipped to expired. Manager notified." },
  { ts: "May 3, 16:48",    who: "Felix Becker",    what: "Signed SOW",                         worker: "Felix Becker", detail: "DocumentMergeContent created. Cert of Completion stored." },
  { ts: "May 1, 09:12",    who: "Priya Singh",     what: "Signed SOW",                         worker: "Priya Singh", detail: "End date May 27, 2026." },
];

Object.assign(window, { WORKERS, SOW_TEMPLATE_FIELDS, ONBOARDING_DOC_REQUIREMENTS, ACTIVITY, today, daysFromNow });

// ---------- Expiring credentials registry (generalized) ----------
// Any badge or document with an expiration date lives here. The dashboard is
// agnostic to credential type — it just renders rows of {worker, credentialType, expires}.
//   - statement_of_work (assignment-scoped, per-project)
//   - drivers_license (worker-scoped, regulatory)
//   - hireart_handbook (worker-scoped, annual re-acknowledgment)
//   - background_check, cpr_cert, etc. — easy to add
const CREDENTIAL_TYPES = {
  statement_of_work: {
    label: "Statement of Work",
    icon: "document",
    scope: "assignment",          // per-project
    description: "Project-scoped SOW",
  },
  drivers_license: {
    label: "Driver's license",
    icon: "credit-card",
    scope: "worker",
    description: "State-issued driver's license (worker-uploaded)",
  },
  hireart_handbook: {
    label: "HireArt handbook",
    icon: "document",
    scope: "worker",
    description: "Annual re-acknowledgment of the HireArt employee handbook",
  },
  background_check: {
    label: "Background check",
    icon: "user",
    scope: "worker",
    description: "Annual background re-screen",
  },
};

function makeCred(workerId, type, expires, opts = {}) {
  const w = WORKERS.find(x => x.id === workerId);
  return {
    id: `${workerId}-${type}-${expires || "open"}`,
    workerId,
    workerName: w ? w.name : "—",
    workerEmail: w ? w.email : "",
    workerJob: w ? w.job : "",
    client: w ? w.client : "—",
    type,                                       // key into CREDENTIAL_TYPES
    label: CREDENTIAL_TYPES[type].label,
    scope: CREDENTIAL_TYPES[type].scope,
    expires,                                    // ISO-ish "May 18, 2026" or null for open-ended
    expiresDate: expires ? new Date(expires) : null,
    status: opts.status || "active",            // active | expiring | expired | pending-signature
    project: opts.project || null,              // only on assignment-scoped creds
    notes: opts.notes || null,
  };
}

// Synthesize credential rows from the existing WORKERS data + a few additional
// non-SOW credentials to demonstrate the generalized dashboard.
const EXPIRING_CREDENTIALS = [
  // SOWs derived from existing WORKERS data
  ...WORKERS
    .filter(w => ["expiring", "expired", "pending-signature", "in-progress"].includes(w.sow.state))
    .map(w => makeCred(w.id, "statement_of_work", w.sow.validThru, {
      status: w.sow.state === "in-progress" ? "pending-signature" : w.sow.state,
      project: w.sow.mergeValues.project_name,
    })),

  // Driver's licenses — worker-scoped, regulatory
  makeCred("w-jamal", "drivers_license", "Jun 2, 2026", { status: "expiring", notes: "CA license · uploaded by worker" }),
  makeCred("w-aisha", "drivers_license", "Apr 18, 2026", { status: "expired", notes: "NY license · re-upload required" }),

  // HireArt handbook — annual re-acknowledgment
  makeCred("w-felix", "hireart_handbook", "May 14, 2026", { status: "expiring", notes: "Re-sign annually" }),
  makeCred("w-maya",  "hireart_handbook", "May 22, 2026", { status: "expiring", notes: "Re-sign annually" }),

  // Background checks
  makeCred("w-priya", "background_check", "May 30, 2026", { status: "expiring", notes: "Annual re-screen" }),
];

Object.assign(window, { CREDENTIAL_TYPES, EXPIRING_CREDENTIALS });

})();
