// SubCalculators.jsx — full working sub-calculators for all 4 secondary tabs
// Uses DS components; exports to window.

const { SectionTitle, Slider, CurrencyInput, PresetChips, Button, Card, StatCard, Badge } =
  window.HappyRetirementDesignSystem_d542ec;
const fmt = window.fmtTH;

// ─── helpers ───────────────────────────────────────────────────────────────
function Field({ label, note, value, onChange, unit, step = 1000, presets }) {
  return (
    <div style={{ marginBottom: 18 }}>
      <div style={{ fontSize: 14, fontWeight: 400, color: "var(--text-body)", marginBottom: 8 }}>{label}</div>
      {note && <div style={{ fontSize: 11, color: "var(--text-muted)", marginBottom: 6 }}>{note}</div>}
      <CurrencyInput value={value} onChange={onChange} />
      {presets && (
        <div style={{ marginTop: 8 }}>
          <PresetChips options={presets} value={value} format={fmt} onChange={onChange} />
        </div>
      )}
    </div>
  );
}

function ResultRow({ label, value, color }) {
  return (
    <div style={{ display: "flex", justifyContent: "space-between", padding: "7px 0", borderBottom: "1px solid var(--border-default)", fontSize: 13 }}>
      <span style={{ color: "var(--text-muted)" }}>{label}</span>
      <span style={{ fontFamily: "var(--font-display)", fontWeight: 400, color: color || "var(--text-brand)" }}>{value}</span>
    </div>
  );
}

// ─── 1. IncomeCalculator ──────────────────────────────────────────────────
function IncomeCalc({ data, onChange, onSave, onBack }) {
  const { salary = 45000, compensation = 0, bonusMonths = 0, other = 0 } = data;
  const si = (k, v) => onChange({ ...data, [k]: v });
  const bonusMonthly = (salary * bonusMonths) / 12;
  const total = salary + compensation + bonusMonthly + other;
  return (
    <div>
      <div style={{ display: "flex", alignItems: "center", gap: 12, marginBottom: 24 }}>
        <Button variant="secondary" size="sm" onClick={onBack}>← กลับ</Button>
        <SectionTitle style={{ margin: 0 }}>💰 กรอกข้อมูลรายได้</SectionTitle>
      </div>
      <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 16 }}>
        <div>
          <Field label="เงินเดือน" note="ก่อนหักภาษี" value={salary} onChange={(v) => si("salary", v)}
            presets={[15000, 25000, 45000, 70000, 100000]} />
          <Field label="ค่าตอบแทน / OT" value={compensation} onChange={(v) => si("compensation", v)}
            presets={[0, 2000, 5000, 10000]} />
          <Field label="รายได้อื่นๆ (ฟรีแลนซ์ ฯลฯ)" value={other} onChange={(v) => si("other", v)}
            presets={[0, 5000, 10000, 20000]} />
        </div>
        <div>
          <div style={{ marginBottom: 18 }}>
            <div style={{ fontSize: 14, fontWeight: 400, color: "var(--text-body)", marginBottom: 8 }}>🎁 โบนัส (เดือน/ปี)</div>
            <Slider label="" value={bonusMonths} min={0} max={12} step={0.5} unit="เดือน"
              format={(v) => v} onChange={(v) => si("bonusMonths", v)} />
            {bonusMonths > 0 && <div style={{ fontSize: 12, color: "var(--text-muted)", marginTop: 4 }}>= เฉลี่ย ฿{fmt(Math.round(bonusMonthly))}/เดือน</div>}
          </div>
          <Card emphasis>
            <div style={{ textAlign: "center" }}>
              <div className="hr-stat__label" style={{ marginBottom: 6 }}>💰 รวมรายได้</div>
              <div style={{ fontFamily: "var(--font-display)", fontSize: 28, fontWeight: 400, color: "var(--text-brand)" }}>
                ฿{fmt(Math.round(total))}<span style={{ fontSize: 13, color: "var(--text-muted)" }}>/เดือน</span>
              </div>
            </div>
          </Card>
        </div>
      </div>
      <Button block size="lg" icon="✅" onClick={() => onSave(Math.round(total), Math.round(salary))} style={{ marginTop: 20 }}>
        ใช้รายได้รวม ฿{fmt(Math.round(total))}
      </Button>
    </div>
  );
}

