// Publication Dapp — on-chain publishing, peer review queue, royalty splits.

function PublicationDapp() {
  const sidebar = (
    <>
      <div style={{ padding: '0 16px 12px', borderBottom: `1px solid ${UB.rule2}`, marginBottom: 14 }}>
        <div style={{ fontFamily: UB.mono, fontSize: 9, letterSpacing: '0.18em', color: UB.ink3, marginBottom: 4 }}>JOURNAL</div>
        <div style={{ fontWeight: 600, fontSize: 13 }}>Open J. Neuroscience</div>
        <div style={{ fontFamily: UB.mono, fontSize: 10, color: UB.ink3 }}>OJN · IF 6.42 · 482 papers</div>
      </div>
      <NavGroup label="Editorial">
        <NavItem icon={Icon.doc} label="Submissions" badge="38" active />
        <NavItem icon={Icon.flask} label="In review" badge="22" />
        <NavItem icon={Icon.check} label="Accepted" badge="14" />
        <NavItem icon={Icon.book} label="Published" />
        <NavItem icon={Icon.shield} label="Retractions" badge="2" />
      </NavGroup>
      <NavGroup label="Reviewers">
        <NavItem icon={Icon.user} label="Roster" />
        <NavItem icon={Icon.cube} label="Bounties" />
      </NavGroup>
      <NavGroup label="Revenue">
        <NavItem icon={Icon.bank} label="Royalty splits" />
        <NavItem icon={Icon.cpu} label="LLM access" />
        <NavItem icon={Icon.storage} label="Data access" />
      </NavGroup>
    </>
  );

  return (
    <Dapp>
      <ChromeBar dapp="PUBLICATION" code="OJN·EDITOR" />
      <Layout rail={sidebar}>
        <PageHead
          eyebrow="Editor dashboard · Open J. Neuroscience"
          title="Submissions queue"
          sub="38 manuscripts · auto-matched to reviewers via TRID. Royalties are split on-chain at acceptance."
          actions={<>
            <Btn small icon={Icon.search}>Filter</Btn>
            <Btn small primary>Issue dPID</Btn>
          </>}
        />

        <div style={{ flex: 1, padding: 24, overflow: 'auto', display: 'grid', gridTemplateColumns: '1.5fr 1fr', gap: 16 }}>
          {/* Submissions table */}
          <Card title="Manuscript queue" code="SORTED · NOVELTY × URGENCY" pad={false}>
            <Row head cells={[
              { v: 'dPID', w: '90px' }, { v: 'Title' },
              { v: 'Auth.', w: '50px' }, { v: 'Stage', w: '90px' },
              { v: 'Bounty', w: '70px' }, { v: 'Days', w: '40px' },
            ]} />
            {[
              ['dpid:042901', 'Astrocyte Ca²⁺ waves modulate cortical sleep states', 4, 'PEER REVIEW', '480', 6, 'info'],
              ['dpid:042898', 'A graph-neural model of hippocampal replay', 3, 'AUTHOR REV.', '320', 2, 'warn'],
              ['dpid:042893', 'Reproduction: Lin et al. 2023 — astrocyte gating', 2, 'PUBLISHED', '150', 0, 'ok'],
              ['dpid:042889', 'Single-cell atlas · murine V1 layer 5', 6, 'PEER REVIEW', '600', 9, 'info'],
              ['dpid:042884', 'Closed-loop optogenetics for stress-resilient circuits', 5, 'COPY EDIT', '280', 1, 'accent'],
              ['dpid:042881', 'Negative result — failure to reproduce Park 2022', 1, 'PEER REVIEW', '420', 11, 'info'],
              ['dpid:042875', 'Methods — robust spike sorting in low-SNR regimes', 3, 'PRE-PRINT', '180', 14, 'default'],
              ['dpid:042871', 'A Bayesian framework for cross-species comparison', 2, 'DECISION', '360', 18, 'warn'],
            ].map((r, i) => (
              <Row key={i} cells={[
                { v: r[0], style: { color: UB.ink3 }, w: '90px' },
                { v: <span style={{ color: UB.ink, fontFamily: UB.sans, fontSize: 12, fontWeight: 500 }}>{r[1]}</span> },
                { v: r[2], w: '50px' },
                { v: <Tag tone={r[6]}>{r[3]}</Tag>, w: '90px' },
                { v: <span style={{ color: UB.ink }}>{r[4]}</span>, w: '70px', style: { textAlign: 'right' } },
                { v: r[5] === 0 ? '—' : `${r[5]}d`, w: '40px', style: { color: r[5] > 10 ? UB.bad : UB.ink3, textAlign: 'right' } },
              ]} />
            ))}
          </Card>

          {/* Right rail */}
          <div style={{ display: 'flex', flexDirection: 'column', gap: 16 }}>
            <Card title="Selected · dpid:042901" action={<Btn small primary>Open</Btn>}>
              <div style={{ fontFamily: UB.serif, fontSize: 20, lineHeight: 1.15, marginBottom: 8 }}>Astrocyte Ca²⁺ waves modulate cortical sleep states</div>
              <div style={{ fontSize: 11, color: UB.ink3, marginBottom: 10 }}>Park, J., Mwangi, A., Tanaka, R., et al. · submitted 6 days ago</div>
              <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 10, marginBottom: 12 }}>
                <Stat label="Novelty" value="0.81" sub="CD index" />
                <Stat label="Reviewers" value="3 / 3" sub="auto-matched" />
                <Stat label="Bounty" value="480" sub="UBR pool" />
                <Stat label="Repro pool" value="48" sub="auto-funded" />
              </div>
              <div style={{ fontFamily: UB.mono, fontSize: 9, letterSpacing: '0.18em', color: UB.ink3, marginBottom: 6 }}>REVIEWER QUEUE</div>
              {[
                ['anon-7f3a', 'TIS 78 · neuro · 12 prior reviews', 'COMMITTED'],
                ['anon-c019', 'TIS 82 · ml · 8 prior reviews', 'IN PROGRESS'],
                ['m.harriot', 'TIS 86 · open name · 41 prior', 'INVITED'],
              ].map((r, i) => (
                <div key={i} style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', padding: '6px 0', borderBottom: i < 2 ? `1px solid ${UB.rule3}` : 'none' }}>
                  <div>
                    <div style={{ fontFamily: UB.mono, fontSize: 11 }}>{r[0]}</div>
                    <div style={{ fontSize: 10, color: UB.ink3 }}>{r[1]}</div>
                  </div>
                  <Tag tone={i === 0 ? 'ok' : i === 1 ? 'accent' : 'warn'}>{r[2]}</Tag>
                </div>
              ))}
            </Card>

            <Card title="Royalty smart contract" code="dpid:042901">
              <div style={{ fontFamily: UB.mono, fontSize: 10, color: UB.ink3, marginBottom: 8, letterSpacing: '0.1em' }}>AUTO-DISTRIBUTED ON ACCEPTANCE</div>
              {[
                ['Authors (4)', 60],
                ['Reviewers (3)', 8],
                ['Reproducibility pool', 8],
                ['Journal — OJN', 14],
                ['UB protocol fee', 4],
                ['Storage / compute', 6],
              ].map(([k, v]) => (
                <div key={k} style={{ marginBottom: 6 }}>
                  <div style={{ display: 'flex', justifyContent: 'space-between', fontSize: 11, marginBottom: 2 }}>
                    <span>{k}</span><span style={{ fontFamily: UB.mono }}>{v}%</span>
                  </div>
                  <div style={{ height: 3, background: UB.paperDeep, position: 'relative' }}>
                    <div style={{ position: 'absolute', inset: 0, width: `${v}%`, background: UB.ink }} />
                  </div>
                </div>
              ))}
            </Card>
          </div>
        </div>
      </Layout>
    </Dapp>
  );
}

window.PublicationDapp = PublicationDapp;
