// ============================================
// Mock data for 社内システム共通マスター登録
// Video / animation production company
// ============================================

const DEPARTMENTS = [
  { id: "D001", code: "PRD",  name: "プロダクション部",    nameEn: "Production",     manager: "S014", members: 18, createdAt: "2022-04-01", note: "プロデューサー・制作進行が所属" },
  { id: "D002", code: "ANIM", name: "アニメーション部",    nameEn: "Animation",      manager: "S005", members: 24, createdAt: "2022-04-01", note: "原画・動画・作監ライン" },
  { id: "D003", code: "BG",   name: "美術部",              nameEn: "Background Art", manager: "S009", members: 9,  createdAt: "2022-04-01", note: "背景美術・美術設定" },
  { id: "D004", code: "CG",   name: "3DCG部",              nameEn: "3DCG",           manager: "S012", members: 11, createdAt: "2022-04-01", note: "モデリング・リギング・アニメーション" },
  { id: "D005", code: "COMP", name: "撮影・コンポジット部", nameEn: "Compositing",    manager: "S016", members: 8,  createdAt: "2022-04-01", note: "撮影・コンポジット・色彩設計" },
  { id: "D006", code: "SND",  name: "サウンド部",          nameEn: "Sound",          manager: "S021", members: 5,  createdAt: "2022-06-15", note: "音響監督・MA・効果" },
  { id: "D007", code: "ADM",  name: "管理本部",            nameEn: "Admin",          manager: "S001", members: 6,  createdAt: "2022-04-01", note: "経理・人事・総務" },
];

const ROLES = [
  { id: "R001", code: "PRD",   name: "プロデューサー",    category: "プロダクション", level: 5, count: 4,  createdAt: "2022-04-01" },
  { id: "R002", code: "APRD",  name: "アシスタントプロデューサー", category: "プロダクション", level: 3, count: 3, createdAt: "2022-04-01" },
  { id: "R003", code: "DESK",  name: "制作デスク",        category: "プロダクション", level: 4, count: 2,  createdAt: "2022-04-01" },
  { id: "R004", code: "PMGR",  name: "制作進行",          category: "プロダクション", level: 2, count: 9,  createdAt: "2022-04-01" },
  { id: "R005", code: "DIR",   name: "監督",              category: "演出",           level: 5, count: 3,  createdAt: "2022-04-01" },
  { id: "R006", code: "EPDIR", name: "話数演出",          category: "演出",           level: 4, count: 4,  createdAt: "2022-04-01" },
  { id: "R007", code: "STBD",  name: "絵コンテ",          category: "演出",           level: 4, count: 2,  createdAt: "2022-04-01" },
  { id: "R008", code: "ADIR",  name: "作画監督",          category: "アニメーション", level: 4, count: 5,  createdAt: "2022-04-01" },
  { id: "R009", code: "KGA",   name: "原画",              category: "アニメーション", level: 3, count: 14, createdAt: "2022-04-01" },
  { id: "R010", code: "DOGA",  name: "動画",              category: "アニメーション", level: 1, count: 8,  createdAt: "2022-04-01" },
  { id: "R011", code: "BGDIR", name: "美術監督",          category: "美術",           level: 5, count: 1,  createdAt: "2022-04-01" },
  { id: "R012", code: "BGART", name: "背景美術",          category: "美術",           level: 3, count: 7,  createdAt: "2022-04-01" },
  { id: "R013", code: "CGDIR", name: "CGディレクター",    category: "3DCG",           level: 5, count: 1,  createdAt: "2022-04-01" },
  { id: "R014", code: "CGANI", name: "CGアニメーター",    category: "3DCG",           level: 3, count: 6,  createdAt: "2022-04-01" },
  { id: "R015", code: "CMP",   name: "撮影",              category: "撮影",           level: 3, count: 5,  createdAt: "2022-04-01" },
  { id: "R016", code: "CMPLD", name: "撮影監督",          category: "撮影",           level: 5, count: 1,  createdAt: "2022-04-01" },
  { id: "R017", code: "CDS",   name: "色彩設計",          category: "撮影",           level: 4, count: 1,  createdAt: "2022-04-01" },
  { id: "R018", code: "SNDIR", name: "音響監督",          category: "サウンド",       level: 5, count: 1,  createdAt: "2022-04-01" },
  { id: "R019", code: "MIX",   name: "ミキサー",          category: "サウンド",       level: 3, count: 2,  createdAt: "2022-04-01" },
  { id: "R020", code: "EXEC",  name: "代表・役員",        category: "管理",           level: 5, count: 2,  createdAt: "2022-04-01" },
  { id: "R021", code: "KEIRI", name: "経理",              category: "管理",           level: 3, count: 3,  createdAt: "2022-04-01" },
  { id: "R022", code: "JINJI", name: "人事",              category: "管理",           level: 3, count: 1,  createdAt: "2022-04-01" },
  { id: "R023", code: "SOMU",  name: "総務",              category: "管理",           level: 3, count: 1,  createdAt: "2022-04-01" },
  { id: "R024", code: "SALES", name: "営業",              category: "管理",           level: 3, count: 3,  createdAt: "2022-04-01" },
  { id: "R025", code: "IT",    name: "IT管理",            category: "管理",           level: 3, count: 1,  createdAt: "2024-04-01" },
];