// ─── 2. PVDCalculator ────────────────────────────────────────────────────
function PVDCalc({ data, onChange, onSave, onBack }) {
  const { salary = 45000, empRate = 5, compRate = 5, empBalance = 0, compBalance = 0, returnRate = 4, yearsLeft = 30 } = data;
  const sp = (k, v) => onChange({ ...data, [k]: v });
  const me = salary * empRate / 100;
  const mc = salary * compRate / 100;
  const r = returnRate / 100;
  const mn = yearsLeft * 12;
  const mr = r / 12;
  const fvE = empBalance * Math.pow(1 + r, yearsLeft) + (mr > 0 ? me * ((Math.pow(1 + mr, mn) - 1) / mr) : me * mn);
  const fvC = compBalance * Math.pow(1 + r, yearsLeft) + (mr > 0 ? mc * ((Math.pow(1 + mr, mn) - 1) / mr) : mc * mn);
  const total = Math.round(fvE + fvC);
  return (
    <div>
      <div style={{ display: "flex", alignItems: "center", gap: 12, marginBottom: 24 }}>
        <Button variant="secondary" size="sm" onClick={onBack}>← กลับ</Button>
        <SectionTitle style={{ margin: 0 }}>🏦 กองทุนสำรองเลี้ยงชีพ (PVD)</SectionTitle>
      </div>
      <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 20 }}>
        <div>
          <Field label="เงินเดือน" value={salary} onChange={(v) => sp("salary", v)}
            presets={[25000, 45000, 70000, 100000]} />
          <Field label="ยอดสะสมพนักงาน (ปัจจุบัน)" value={empBalance} onChange={(v) => sp("empBalance", v)}
            presets={[0, 50000, 200000, 500000]} />
          <Field label="ยอดสะสมนายจ้าง (ปัจจุบัน)" value={compBalance} onChange={(v) => sp("compBalance", v)}
            presets={[0, 50000, 200000, 500000]} />
        </div>
        <div>
          <Slider label={`อัตราพนักงาน (${empRate}%)`} value={empRate} min={2} max={15}
            unit="%" onChange={(v) => sp("empRate", v)} />
          <div style={{ marginBottom: 16 }}></div>
          <Slider label={`อัตรานายจ้าง (${compRate}%)`} value={compRate} min={2} max={15}
            unit="%" onChange={(v) => sp("compRate", v)} />
          <div style={{ marginBottom: 16 }}></div>
          <Slider label={`ผลตอบแทนกองทุน (${returnRate}%)`} value={returnRate} min={1} max={15} step={0.5}
            unit="%" onChange={(v) => sp("returnRate", v)} />
          <div style={{ marginBottom: 16 }}></div>
          <Slider label={`ปีที่เหลือก่อนเกษียณ (${yearsLeft} ปี)`} value={yearsLeft} min={1} max={40}
            unit="ปี" onChange={(v) => sp("yearsLeft", Math.round(v))} />
        </div>
      </div>
      <Card accent="var(--gold-600)" style={{ marginTop: 20, background: "rgba(192,146,42,0.06)" }}>
        <ResultRow label="ส่วนสะสมพนักงาน (FV)" value={`฿${fmt(Math.round(fvE))}`} />
        <ResultRow label="ส่วนสะสมนายจ้าง (FV)" value={`฿${fmt(Math.round(fvC))}`} />
        <div style={{ display: "flex", justifyContent: "space-between", padding: "10px 0 4px", fontSize: 14 }}>
          <span style={{ fontWeight: 400 }}>💰 มูลค่ากองทุน ณ เกษียณ</span>
          <span style={{ fontFamily: "var(--font-display)", fontWeight: 400, fontSize: 22, color: "var(--gold-600)" }}>฿{fmt(total)}</span>
        </div>
      </Card>
      <Button block size="lg" icon="✅" onClick={() => onSave(total)} style={{ marginTop: 16 }}>
        ใช้มูลค่า ฿{fmt(total)} ในแผน
      </Button>
    </div>
  );
}

