/* ============================================================
   beedle dataroom — mock data
   dataroom/company, dataroom/sections, dataroom/documents, keys, roles
   ============================================================ */

// ---- Company (dataroom/company) ----
const COMPANY = {
  name: "beedle solutions Inc.",
  tagline: "Simplified Technology for Families & Seniors",
  description:
    "beedle is an always-on communication and care hub — a voice-assisted touchscreen and companion app purpose-built for seniors and people living with cognitive or physical challenges, and the families and caregivers who support them.",
  location: "Montreal, Quebec, Canada",
  founded: "2022",
  stage: "Series A",
  room: "Series A — Due Diligence",
  colors: { blue: "#15B4E7", gold: "#F3BB3A", red: "#EC2B3B" },
};

// ---- Keys (visibility) ----
// The key catalog is DYNAMIC: the server persists it (config.keys) and the app
// hydrates it on boot via setKeys(). Every authenticated user implicitly holds
// "all" (the public key, always present). Components read this same object, so
// setKeys() mutates it in place rather than replacing the reference.
const KEYS = {
  all:           { label: "All members",   tone: "" },
  "series-a":    { label: "Series A",       tone: "blue" },
  "lead":        { label: "Lead investor",  tone: "gold" },
  legal:         { label: "Legal counsel",  tone: "red" },
};
function setKeys(next) {
  for (const k of Object.keys(KEYS)) delete KEYS[k];
  KEYS.all = { label: "All members", tone: "" };
  if (next && typeof next === "object") {
    for (const [k, v] of Object.entries(next)) {
      if (k === "all") continue;
      KEYS[k] = { label: (v && v.label) || k, tone: (v && v.tone) || "" };
    }
  }
}

// ---- Roles / keyrings (dataroom-admin sets these per user) ----
const ROLES = {
  admin: {
    id: "admin", name: "Dana Whitfield", role: "Dataroom Admin",
    initials: "DW", avatar: "admin", admin: true,
    keyring: ["all", "series-a", "lead", "legal"],
    desc: "Full control — manage sections, documents, branding & keys.",
  },
  lead: {
    id: "lead", name: "Marcus Ø. Reyes", role: "Lead Investor",
    initials: "MR", avatar: "gold", admin: false,
    keyring: ["all", "series-a", "lead"],
    desc: "Northwind Capital — holds the lead-investor key.",
  },
  seriesa: {
    id: "seriesa", name: "Priya Anand", role: "Series A Investor",
    initials: "PA", avatar: "", admin: false,
    keyring: ["all", "series-a"],
    desc: "Syndicate participant — Series A access, no legal room.",
  },
  basic: {
    id: "basic", name: "Jordan Lee", role: "Prospective Investor",
    initials: "JL", avatar: "red", admin: false,
    keyring: ["all"],
    desc: "NDA on file — overview materials only.",
  },
};

// ---- Sections (dataroom/sections) ----
// icon keys map to ICONS in icons.jsx
const SECTIONS = [
  { id: "overview",  name: "Company Overview",   icon: "compass",  color: "#15B4E7", key: "all",
    desc: "Executive summary, pitch deck, and the beedle story." },
  { id: "product",   name: "Product & Technology", icon: "cpu",    color: "#0E97C6", key: "all",
    desc: "The device, the care app, and how it all fits together." },
  { id: "market",    name: "Market & Traction",  icon: "trend",    color: "#1E9E6A", key: "series-a",
    desc: "TAM, go-to-market, pilots, and customer love." },
  { id: "financials",name: "Financials",         icon: "chart",    color: "#E0762B", key: "series-a",
    desc: "Model, P&L, unit economics and the Series A ask." },
  { id: "legal",     name: "Legal & Cap Table",  icon: "scale",    color: "#7A57D1", key: "lead",
    desc: "Incorporation, cap table, IP and the draft term sheet." },
  { id: "team",      name: "Team & People",      icon: "people",   color: "#EC2B3B", key: "all",
    desc: "Founders, advisors, org chart and hiring plan." },
];