const AVATAR_PALETTE = [
  ["#fee2e2", "#991b1b"], ["#fef3c7", "#92400e"], ["#dcfce7", "#166534"],
  ["#dbeafe", "#1e40af"], ["#ede9fe", "#5b21b6"], ["#fce7f3", "#9d174d"],
  ["#f3e8ff", "#6b21a8"], ["#e0f2fe", "#075985"], ["#fef9c3", "#854d0e"],
  ["#fae8ff", "#86198f"]
];

const STAFF = [
  { id: "S001", code: "A0001", lastName: "山田", firstName: "健一",    lastKana: "ヤマダ",     firstKana: "ケンイチ",    email: "yamada.k@adfproject.jp",   dept: "D007", roles: ["R020", "R021"],         status: "active",   joined: "2010-04-01", note: "代表取締役・経理統括" },
  { id: "S002", code: "A0002", lastName: "佐藤", firstName: "美咲",    lastKana: "サトウ",     firstKana: "ミサキ",      email: "sato.m@adfproject.jp",     dept: "D001", roles: ["R001", "R024"],         status: "active",   joined: "2012-04-01", note: "主任プロデューサー・営業窓口" },
  { id: "S003", code: "A0003", lastName: "鈴木", firstName: "拓海",    lastKana: "スズキ",     firstKana: "タクミ",      email: "suzuki.t@adfproject.jp",   dept: "D001", roles: ["R002"],                 status: "active",   joined: "2018-04-01", note: "" },
  { id: "S004", code: "A0004", lastName: "高橋", firstName: "あかね",  lastKana: "タカハシ",   firstKana: "アカネ",      email: "takahashi.a@adfproject.jp", dept: "D001", roles: ["R004"],                 status: "active",   joined: "2023-04-01", note: "新人研修中" },
  { id: "S005", code: "A0005", lastName: "中村", firstName: "晃",      lastKana: "ナカムラ",   firstKana: "アキラ",      email: "nakamura.a@adfproject.jp", dept: "D002", roles: ["R005", "R007"],         status: "active",   joined: "2008-10-01", note: "監督・絵コンテ兼任" },
  { id: "S006", code: "A0006", lastName: "渡辺", firstName: "千夏",    lastKana: "ワタナベ",   firstKana: "チナツ",      email: "watanabe.c@adfproject.jp", dept: "D002", roles: ["R008"],                 status: "active",   joined: "2014-04-01", note: "" },
  { id: "S007", code: "A0007", lastName: "伊藤", firstName: "翔",      lastKana: "イトウ",     firstKana: "ショウ",      email: "ito.s@adfproject.jp",      dept: "D002", roles: ["R009"],                 status: "active",   joined: "2019-04-01", note: "アクション作画" },
  { id: "S008", code: "A0008", lastName: "小林", firstName: "美月",    lastKana: "コバヤシ",   firstKana: "ミヅキ",      email: "kobayashi.m@adfproject.jp", dept: "D002", roles: ["R009"],                 status: "active",   joined: "2021-04-01", note: "" },
  { id: "S009", code: "A0009", lastName: "加藤", firstName: "雄介",    lastKana: "カトウ",     firstKana: "ユウスケ",    email: "kato.y@adfproject.jp",     dept: "D003", roles: ["R011"],                 status: "active",   joined: "2011-04-01", note: "" },
  { id: "S010", code: "A0010", lastName: "吉田", firstName: "葵",      lastKana: "ヨシダ",     firstKana: "アオイ",      email: "yoshida.a@adfproject.jp",  dept: "D003", roles: ["R012"],                 status: "active",   joined: "2020-04-01", note: "" },
  { id: "S011", code: "A0011", lastName: "山本", firstName: "蓮",      lastKana: "ヤマモト",   firstKana: "レン",        email: "yamamoto.r@adfproject.jp", dept: "D003", roles: ["R012"],                 status: "leave",    joined: "2019-09-01", note: "育休中" },
  { id: "S012", code: "A0012", lastName: "松本", firstName: "智也",    lastKana: "マツモト",   firstKana: "トモヤ",      email: "matsumoto.t@adfproject.jp", dept: "D004", roles: ["R013"],                 status: "active",   joined: "2013-04-01", note: "CGリード" },
  { id: "S013", code: "A0013", lastName: "井上", firstName: "美緒",    lastKana: "イノウエ",   firstKana: "ミオ",        email: "inoue.m@adfproject.jp",    dept: "D004", roles: ["R014"],                 status: "active",   joined: "2020-04-01", note: "" },
  { id: "S014", code: "A0014", lastName: "木村", firstName: "亮太",    lastKana: "キムラ",     firstKana: "リョウタ",    email: "kimura.r@adfproject.jp",   dept: "D001", roles: ["R001", "R024"],         status: "active",   joined: "2009-04-01", note: "P・営業" },
  { id: "S015", code: "A0015", lastName: "斎藤", firstName: "彩",      lastKana: "サイトウ",   firstKana: "アヤ",        email: "saito.a@adfproject.jp",    dept: "D001", roles: ["R003", "R021"],         status: "active",   joined: "2016-04-01", note: "制作デスク・経理兼任" },
  { id: "S016", code: "A0016", lastName: "清水", firstName: "大樹",    lastKana: "シミズ",     firstKana: "ダイキ",      email: "shimizu.d@adfproject.jp",  dept: "D005", roles: ["R016"],                 status: "active",   joined: "2014-04-01", note: "" },
  { id: "S017", code: "A0017", lastName: "森",   firstName: "由香",    lastKana: "モリ",       firstKana: "ユカ",        email: "mori.y@adfproject.jp",     dept: "D005", roles: ["R015"],                 status: "active",   joined: "2021-04-01", note: "" },
  { id: "S018", code: "A0018", lastName: "池田", firstName: "祐介",    lastKana: "イケダ",     firstKana: "ユウスケ",    email: "ikeda.y@adfproject.jp",    dept: "D005", roles: ["R017"],                 status: "active",   joined: "2018-04-01", note: "" },
  { id: "S019", code: "A0019", lastName: "橋本", firstName: "美波",    lastKana: "ハシモト",   firstKana: "ミナミ",      email: "hashimoto.m@adfproject.jp", dept: "D002", roles: ["R006", "R007"],         status: "active",   joined: "2017-04-01", note: "話数演出・絵コンテ" },
  { id: "S020", code: "A0020", lastName: "石川", firstName: "颯",      lastKana: "イシカワ",   firstKana: "ハヤテ",      email: "ishikawa.h@adfproject.jp", dept: "D002", roles: ["R009"],                 status: "active",   joined: "2019-04-01", note: "メカ作画" },
  { id: "S021", code: "A0021", lastName: "前田", firstName: "桂",      lastKana: "マエダ",     firstKana: "カツラ",      email: "maeda.k@adfproject.jp",    dept: "D006", roles: ["R018"],                 status: "active",   joined: "2015-04-01", note: "" },
  { id: "S022", code: "A0022", lastName: "藤田", firstName: "明日香",  lastKana: "フジタ",     firstKana: "アスカ",      email: "fujita.a@adfproject.jp",   dept: "D006", roles: ["R019"],                 status: "active",   joined: "2020-04-01", note: "" },
  { id: "S023", code: "A0023", lastName: "岡田", firstName: "悠人",    lastKana: "オカダ",     firstKana: "ユウト",      email: "okada.y@adfproject.jp",    dept: "D002", roles: ["R010"],                 status: "active",   joined: "2024-04-01", note: "新人" },
  { id: "S024", code: "A0024", lastName: "後藤", firstName: "玲奈",    lastKana: "ゴトウ",     firstKana: "レナ",        email: "goto.r@adfproject.jp",     dept: "D002", roles: ["R010"],                 status: "active",   joined: "2024-04-01", note: "新人" },
  { id: "S025", code: "A0025", lastName: "長谷川", firstName: "凛",    lastKana: "ハセガワ",   firstKana: "リン",        email: "hasegawa.r@adfproject.jp", dept: "D004", roles: ["R014"],                 status: "active",   joined: "2022-04-01", note: "" },
  { id: "S026", code: "A0026", lastName: "村上", firstName: "海斗",    lastKana: "ムラカミ",   firstKana: "カイト",      email: "murakami.k@adfproject.jp", dept: "D001", roles: ["R004"],                 status: "active",   joined: "2022-04-01", note: "" },
  { id: "S027", code: "A0027", lastName: "近藤", firstName: "麻衣",    lastKana: "コンドウ",   firstKana: "マイ",        email: "kondo.m@adfproject.jp",    dept: "D001", roles: ["R004"],                 status: "active",   joined: "2021-04-01", note: "海外案件対応" },
  { id: "S028", code: "A0028", lastName: "坂本", firstName: "陽太",    lastKana: "サカモト",   firstKana: "ヨウタ",      email: "sakamoto.y@adfproject.jp", dept: "D002", roles: ["R006"],                 status: "active",   joined: "2017-04-01", note: "" },
  { id: "S029", code: "A0029", lastName: "遠藤", firstName: "莉子",    lastKana: "エンドウ",   firstKana: "リコ",        email: "endo.r@adfproject.jp",     dept: "D003", roles: ["R012"],                 status: "active",   joined: "2022-04-01", note: "" },
  { id: "S030", code: "A0030", lastName: "青木", firstName: "翼",      lastKana: "アオキ",     firstKana: "ツバサ",      email: "aoki.t@adfproject.jp",     dept: "D007", roles: ["R021"],                 status: "inactive", joined: "2013-04-01", note: "退職済 2024-03" },
  { id: "S031", code: "A0031", lastName: "白井", firstName: "知佳",    lastKana: "シライ",     firstKana: "チカ",        email: "shirai.c@adfproject.jp",   dept: "D007", roles: ["R022", "R023"],         status: "active",   joined: "2016-04-01", note: "人事・総務兼任" },
  { id: "S032", code: "A0032", lastName: "野口", firstName: "稔",      lastKana: "ノグチ",     firstKana: "ミノル",      email: "noguchi.m@adfproject.jp",  dept: "D007", roles: ["R025"],                 status: "active",   joined: "2020-04-01", note: "情報システム" },
];