// ─── 3. SSOCalculator ────────────────────────────────────────────────────
function SSOCalc({ data, onChange, onSave, onBack }) {
  const { salary = 15000, yearsContrib = 15 } = data;
  const sp = (k, v) => onChange({ ...data, [k]: v });
  const cappedSalary = Math.min(salary, 15000);
  const eligible = yearsContrib >= 15;
  const basePension = eligible ? cappedSalary * 0.20 : 0;
  const extraYears = Math.max(0, yearsContrib - 15);
  const pension = eligible ? Math.min(Math.round(basePension + cappedSalary * 0.015 * extraYears), 7500) : 0;
  const lumpsum = !eligible ? Math.round(yearsContrib * 12 * cappedSalary * 0.05) : 0;
  return (
    <div>
      <div style={{ display: "flex", alignItems: "center", gap: 12, marginBottom: 24 }}>
        <Button variant="secondary" size="sm" onClick={onBack}>← กลับ</Button>
        <SectionTitle style={{ margin: 0 }}>🛡️ ประกันสังคม ชราภาพ</SectionTitle>
      </div>
      <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 20 }}>
        <div>
          <Field label="เงินเดือน (ใช้คำนวณ ประกันสังคมอิงฐาน ≤ ฿15,000)"
            value={salary} onChange={(v) => sp("salary", v)}
            presets={[8000, 10000, 15000, 20000]} unit="บาท" />
          <div style={{ fontSize: 12, color: "var(--text-muted)", marginTop: -10, marginBottom: 12 }}>
            ฐานคำนวณจริง: ฿{fmt(cappedSalary)}/เดือน (ไม่เกิน 15,000)
          </div>
          <Slider label={`ปีที่ส่งสมทบ`} value={yearsContrib} min={1} max={40}
            unit="ปี" onChange={(v) => sp("yearsContrib", Math.round(v))} />
        </div>
        <div>
          <Card accent={eligible ? "var(--color-success)" : "var(--color-warning)"}
            style={{ background: eligible ? "rgba(46,125,82,0.06)" : "rgba(192,146,42,0.06)" }}>
            <div style={{ marginBottom: 12 }}>
              {eligible
                ? <Badge variant="success" icon="✅">ได้รับบำนาญ (ส่งครบ 15 ปี)</Badge>
                : <Badge variant="warning" icon="⚠️">ยังไม่ถึง 15 ปี — ได้เงินก้อนคืน</Badge>}
            </div>
            {eligible ? (
              <>
                <ResultRow label="20% ของฐานเงินเดือน" value={`฿${fmt(Math.round(basePension))}`} />
                {extraYears > 0 && <ResultRow label={`+1.5% × ${extraYears} ปีเกิน`} value={`฿${fmt(Math.round(cappedSalary * 0.015 * extraYears))}`} />}
                <div style={{ display: "flex", justifyContent: "space-between", padding: "10px 0 4px", fontSize: 14 }}>
                  <span style={{ fontWeight: 400 }}>🏦 บำนาญ/เดือน</span>
                  <span style={{ fontFamily: "var(--font-display)", fontWeight: 400, fontSize: 22, color: "var(--color-success)" }}>฿{fmt(pension)}</span>
                </div>
              </>
            ) : (
              <>
                <ResultRow label="เงินชดเชยคืนก้อน (ประมาณ)" value={`฿${fmt(lumpsum)}`} />
                <div style={{ fontSize: 12, color: "var(--text-muted)", marginTop: 8 }}>ต้องส่งสมทบอีก {15 - yearsContrib} ปีจึงจะได้บำนาญ</div>
              </>
            )}
          </Card>
        </div>
      </div>
      <Button block size="lg" icon="✅" onClick={() => onSave(pension)} style={{ marginTop: 16 }}
        disabled={!eligible}>
        {eligible ? `ใช้บำนาญ ฿${fmt(pension)}/เดือน` : "ยังไม่ได้รับบำนาญ"}
      </Button>
    </div>
  );
}

