import { formatNumber } from "../utils/format.js";

export const projects = [
  { id: "qz-a2", name: "泉州市百崎通道 A2 合同段", section: "A2 合同段", scale: 1 },
  { id: "bridge-demo", name: "跨江大桥示范段", section: "示范段", scale: 0.82 },
  { id: "road-demo", name: "市政道路提升工程", section: "一期", scale: 0.64 },
];

export const measurementPeriods = ["2025-10", "2025-11", "2025-12", "2026-01"];

export function getDecomposeRows(structureIndex, projectScale = 1) {
  return Array.from({ length: 12 }, (_, i) => {
    const baseQty = (109.26 + i * 19.8 + structureIndex * 2.6) * projectScale;
    const changedQty = baseQty * (i % 3 === 0 ? 1.08 : i % 3 === 1 ? 0.96 : 1.0);
    const measuredQty = changedQty * (0.25 + (i % 5) * 0.15);
    const doneQty = changedQty * (0.18 + (i % 4) * 0.2);
    return {
      code: `BOQ-${String(1001 + i)}`,
      name: ["混凝土浇筑", "钢筋制安", "模板工程", "土方开挖", "路基填筑", "防水层"][i % 6],
      unit: ["m³", "t", "㎡", "m³", "m³", "㎡"][i % 6],
      decomposeQty: baseQty,
      changedQty,
      measuredQty,
      measureRate: changedQty > 0 ? measuredQty / changedQty : 0,
      doneQty,
      doneRate: changedQty > 0 ? doneQty / changedQty : 0,
    };
  });
}

export function getMaterialRows(structureIndex, projectScale = 1) {
  return [
    { code: "MAT-01", name: "钢筋", unit: "t", qty: formatNumber((12.3 + structureIndex * 0.6) * projectScale, 1) },
    { code: "MAT-02", name: "水泥", unit: "t", qty: formatNumber((80 + structureIndex * 1.8) * projectScale, 1) },
    { code: "MAT-03", name: "碎石", unit: "t", qty: formatNumber((320 + structureIndex * 2.5) * projectScale, 1) },
  ];
}

export function getPayRows(period, structureIndex, structureName) {
  return Array.from({ length: 16 }, (_, i) => {
    const unitPrice = 520 + i * 28;
    const prevQty = (8 + i * 1.5 + structureIndex * 0.3) * (i % 3 === 0 ? 0.9 : 1.05);
    const curQty = 2.4 + (i % 5) * 0.9 + structureIndex * 0.1;
    const curAmt = curQty * unitPrice;
    const cumQty = prevQty + curQty;
    return {
      no: i + 1,
      period,
      code: `BOQ-${String(3001 + i)}`,
      name: `${["混凝土浇筑", "钢筋制安", "模板工程", "土方开挖", "路基填筑", "防水层"][i % 6]}（${structureName}）`,
      unit: ["m³", "t", "㎡", "m³", "m³", "㎡"][i % 6],
      unitPrice,
      prevQty,
      curQty,
      curAmt,
      cumQty,
    };
  });
}