const WORKS = [
  { id: "W001", code: "ADF-2024-01", title: "蒼海のクラリオン",            titleEn: "Clarion of the Azure Sea", clientId: "CL01", producer: "S002", director: "S005", status: "in_production",   type: "TV",      episodes: 12, startDate: "2024-04-01", endDate: "2024-09-30", budget: 480000000, tags: ["ファンタジー", "ハイファンタジー"],
    team: [
      { staffId: "S003", roleId: "R002" },
      { staffId: "S004", roleId: "R004" },
      { staffId: "S006", roleId: "R008" },
      { staffId: "S007", roleId: "R009" },
      { staffId: "S008", roleId: "R009" },
      { staffId: "S009", roleId: "R011" },
      { staffId: "S010", roleId: "R012" },
      { staffId: "S012", roleId: "R013" },
      { staffId: "S016", roleId: "R016" },
      { staffId: "S018", roleId: "R017" },
      { staffId: "S021", roleId: "R018" },
    ]},
  { id: "W002", code: "ADF-2024-02", title: "Re:コードネーム0",            titleEn: "Re:Codename 0",            clientId: "CL02",       producer: "S014", director: "S005", status: "in_production",   type: "TV",      episodes: 24, startDate: "2024-01-08", endDate: "2024-12-22", budget: 960000000, tags: ["SF", "アクション"],
    team: [
      { staffId: "S015", roleId: "R003" },
      { staffId: "S026", roleId: "R004" },
      { staffId: "S027", roleId: "R004" },
      { staffId: "S019", roleId: "R007" },
      { staffId: "S020", roleId: "R009" },
      { staffId: "S013", roleId: "R014" },
      { staffId: "S025", roleId: "R014" },
      { staffId: "S017", roleId: "R015" },
      { staffId: "S022", roleId: "R019" },
    ]},
  { id: "W003", code: "ADF-2024-03", title: "週末のコーヒースタンド",      titleEn: "Weekend Coffee Stand",     clientId: "CL03",       producer: "S002", director: "S028", status: "completed",       type: "Movie",   episodes: 1,  startDate: "2023-06-01", endDate: "2024-04-15", budget: 320000000, tags: ["日常", "青春"],
    team: [
      { staffId: "S006", roleId: "R008" },
      { staffId: "S008", roleId: "R009" },
      { staffId: "S010", roleId: "R012" },
      { staffId: "S029", roleId: "R012" },
      { staffId: "S016", roleId: "R016" },
    ]},
  { id: "W004", code: "ADF-2024-04", title: "GeoSync Project: ZERO",       titleEn: "GeoSync Project: ZERO",    clientId: "CL04",             producer: "S014", director: "S028", status: "planning",        type: "ONA",     episodes: 6,  startDate: "2025-01-15", endDate: "2025-07-30", budget: 240000000, tags: ["SF", "短編", "配信"],
    team: [
      { staffId: "S012", roleId: "R013" },
      { staffId: "S013", roleId: "R014" },
      { staffId: "S025", roleId: "R014" },
    ]},
  { id: "W005", code: "ADF-2023-09", title: "星巡りのアレシア 第2期",      titleEn: "Alesia Starwheel S2",      clientId: "CL01",   producer: "S002", director: "S005", status: "completed",       type: "TV",      episodes: 13, startDate: "2023-04-01", endDate: "2023-09-30", budget: 520000000, tags: ["ファンタジー", "続編"],
    team: [
      { staffId: "S006", roleId: "R008" },
      { staffId: "S007", roleId: "R009" },
      { staffId: "S009", roleId: "R011" },
      { staffId: "S021", roleId: "R018" },
    ]},
  { id: "W006", code: "ADF-2024-05", title: "深夜放送ジャンクション",      titleEn: "Midnight Junction",        clientId: "CL05",                 producer: "S014", director: "S019", status: "in_production",   type: "TV",      episodes: 12, startDate: "2024-07-01", endDate: "2024-12-31", budget: 380000000, tags: ["ミステリー", "深夜枠"],
    team: [
      { staffId: "S026", roleId: "R004" },
      { staffId: "S028", roleId: "R006" },
      { staffId: "S007", roleId: "R009" },
      { staffId: "S020", roleId: "R009" },
      { staffId: "S017", roleId: "R015" },
    ]},
  { id: "W007", code: "ADF-2024-06", title: "ハイファイ・サマー",          titleEn: "Hi-Fi Summer",             clientId: "CL06",             producer: "S002", director: "S019", status: "post_production", type: "Movie",   episodes: 1,  startDate: "2023-09-01", endDate: "2025-06-30", budget: 410000000, tags: ["音楽", "青春"],
    team: [
      { staffId: "S003", roleId: "R002" },
      { staffId: "S006", roleId: "R008" },
      { staffId: "S008", roleId: "R009" },
      { staffId: "S018", roleId: "R017" },
      { staffId: "S021", roleId: "R018" },
      { staffId: "S022", roleId: "R019" },
    ]},
  { id: "W008", code: "ADF-2024-07", title: "PV-キヌガサ自動車CM春夏編",   titleEn: "Kinugasa Motors CM",       clientId: "CL07",               producer: "S014", director: "S028", status: "completed",       type: "CM",      episodes: 4,  startDate: "2024-02-01", endDate: "2024-03-31", budget: 60000000,  tags: ["CM", "受託"],
    team: [
      { staffId: "S013", roleId: "R014" },
      { staffId: "S017", roleId: "R015" },
    ]},
  { id: "W009", code: "ADF-2024-08", title: "OP-Vtuberライブ背景アニメ",    titleEn: "Vtuber Live BG",           clientId: "CL08",           producer: "S002", director: "S019", status: "in_production",   type: "Other",   episodes: 2,  startDate: "2024-09-01", endDate: "2024-11-15", budget: 28000000,  tags: ["MV", "受託"],
    team: [
      { staffId: "S010", roleId: "R012" },
      { staffId: "S017", roleId: "R015" },
    ]},
  { id: "W010", code: "ADF-2025-01", title: "残響のセプテンバー",          titleEn: "September Resonance",      clientId: "CL01",   producer: "S014", director: "S005", status: "planning",        type: "TV",      episodes: 12, startDate: "2025-04-01", endDate: "2025-09-30", budget: 540000000, tags: ["SF", "ドラマ"],
    team: [
      { staffId: "S004", roleId: "R004" },
    ]},
  { id: "W011", code: "ADF-2023-12", title: "クロスフィードの少年",        titleEn: "Crossfeed Boy",            clientId: "CL03",       producer: "S002", director: "S028", status: "completed",       type: "OVA",     episodes: 3,  startDate: "2023-01-15", endDate: "2023-12-20", budget: 180000000, tags: ["音楽", "OVA"],
    team: [
      { staffId: "S006", roleId: "R008" },
      { staffId: "S007", roleId: "R009" },
      { staffId: "S021", roleId: "R018" },
    ]},
  { id: "W012", code: "ADF-2024-09", title: "PRJ-X (仮)",                   titleEn: "Project X (tentative)",    clientId: "CL09",                    producer: "S014", director: "—",     status: "planning",        type: "TV",      episodes: 12, startDate: "2025-10-01", endDate: "2026-03-31", budget: 600000000, tags: ["未発表"],
    team: []},
];