// ─── 4. SeveranceCalculator ──────────────────────────────────────────────
function SeveranceCalc({ data, onChange, onSave, onBack }) {
  const { lastSalary = 45000, yearsWorked = 10 } = data;
  const sp = (k, v) => onChange({ ...data, [k]: v });
  const getSeveranceDays = (y) => {
    if (y < 0.33) return 0;
    if (y < 1)   return 30;
    if (y < 3)   return 90;
    if (y < 6)   return 180;
    if (y < 10)  return 240;
    if (y < 20)  return 300;
    return 400;
  };
  const days = getSeveranceDays(yearsWorked);
  const gross = Math.round((lastSalary / 30) * days);
  // Progressive severance tax per Thai Revenue Code
  const calcTax = (inc) => {
    const brackets = [[150000,0],[150000,0.05],[200000,0.10],[250000,0.15],[250000,0.20],[1000000,0.25],[3000000,0.30],[Infinity,0.35]];
    let tax = 0, rem = inc;
    for (const [lim, rate] of brackets) { if (rem <= 0) break; tax += Math.min(rem, lim) * rate; rem -= lim; }
    return tax;
  };
  const exempt = Math.min(gross, 600000);
  const d1 = 7000 * yearsWorked;
  const d2 = Math.max(0, gross - exempt - d1) * 0.5;
  const taxable = Math.max(0, gross - exempt - d1 - d2);
  const net = Math.round(gross - calcTax(taxable));
  return (
    <div>
      <div style={{ display: "flex", alignItems: "center", gap: 12, marginBottom: 24 }}>
        <Button variant="secondary" size="sm" onClick={onBack}>← กลับ</Button>
        <SectionTitle style={{ margin: 0 }}>💼 เงินชดเชย (พ.ร.บ. คุ้มครองแรงงาน)</SectionTitle>
      </div>
      <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 20 }}>
        <div>
          <Field label="เงินเดือนสุดท้าย" value={lastSalary} onChange={(v) => sp("lastSalary", v)}
            presets={[25000, 45000, 70000, 100000]} />
          <Slider label={`อายุงาน`} value={yearsWorked} min={0} max={40}
            unit="ปี" onChange={(v) => sp("yearsWorked", v)} />
        </div>
        <div>
          <Card accent="var(--clay-600)" style={{ background: "rgba(192,114,42,0.06)" }}>
            <ResultRow label="อายุงาน" value={`${yearsWorked} ปี`} color="var(--text-body)" />
            <ResultRow label="วันชดเชยตามกฎหมาย" value={`${days} วัน`} />
            <ResultRow label="ก่อนหักภาษี" value={`฿${fmt(gross)}`} />
            <div style={{ display: "flex", justifyContent: "space-between", padding: "10px 0 4px", fontSize: 14 }}>
              <span style={{ fontWeight: 400 }}>💼 หลังหักภาษี (ประมาณ)</span>
              <span style={{ fontFamily: "var(--font-display)", fontWeight: 400, fontSize: 22, color: "var(--clay-600)" }}>฿{fmt(net)}</span>
            </div>
          </Card>
          <div style={{ fontSize: 11, color: "var(--text-muted)", marginTop: 8, lineHeight: 1.6 }}>
            * หักภาษีโดยประมาณ 25% — ค่าจริงขึ้นกับรายได้สะสมและการยื่น 401(k)
          </div>
        </div>
      </div>
      <Button block size="lg" icon="✅" onClick={() => onSave(net)} style={{ marginTop: 16 }}
        disabled={days === 0}>
        ใช้เงินชดเชย ฿{fmt(net)}
      </Button>
    </div>
  );
}

