// scene_rubric.jsx — Rubric editor in product shell + callout

function SceneRubric() {
  const t = useTime();

  const criteria = [
    { name: 'Capability',    code: 'CAP', weight: 30, color: LC_PURPLE },
    { name: 'Engagement',    code: 'ENG', weight: 25, color: LC_BLUE },
    { name: 'Communication', code: 'COM', weight: 25, color: LC_GREEN },
    { name: 'Culture Add',   code: 'CUL', weight: 20, color: LC_ORANGE },
  ];

  const total = criteria.reduce((s, c, i) => {
    const ct = Easing.easeOutCubic(clamp((t - 1.5 - i * 0.3) / 0.9, 0, 1));
    return s + c.weight * ct;
  }, 0);
  const valid = total >= 99.5;

  return (
    <>
      <PSShell
        breadcrumb={['Select', 'TalentScreen', 'Screen', 'Video Interview', 'Rubrics', 'Edit']}
        title="Edit Rubric"
        eyebrow="MODIFY SCORING CRITERIA AND CONFIGURATION"
        icon="rubric"
      >

        {/* Submenu */}
        <div style={{ position: 'absolute', left: 104, top: 172, zIndex: 1 }}>
          <PSSubmenu active="Rubrics"/>
        </div>

        {/* Published notice banner */}
        <div style={{
          position: 'absolute',
          left: 340, top: 172,
          width: 1140, height: 54,
          background: '#FEF3C7',
          borderRadius: 10,
          border: `1px solid #FDE68A`,
          padding: '10px 18px',
          display: 'flex', alignItems: 'center', gap: 12,
          opacity: Easing.easeOutCubic(clamp((t - 0.2) / 0.6, 0, 1)),
        }}>
          <svg width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="#B45309" strokeWidth="2" strokeLinecap="round"><path d="M9 2L1 15h16zM9 7v4M9 13.5v0"/></svg>
          <div>
            <div style={{
              fontFamily: 'Gilroy, sans-serif', fontSize: 12, fontWeight: 700, color: '#92400E',
            }}>This rubric is published</div>
            <div style={{
              fontFamily: 'Gilroy, sans-serif', fontSize: 11, fontWeight: 500, color: '#92400E', opacity: 0.8,
            }}>Changes will update the published rubric. Active sessions won't be affected (they use a frozen snapshot).</div>
          </div>
        </div>

        {/* Rubric name card */}
        <div style={{
          position: 'absolute',
          left: 340, top: 250,
          width: 1140, height: 150,
          background: '#fff',
          borderRadius: 12,
          border: `1px solid ${LC_LINE}`,
          padding: '22px 28px',
          boxShadow: '0 1px 3px rgba(22,22,31,0.04)',
          opacity: Easing.easeOutCubic(clamp((t - 0.6) / 0.7, 0, 1)),
        }}>
          <div style={{
            fontFamily: 'Gilroy, sans-serif', fontSize: 11, fontWeight: 600,
            color: LC_INK_MUTED, letterSpacing: '0.12em',
            textTransform: 'uppercase', marginBottom: 8,
          }}>Rubric Name</div>
          <div style={{
            padding: '10px 14px',
            border: `1px solid ${LC_PURPLE}`,
            borderRadius: 8,
            fontFamily: 'Gilroy, sans-serif', fontSize: 16, fontWeight: 600,
            color: LC_INK,
            marginBottom: 12,
            maxWidth: 400,
          }}>Standard Marketing Criteria</div>
          <div style={{
            fontFamily: 'Gilroy, sans-serif', fontSize: 11, fontWeight: 600,
            color: LC_INK_MUTED, letterSpacing: '0.12em',
            textTransform: 'uppercase', marginBottom: 4,
          }}>Description</div>
          <div style={{
            fontFamily: 'Gilroy, sans-serif', fontSize: 13, fontWeight: 400,
            color: LC_INK_SOFT, lineHeight: 1.5,
            maxWidth: 900,
          }}>Assessment under this criterion helps identify candidates who combine practical marketing skills with proactive participation, creativity, and an orientation toward achieving measurable impact.</div>
        </div>

        {/* Scoring criteria card */}
        <div style={{
          position: 'absolute',
          left: 340, top: 420,
          width: 1140,
          background: '#fff',
          borderRadius: 12,
          border: `1px solid ${LC_LINE}`,
          padding: '22px 28px',
          boxShadow: '0 1px 3px rgba(22,22,31,0.04)',
          opacity: Easing.easeOutCubic(clamp((t - 1.0) / 0.7, 0, 1)),
        }}>
          <div style={{
            display: 'flex', alignItems: 'center', justifyContent: 'space-between',
            marginBottom: 16,
          }}>
            <div>
              <div style={{
                fontFamily: 'Gilroy, sans-serif', fontSize: 17, fontWeight: 700, color: LC_INK, letterSpacing: '-0.01em',
              }}>Scoring Criteria</div>
              <div style={{
                fontFamily: 'Gilroy, sans-serif', fontSize: 12, fontWeight: 400, color: LC_INK_SOFT, marginTop: 2,
              }}>Define the dimensions used to evaluate interview responses.</div>
            </div>
            <div style={{
              padding: '8px 14px',
              borderRadius: 8,
              background: LC_PURPLE,
              color: '#fff',
              fontFamily: 'Gilroy, sans-serif',
              fontSize: 12, fontWeight: 600,
              display: 'flex', alignItems: 'center', gap: 6,
            }}>+ Add Criterion</div>
          </div>

          {criteria.map((c, i) => {
            const cT = Easing.easeOutBack(clamp((t - 1.5 - i * 0.3) / 0.8, 0, 1));
            const weightT = Easing.easeOutCubic(clamp((t - 1.5 - i * 0.3) / 0.9, 0, 1));
            const displayWeight = Math.round(c.weight * weightT);
            return (
              <div key={i} style={{
                padding: '14px 18px',
                marginBottom: 8,
                background: '#FBFAFD',
                borderRadius: 10,
                border: `1px solid ${LC_LINE}`,
                opacity: clamp(cT, 0, 1),
                transform: `translateY(${(1 - clamp(cT, 0, 1)) * 14}px) scale(${0.97 + clamp(cT, 0, 1) * 0.03})`,
                display: 'grid',
                gridTemplateColumns: '34px 1fr 180px 120px',
                gap: 20,
                alignItems: 'center',
              }}>
                <div style={{
                  width: 28, height: 28, borderRadius: 14,
                  background: c.color + '22',
                  color: c.color,
                  fontFamily: 'Gilroy, sans-serif',
                  fontSize: 12, fontWeight: 700,
                  display: 'flex', alignItems: 'center', justifyContent: 'center',
                }}>{i + 1}</div>

                <div>
                  <div style={{
                    fontFamily: 'Gilroy, sans-serif', fontSize: 14, fontWeight: 600, color: LC_INK,
                  }}>{c.name}</div>
                  <div style={{
                    fontFamily: 'Gilroy, sans-serif', fontSize: 10, fontWeight: 600,
                    color: LC_INK_MUTED, letterSpacing: '0.12em', marginTop: 3,
                    textTransform: 'uppercase',
                  }}>CODE · {c.code}  ·  SCALE · {c.name.toUpperCase()}</div>
                </div>

                <div>
                  <div style={{
                    fontFamily: 'Gilroy, sans-serif', fontSize: 10, fontWeight: 600,
                    color: LC_INK_MUTED, letterSpacing: '0.12em',
                    textTransform: 'uppercase', marginBottom: 4,
                  }}>Weight</div>
                  <div style={{
                    height: 6, borderRadius: 3,
                    background: LC_LINE,
                    overflow: 'hidden',
                  }}>
                    <div style={{
                      height: '100%',
                      width: `${c.weight * weightT}%`,
                      background: c.color,
                      borderRadius: 3,
                    }}/>
                  </div>
                </div>

                <div style={{
                  fontFamily: 'Gilroy, sans-serif',
                  fontSize: 20, fontWeight: 700,
                  color: LC_INK,
                  textAlign: 'right',
                  fontVariantNumeric: 'tabular-nums',
                  letterSpacing: '-0.02em',
                }}>{displayWeight}<span style={{ fontSize: 13, fontWeight: 500, color: LC_INK_SOFT, marginLeft: 2 }}>%</span></div>
              </div>
            );
          })}

          {/* Total bar */}
          <div style={{
            marginTop: 10,
            padding: '14px 18px',
            borderRadius: 10,
            background: valid ? '#D1FAE5' : '#F6F5FA',
            border: `1px solid ${valid ? '#6EE7B7' : LC_LINE}`,
            display: 'flex', alignItems: 'center', gap: 16,
            transition: 'background 0.3s, border-color 0.3s',
          }}>
            <div style={{
              width: 28, height: 28, borderRadius: 14,
              background: valid ? LC_GREEN : LC_INK_MUTED,
              color: '#fff',
              display: 'flex', alignItems: 'center', justifyContent: 'center',
            }}>
              <svg width="14" height="14" viewBox="0 0 14 14" fill="none" stroke="currentColor" strokeWidth="2.4" strokeLinecap="round" strokeLinejoin="round">
                {valid ? <path d="M3 7.5l2.5 2.5L11 4"/> : <path d="M5 5l4 4M9 5l-4 4"/>}
              </svg>
            </div>
            <div style={{
              fontFamily: 'Gilroy, sans-serif', fontSize: 14, fontWeight: 700, color: LC_INK, letterSpacing: '-0.01em',
            }}>Total Weight</div>
            <div style={{ flex: 1 }}/>
            <div style={{
              fontFamily: 'Gilroy, sans-serif',
              fontSize: 28, fontWeight: 700,
              color: LC_INK,
              fontVariantNumeric: 'tabular-nums',
              letterSpacing: '-0.03em',
            }}>{Math.round(total)}<span style={{ fontSize: 16, fontWeight: 500, color: LC_INK_SOFT, marginLeft: 2 }}>%</span></div>
            {(() => {
              const chipT = Easing.easeOutBack(clamp((t - 4.5) / 0.6, 0, 1));
              return (
                <div style={{
                  padding: '6px 14px',
                  borderRadius: 14,
                  background: valid ? LC_GREEN : LC_INK_MUTED,
                  color: '#fff',
                  fontFamily: 'Gilroy, sans-serif',
                  fontSize: 11, fontWeight: 700,
                  letterSpacing: '0.06em',
                  display: 'flex', alignItems: 'center', gap: 6,
                  opacity: clamp(chipT, 0, 1),
                  transform: `scale(${0.8 + clamp(chipT, 0, 1) * 0.2})`,
                }}>
                  <svg width="11" height="11" viewBox="0 0 11 11" fill="none" stroke="#fff" strokeWidth="2.4" strokeLinecap="round" strokeLinejoin="round"><path d="M2 5.5l2.5 2.5L9 3"/></svg>
                  VALID
                </div>
              );
            })()}
          </div>

          {/* Action buttons */}
          <div style={{
            marginTop: 18,
            display: 'flex', gap: 10,
          }}>
            <div style={{
              padding: '10px 18px',
              borderRadius: 8,
              background: LC_PURPLE,
              color: '#fff',
              fontFamily: 'Gilroy, sans-serif',
              fontSize: 12, fontWeight: 600,
            }}>💾 Save Changes</div>
            <div style={{
              padding: '10px 18px',
              borderRadius: 8,
              border: `1px solid ${LC_LINE}`,
              color: LC_INK_SOFT,
              fontFamily: 'Gilroy, sans-serif',
              fontSize: 12, fontWeight: 600,
            }}>Edit Anchors</div>
            <div style={{
              padding: '10px 18px',
              borderRadius: 8,
              border: `1px solid ${LC_LINE}`,
              color: LC_INK_SOFT,
              fontFamily: 'Gilroy, sans-serif',
              fontSize: 12, fontWeight: 600,
            }}>✕ Cancel</div>
          </div>
        </div>

      </PSShell>

      {/* Callout: reviewer leaning in */}
      <PSCallout
        src="assets/callouts/callout3.png"
        side="left"
        heightPx={700}
        bubbleTop={260}
        appear={4.2}
        bubbleDelay={0.8}
        translateOut={200}
        bubble={{
          label: 'PEOPLE OPERATIONS · PRIYA',
          text: '"Fair, weighted, and auditable. Our hiring managers finally trust the scores."',
          meta: 'DEI Lead · Fintech',
        }}
      />

      {/* Cursor gesture: hovering Save Changes */}
      <LCCursor path={[
        { t: 5.2, x: 800, y: 960 },
        { t: 6.0, x: 420, y: 950 },
        { t: 6.6, x: 420, y: 950, click: true },
      ]}/>
    </>
  );
}

Object.assign(window, { SceneRubric });