// ---- Documents (dataroom/documents) ----
// type: pdf | image | html | video | ppt
let _id = 0; const uid = () => "doc_" + (++_id);
const DOCUMENTS = [
  // Company Overview
  { id: uid(), section: "overview", name: "Executive Summary", type: "html", key: "all",
    size: "—", pages: 1, updated: "May 28, 2026", downloadable: true,
    by: "Dana Whitfield", desc: "A one-page narrative on what beedle is, who it serves, and why now." },
  { id: uid(), section: "overview", name: "Series A Pitch Deck", type: "ppt", key: "all",
    size: "14.2 MB", pages: 18, updated: "May 30, 2026", downloadable: true,
    by: "Dana Whitfield", desc: "The full investor deck — problem, product, market, traction, ask." },
  { id: uid(), section: "overview", name: "Company Fact Sheet", type: "pdf", key: "all",
    size: "0.4 MB", pages: 2, updated: "May 12, 2026", downloadable: true,
    by: "Dana Whitfield", desc: "Key facts, milestones and contacts at a glance." },

  // Product & Technology
  { id: uid(), section: "product", name: "Product Demo — 24\" Hub", type: "video", key: "all",
    size: "86 MB", pages: 1, updated: "May 24, 2026", downloadable: false, duration: "3:42",
    by: "Sofia Marchetti", desc: "A walk-through of the touchscreen device and a guided care-call." },
  { id: uid(), section: "product", name: "Device Photography", type: "image", key: "all",
    size: "5.1 MB", pages: 6, updated: "Apr 30, 2026", downloadable: true,
    by: "Sofia Marchetti", desc: "Studio and in-home photos of the beedle hub." },
  { id: uid(), section: "product", name: "Technical Architecture", type: "pdf", key: "all",
    size: "1.8 MB", pages: 11, updated: "May 18, 2026", downloadable: false,
    by: "Aiden Cho", desc: "System diagram, data flow, security model and platform stack." },

  // Market & Traction
  { id: uid(), section: "market", name: "Market & TAM Analysis", type: "pdf", key: "series-a",
    size: "2.3 MB", pages: 9, updated: "May 20, 2026", downloadable: true,
    by: "Priya patel", desc: "Aging-in-place market sizing for North America and the EU." },
  { id: uid(), section: "market", name: "Traction Dashboard", type: "html", key: "series-a",
    size: "—", pages: 1, updated: "Jun 02, 2026", downloadable: false,
    by: "Dana Whitfield", desc: "Live-style KPI snapshot — pilots, MRR, retention, NPS." },
  { id: uid(), section: "market", name: "Customer Testimonials", type: "video", key: "series-a",
    size: "62 MB", pages: 1, updated: "May 16, 2026", downloadable: false, duration: "2:18",
    by: "Sofia Marchetti", desc: "Families and care homes on living with beedle." },

  // Financials
  { id: uid(), section: "financials", name: "Financial Model (5-yr)", type: "pdf", key: "series-a",
    size: "3.6 MB", pages: 22, updated: "Jun 01, 2026", downloadable: false,
    by: "Renée Dubois", desc: "Bottom-up model, assumptions, cohort and scenario sheets." },
  { id: uid(), section: "financials", name: "P&L Statement 2024–2025", type: "pdf", key: "series-a",
    size: "0.9 MB", pages: 4, updated: "May 10, 2026", downloadable: true,
    by: "Renée Dubois", desc: "Audited profit & loss for the last two fiscal years." },
  { id: uid(), section: "financials", name: "Unit Economics", type: "html", key: "series-a",
    size: "—", pages: 1, updated: "May 29, 2026", downloadable: false,
    by: "Renée Dubois", desc: "CAC, LTV, payback and contribution margin by channel." },

  // Legal & Cap Table
  { id: uid(), section: "legal", name: "Capitalization Table", type: "pdf", key: "lead",
    size: "0.6 MB", pages: 3, updated: "May 31, 2026", downloadable: false,
    by: "Dana Whitfield", desc: "Fully-diluted cap table including option pool." },
  { id: uid(), section: "legal", name: "Articles of Incorporation", type: "pdf", key: "legal",
    size: "1.1 MB", pages: 14, updated: "Jan 18, 2026", downloadable: false,
    by: "Counsel — Fabron LLP", desc: "Federal incorporation and amended articles." },
  { id: uid(), section: "legal", name: "Draft Term Sheet", type: "pdf", key: "lead",
    size: "0.5 MB", pages: 6, updated: "Jun 03, 2026", downloadable: false,
    by: "Counsel — Fabron LLP", desc: "Proposed Series A terms — confidential." },

  // Team
  { id: uid(), section: "team", name: "Founders & Leadership", type: "html", key: "all",
    size: "—", pages: 1, updated: "May 22, 2026", downloadable: true,
    by: "Dana Whitfield", desc: "Bios for the founding team and key leadership." },
  { id: uid(), section: "team", name: "Org Chart & Hiring Plan", type: "image", key: "all",
    size: "0.8 MB", pages: 1, updated: "May 08, 2026", downloadable: true,
    by: "Dana Whitfield", desc: "Current org and the 18-month hiring roadmap." },
];

// ---- helpers ----
// Mode-aware: "can see it exists" = at least the list mode (see modes.js). Falls
// back to the old binary rule if the kernel isn't loaded (static prototype).
function canSee(item, role){
  if (window.accessMode) return window.accessMode(item, role) >= window.MODE_RANK.list;
  if (role.admin) return true;
  return item.key === "all" || role.keyring.includes(item.key);
}
function visibleSections(role){ return SECTIONS.filter(s => canSee(s, role)); }
function sectionDocs(secId){ return DOCUMENTS.filter(d => d.section === secId); }
function visibleDocs(secId, role){ return sectionDocs(secId).filter(d => canSee(d, role)); }

Object.assign(window, {
  COMPANY, KEYS, ROLES, SECTIONS, DOCUMENTS, setKeys,
  canSee, visibleSections, sectionDocs, visibleDocs,
});