// ─── 5. AssetsCalculator ─────────────────────────────────────────────────
const ASSET_TYPES = [
  { key: "rmf",   retKey: "rmfRet",    defRet: 5,  label: "กองทุน RMF",              emoji: "🏦", sliderColor: "#2980b9", badge: "ลดหย่อนภาษีได้",      badgeColor: "#2a9d8f" },
  { key: "esg",   retKey: "esgRet",    defRet: 5,  label: "กองทุน ESG",              emoji: "🌱", sliderColor: "#27ae60", badge: "ลดหย่อนภาษีได้",      badgeColor: "#27ae60" },
  { key: "ssf",   retKey: "ssfRet",    defRet: 5,  label: "กองทุน SSF",              emoji: "🛡️", sliderColor: "#8e44ad", badge: "ลดหย่อนภาษีได้",      badgeColor: "#8e44ad" },
  { key: "stocks",retKey: "stocksRet", defRet: 7,  label: "หุ้น",                    emoji: "📊", sliderColor: "#c0392b", badge: "ความเสี่ยงสูง",         badgeColor: "#c0392b" },
  { key: "gold",  retKey: "goldRet",   defRet: 5,  label: "ทองคำ",                   emoji: "🥇", sliderColor: "#c0922a", badge: "ความเสี่ยงปานกลาง",    badgeColor: "#c0922a" },
  { key: "crypto",retKey: "cryptoRet", defRet: 10, label: "คริปโตเคอร์เรนซี",         emoji: "₿",  sliderColor: "#e67e22", badge: "ความเสี่ยงสูงมาก",      badgeColor: "#e67e22" },
  { key: "other", retKey: "otherRet",  defRet: 3,  label: "อสังหาริมทรัพย์ / อื่นๆ", emoji: "🏠", sliderColor: "#7f8c8d", badge: "ความเสี่ยงต่ำ",          badgeColor: "#7f8c8d" },
];

function AssetCard({ item, data, onChange, yearsLeft }) {
  const val  = data[item.key]  || 0;
  const ret  = data[item.retKey] !== undefined ? data[item.retKey] : item.defRet;
  const fv   = val > 0 ? Math.round(val * Math.pow(1 + ret / 100, yearsLeft)) : 0;
  const pct  = (ret / 50) * 100;
  const [editing, setEditing] = React.useState(false);
  const [raw, setRaw] = React.useState("");
  const fmt = window.fmtTH;

  return (
    <div style={{ background: "var(--surface-card)", border: "1.5px solid var(--border-default)", borderRadius: "var(--radius-lg)", padding: "16px 18px", marginBottom: 12 }}>
      {/* Header */}
      <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: 14 }}>
        <div style={{ display: "flex", alignItems: "center", gap: 8 }}>
          <span style={{ fontSize: 20 }}>{item.emoji}</span>
          <span style={{ fontFamily: "var(--font-display)", fontWeight: 400, fontSize: 15, color: "var(--text-heading)" }}>{item.label}</span>
        </div>
        <span style={{ fontSize: 11, fontWeight: 400, padding: "3px 10px", borderRadius: "var(--radius-pill)", border: `1.5px solid ${item.badgeColor}`, color: item.badgeColor, background: `${item.badgeColor}15` }}>
          {item.badge}
        </span>
      </div>

      {/* Two-col body */}
      <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 16, alignItems: "start" }}>
        {/* Left: current value input */}
        <div>
          <div style={{ fontSize: 11, color: "var(--text-muted)", fontWeight: 400, marginBottom: 8 }}>มูลค่าปัจจุบัน</div>
          <div style={{ background: "var(--surface-sunken)", border: `1.5px solid ${val > 0 ? item.sliderColor + "80" : "var(--border-default)"}`, borderRadius: "var(--radius-md)", padding: "9px 12px", display: "flex", alignItems: "center", gap: 6 }}>
            <span style={{ fontSize: 14, color: "var(--text-brand)", fontFamily: "var(--font-display)" }}>฿</span>
            <input
              type="text" inputMode="numeric" placeholder="0"
              value={editing ? raw : (val > 0 ? fmt(val) : "")}
              onFocus={() => { setEditing(true); setRaw(val > 0 ? String(val) : ""); }}
              onChange={e => setRaw(e.target.value.replace(/[^0-9]/g, ""))}
              onBlur={() => { setEditing(false); const n = parseInt(raw || "0", 10); onChange({ ...data, [item.key]: n }); }}
              onKeyDown={e => { if (e.key === "Enter") e.target.blur(); }}
              style={{ flex: 1, background: "transparent", border: "none", outline: "none", fontFamily: "var(--font-display)", fontSize: 16, color: "var(--text-brand)", textAlign: "right" }}
            />
            <span style={{ fontSize: 11, color: "var(--text-muted)" }}>฿</span>
          </div>
        </div>

        {/* Right: return rate slider */}
        <div>
          <div style={{ fontSize: 11, color: "var(--text-muted)", fontWeight: 400, marginBottom: 8 }}>ผลตอบแทน/ปี</div>
          <div style={{ display: "flex", alignItems: "center", gap: 10 }}>
            <div style={{ flex: 1, position: "relative", height: 36, display: "flex", alignItems: "center" }}>
              <div style={{ position: "absolute", left: 0, right: 0, height: 4, borderRadius: 2, background: "var(--surface-sunken)" }}>
                <div style={{ width: `${Math.min(pct, 100)}%`, height: "100%", borderRadius: 2, background: item.sliderColor, transition: "width 0.1s" }} />
              </div>
              <input type="range" min={0} max={50} step={0.5} value={ret}
                onChange={e => onChange({ ...data, [item.retKey]: parseFloat(e.target.value) })}
                style={{ position: "absolute", width: "100%", height: 36, WebkitAppearance: "none", appearance: "none", background: "transparent", outline: "none", cursor: "pointer", margin: 0, padding: 0, "--thumb-color": item.sliderColor }}
              />
              <style>{`input[type=range]::-webkit-slider-thumb{-webkit-appearance:none;width:20px;height:20px;border-radius:50%;background:${item.sliderColor};border:3px solid var(--surface-card);box-shadow:0 2px 6px rgba(0,0,0,0.15);cursor:pointer;}`}</style>
            </div>
            <div style={{ minWidth: 52, background: "var(--surface-sunken)", border: `1.5px solid ${item.sliderColor}60`, borderRadius: "var(--radius-sm)", padding: "6px 8px", textAlign: "center", fontFamily: "var(--font-display)", fontSize: 13, fontWeight: 400, color: item.sliderColor }}>
              {ret.toFixed(1)}%
            </div>
          </div>
        </div>
      </div>
    </div>
  );
}