const WORK_STATUS = {
  planning:        { label: "企画",         tone: "default" },
  in_production:   { label: "制作中",       tone: "info" },
  post_production: { label: "ポスプロ",     tone: "warning" },
  completed:       { label: "完了",         tone: "success" },
  on_hold:         { label: "停止中",       tone: "danger" },
};

const STAFF_STATUS = {
  active:   { label: "在籍",   tone: "success" },
  leave:    { label: "休職",   tone: "warning" },
  inactive: { label: "退職",   tone: "default" },
};

const EMPLOYMENT_TYPES = ["正社員", "契約社員", "業務委託", "アルバイト"];

// ============================================
// Access users — システムにログインできる人
// ============================================
const ACCESS_USERS = [
  { id: "U001", staffId: "S001", email: "yamada.k@adfproject.jp",   role: "admin",  status: "active",   lastLogin: "2026-05-18 14:32:11", invitedAt: "2022-04-01", invitedBy: null,   note: "代表" },
  { id: "U002", staffId: "S032", email: "noguchi.m@adfproject.jp",  role: "admin",  status: "active",   lastLogin: "2026-05-18 08:30:55", invitedAt: "2022-04-01", invitedBy: "U001", note: "情シス" },
  { id: "U003", staffId: "S031", email: "shirai.c@adfproject.jp",   role: "admin",  status: "active",   lastLogin: "2026-05-17 09:12:00", invitedAt: "2022-04-01", invitedBy: "U001", note: "人事・総務" },
  { id: "U004", staffId: "S015", email: "saito.a@adfproject.jp",    role: "editor", status: "active",   lastLogin: "2026-05-18 11:45:22", invitedAt: "2022-04-01", invitedBy: "U001", note: "制作デスク" },
  { id: "U005", staffId: "S003", email: "suzuki.t@adfproject.jp",   role: "editor", status: "pending",  lastLogin: null,                  invitedAt: "2026-05-17", invitedBy: "U001", note: "招待中" },
];