function AssetsCalc({ data, onChange, onSave, onBack, yearsLeft = 30 }) {
  const fmt = window.fmtTH;
  const totalCurrent = ASSET_TYPES.reduce((s, item) => s + (data[item.key] || 0), 0);
  const totalFV = ASSET_TYPES.reduce((s, item) => {
    const val = data[item.key] || 0;
    const ret = data[item.retKey] !== undefined ? data[item.retKey] : item.defRet;
    return s + (val > 0 ? Math.round(val * Math.pow(1 + ret / 100, yearsLeft)) : 0);
  }, 0);

  return (
    <div>
      <div style={{ display: "flex", alignItems: "center", gap: 12, marginBottom: 24 }}>
        <Button variant="secondary" size="sm" onClick={onBack}>← กลับ</Button>
        <SectionTitle style={{ margin: 0 }}>📊 สินทรัพย์และการลงทุน</SectionTitle>
      </div>

      {ASSET_TYPES.map(item => (
        <AssetCard key={item.key} item={item} data={data} onChange={onChange} yearsLeft={yearsLeft} />
      ))}

      {/* Summary */}
      <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 12, marginTop: 8 }}>
        <Card flat style={{ textAlign: "center", background: "var(--surface-inset)" }}>
          <div style={{ fontSize: 12, color: "var(--text-muted)", marginBottom: 8 }}>มูลค่าปัจจุบัน</div>
          <div style={{ fontFamily: "var(--font-display)", fontSize: 26, color: "var(--text-heading)" }}>
            ฿{fmt(totalCurrent)}
          </div>
        </Card>
        <Card flat style={{ textAlign: "center", background: "var(--surface-inset)", border: "1.5px solid var(--blue-600)" }}>
          <div style={{ fontSize: 12, color: "var(--text-muted)", marginBottom: 8 }}>มูลค่าเมื่อเกษียณ (FV)</div>
          <div style={{ fontFamily: "var(--font-display)", fontSize: 26, color: "var(--blue-600)" }}>
            ฿{fmt(totalFV)}
          </div>
        </Card>
      </div>

      <Button block size="lg" icon="✅" onClick={() => onSave(totalFV)} style={{ marginTop: 14 }}
        disabled={totalFV === 0}>
        ใช้มูลค่าเมื่อเกษียณ ฿{fmt(totalFV)}
      </Button>
    </div>
  );
}

window.IncomeCalc     = IncomeCalc;
window.PVDCalc        = PVDCalc;
window.SSOCalc        = SSOCalc;
window.SeveranceCalc  = SeveranceCalc;
window.AssetsCalc     = AssetsCalc;