const USER_ROLES = {
  admin:  { label: "管理者",   tone: "accent",  description: "全マスターのCRUD + システム設定" },
  editor: { label: "編集者",   tone: "info",    description: "スタッフ・作品のCRUDのみ" },
  viewer: { label: "閲覧者",   tone: "default", description: "全マスター閲覧のみ" },
};

const USER_STATUS = {
  active:   { label: "有効",   tone: "success" },
  disabled: { label: "無効",   tone: "default" },
  pending:  { label: "招待中", tone: "warning" },
};

const AUDIT_LOG = [
  { id: "L0001", ts: "2026-05-18 14:32:11", user: "S001", entity: "staff",      entityId: "S023", action: "create", field: "—",        before: "—",          after: "岡田 悠人",      note: "新規スタッフ登録" },
  { id: "L0002", ts: "2026-05-18 13:18:04", user: "S002", entity: "work",       entityId: "W009", action: "update", field: "status",   before: "planning",   after: "in_production", note: "" },
  { id: "L0003", ts: "2026-05-18 11:45:22", user: "S015", entity: "staff",      entityId: "S011", action: "update", field: "status",   before: "active",     after: "leave",         note: "育休開始" },
  { id: "L0004", ts: "2026-05-17 18:02:55", user: "S001", entity: "department", entityId: "D006", action: "create", field: "—",        before: "—",          after: "サウンド部",    note: "新規部署" },
  { id: "L0005", ts: "2026-05-17 16:21:30", user: "S014", entity: "work",       entityId: "W010", action: "create", field: "—",        before: "—",          after: "残響のセプテンバー", note: "" },
  { id: "L0006", ts: "2026-05-17 10:08:12", user: "S002", entity: "staff",      entityId: "S006", action: "update", field: "role",     before: "R009",       after: "R008",          note: "昇格" },
  { id: "L0007", ts: "2026-05-16 19:42:09", user: "S001", entity: "role",       entityId: "R019", action: "create", field: "—",        before: "—",          after: "ミキサー",      note: "" },
  { id: "L0008", ts: "2026-05-16 14:11:48", user: "S015", entity: "work",       entityId: "W008", action: "update", field: "status",   before: "in_production", after: "completed",  note: "" },
  { id: "L0009", ts: "2026-05-16 09:30:00", user: "S014", entity: "staff",      entityId: "S030", action: "update", field: "status",   before: "active",     after: "inactive",      note: "退職処理" },
  { id: "L0010", ts: "2026-05-15 17:55:32", user: "S001", entity: "staff",      entityId: "S027", action: "update", field: "email",    before: "kondou.m@..",after: "kondo.m@..",    note: "メール表記修正" },
  { id: "L0011", ts: "2026-05-15 15:12:08", user: "S002", entity: "work",       entityId: "W006", action: "update", field: "episodes", before: "10",         after: "12",            note: "話数変更" },
  { id: "L0012", ts: "2026-05-14 11:01:55", user: "S015", entity: "staff",      entityId: "S024", action: "create", field: "—",        before: "—",          after: "後藤 玲奈",     note: "新規スタッフ登録" },
];

// ============================================
// Clients — 取引先（作品クライアント）
// ============================================
const CLIENT_TYPES = {
  committee:  { label: "製作委員会",       tone: "info" },
  production: { label: "制作会社",         tone: "accent" },
  publisher:  { label: "出版社",           tone: "success" },
  streaming:  { label: "配信プラットフォーム", tone: "info" },
  advertiser: { label: "広告主",           tone: "warning" },
  label:      { label: "レーベル",         tone: "default" },
  other:      { label: "その他",           tone: "default" },
};

const CLIENT_STATUS = {
  active:   { label: "取引中", tone: "success" },
  inactive: { label: "停止",   tone: "default" },
};

const CLIENTS = [
  { id: "CL01", code: "TAS",  name: "東京アニメーションスタジオ", nameKana: "トウキョウアニメーションスタジオ", type: "production", contactPerson: "佐々木 慎也", contactEmail: "sasaki@tas.example.jp",   contactPhone: "03-3000-1010", status: "active",   createdAt: "2022-04-01", note: "主要取引先・継続案件多数" },
  { id: "CL02", code: "MF",   name: "メディア・ファクトリー",     nameKana: "メディアファクトリー",             type: "publisher",  contactPerson: "黒田 大輔",   contactEmail: "kuroda@mf.example.jp",      contactPhone: "03-3000-2020", status: "active",   createdAt: "2022-04-01", note: "原作出版" },
  { id: "CL03", code: "SP",   name: "サンライズパートナーズ",     nameKana: "サンライズパートナーズ",           type: "production", contactPerson: "山口 明菜",   contactEmail: "yamaguchi@sp.example.jp",   contactPhone: "03-3000-3030", status: "active",   createdAt: "2022-04-01", note: "" },
  { id: "CL04", code: "PFI",  name: "Pixel Forge Inc.",          nameKana: "ピクセルフォージ",                 type: "streaming",  contactPerson: "Alex Walker", contactEmail: "alex.w@pixelforge.example", contactPhone: "+1-310-555-0010", status: "active", createdAt: "2024-01-10", note: "海外・英語対応" },
  { id: "CL05", code: "NO",   name: "ナイトオウル",               nameKana: "ナイトオウル",                     type: "committee",  contactPerson: "三浦 真理",   contactEmail: "miura@nightowl.example.jp", contactPhone: "03-3000-4040", status: "active",   createdAt: "2024-04-01", note: "深夜枠製作委員会" },
  { id: "CL06", code: "MW",   name: "ミューズワークス",           nameKana: "ミューズワークス",                 type: "label",      contactPerson: "高田 紀子",   contactEmail: "takada@muse.example.jp",    contactPhone: "03-3000-5050", status: "active",   createdAt: "2023-09-01", note: "音楽レーベル" },
  { id: "CL07", code: "KIN",  name: "キヌガサ自動車",             nameKana: "キヌガサジドウシャ",               type: "advertiser", contactPerson: "藤村 浩二",   contactEmail: "fujimura@kinugasa.example.jp", contactPhone: "052-300-6060", status: "active", createdAt: "2024-01-15", note: "CM案件" },
  { id: "CL08", code: "SHS",  name: "シャイニーステージ",         nameKana: "シャイニーステージ",               type: "other",      contactPerson: "稲葉 怜",     contactEmail: "inaba@shinystage.example.jp", contactPhone: "03-3000-7070", status: "active", createdAt: "2024-08-01", note: "Vtuber事務所" },
  { id: "CL09", code: "ND",   name: "(非公開)",                   nameKana: "ヒコウカイ",                       type: "other",      contactPerson: "—",           contactEmail: "—",                          contactPhone: "—",            status: "active",   createdAt: "2024-09-01", note: "NDA案件・社内コード PRJ-X" },
  { id: "CL10", code: "KDS",  name: "講談ストリーム",             nameKana: "コウダンストリーム",               type: "streaming",  contactPerson: "西原 一誠",   contactEmail: "nishihara@kds.example.jp",  contactPhone: "03-3000-8080", status: "inactive", createdAt: "2023-06-01", note: "現在進行中の案件なし" },
];
const CATEGORIES = [
  { id: "C001", name: "プロダクション", description: "プロデューサー・制作進行ライン",       order: 1, createdAt: "2022-04-01" },
  { id: "C002", name: "演出",           description: "監督・話数演出・絵コンテ",             order: 2, createdAt: "2022-04-01" },
  { id: "C003", name: "アニメーション", description: "原画・動画・作画監督",                 order: 3, createdAt: "2022-04-01" },
  { id: "C004", name: "美術",           description: "背景美術・美術設定",                   order: 4, createdAt: "2022-04-01" },
  { id: "C005", name: "3DCG",           description: "モデリング・リギング・CGアニメーション", order: 5, createdAt: "2022-04-01" },
  { id: "C006", name: "撮影",           description: "撮影・コンポジット・色彩設計",         order: 6, createdAt: "2022-04-01" },
  { id: "C007", name: "サウンド",       description: "音響監督・MA・効果",                   order: 7, createdAt: "2022-04-01" },
  { id: "C008", name: "管理",           description: "経理・人事・総務・営業など管理業務",   order: 8, createdAt: "2022-04-01" },
];

// Quick lookup helpers
const _byId = (arr) => Object.fromEntries(arr.map(x => [x.id, x]));
const DEPT_BY_ID = _byId(DEPARTMENTS);
const ROLE_BY_ID = _byId(ROLES);
const STAFF_BY_ID = _byId(STAFF);
const WORK_BY_ID = _byId(WORKS);
const CLIENT_BY_ID = _byId(CLIENTS);

function avatarColor(id) {
  let h = 0;
  for (let i = 0; i < (id || "").length; i++) h = (h * 31 + id.charCodeAt(i)) >>> 0;
  return AVATAR_PALETTE[h % AVATAR_PALETTE.length];
}

function initialsFor(s) {
  if (!s) return "?";
  if (s.lastName) return (s.lastName[0] || "") + (s.firstName?.[0] || "");
  return s.name?.slice(0, 2) || "?";
}

function formatYen(n) {
  if (n == null) return "—";
  if (n >= 100000000) return (n / 100000000).toFixed(n % 100000000 === 0 ? 0 : 1) + "億";
  if (n >= 10000) return (n / 10000).toLocaleString() + "万";
  return n.toLocaleString();
}

Object.assign(window, {
  DEPARTMENTS, ROLES, STAFF, WORKS, AUDIT_LOG, CATEGORIES, ACCESS_USERS, USER_ROLES, USER_STATUS,
  CLIENTS, CLIENT_TYPES, CLIENT_STATUS,
  WORK_STATUS, STAFF_STATUS, EMPLOYMENT_TYPES,
  DEPT_BY_ID, ROLE_BY_ID, STAFF_BY_ID, WORK_BY_ID, CLIENT_BY_ID,
  avatarColor, initialsFor, formatYen,
});
