File size: 17,189 Bytes
d73c30b
273b642
e2d3383
d73c30b
273b642
c5cf4e8
e2d3383
d73c30b
273b642
d73c30b
 
e2d3383
 
 
d030f97
 
 
 
 
 
 
 
 
 
 
6fe8658
d73c30b
f02f32b
c5309fb
590f941
 
9cdcdf2
 
c464a92
273b642
c464a92
 
 
 
 
 
273b642
 
c464a92
 
 
 
273b642
 
c464a92
 
 
 
273b642
 
c464a92
 
 
d030f97
e2d3383
273b642
 
 
 
 
 
 
4f376d9
273b642
 
d73c30b
e2d3383
d73c30b
 
e2d3383
273b642
 
 
 
 
 
 
 
 
e2d3383
 
273b642
 
 
c5cf4e8
273b642
 
c5cf4e8
e2d3383
 
 
273b642
 
 
 
 
 
c5cf4e8
273b642
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6fe8658
 
c5cf4e8
 
 
 
eaf5c00
c5cf4e8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
eaf5c00
c5cf4e8
 
 
 
 
 
1b15bc9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c5cf4e8
1b15bc9
c5cf4e8
 
 
 
 
 
273b642
c5cf4e8
 
 
 
 
 
273b642
 
c5cf4e8
 
273b642
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d030f97
273b642
 
 
 
 
 
 
 
 
e2d3383
273b642
 
 
 
 
 
 
 
 
e9356b7
273b642
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e9356b7
273b642
 
 
 
 
 
 
 
 
e9356b7
273b642
 
 
 
 
 
 
 
 
d73c30b
9cdcdf2
273b642
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e2d3383
273b642
d73c30b
 
273b642
 
 
 
d73c30b
273b642
 
 
 
 
 
 
 
 
 
 
 
 
 
c5cf4e8
273b642
c5cf4e8
590f941
 
 
 
 
 
 
 
 
 
 
 
 
273b642
 
 
1b15bc9
590f941
 
 
 
273b642
 
 
590f941
 
 
 
 
 
 
 
1b15bc9
 
 
 
 
 
 
 
590f941
1b15bc9
590f941
 
 
 
 
 
 
1b15bc9
 
590f941
273b642
 
d73c30b
 
273b642
 
c5309fb
 
273b642
 
c5309fb
 
 
 
 
273b642
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4675133
 
 
 
 
 
 
 
c5309fb
 
 
 
e2d3383
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
import { useState } from 'react'
import { ChevronDown, ChevronRight } from 'lucide-react'
import { LoadingSpinner, ErrorState } from '../components/LoadingState'
import { useCoverageRecommendation } from '../lib/api'
import MetricCard from '../components/MetricCard'
import { REGION } from '../regionConfig'

function formatUsd(n: number | undefined | null): string {
  if (n == null) return '—'
  if (n >= 1_000_000) return '$' + (n / 1_000_000).toFixed(1) + 'M'
  if (n >= 1_000) return '$' + (n / 1_000).toFixed(0) + 'K'
  return '$' + n.toLocaleString(undefined, { maximumFractionDigits: 0 })
}

const GENDERS = [
  { key: 'all', label: 'All' },
  { key: 'women', label: 'Women' },
  { key: 'men', label: 'Men' },
]
const SETTLEMENTS = [
  { key: 'all', label: 'All zones' },
  { key: 'informal', label: 'Informal' },
  { key: 'mixed', label: 'Mixed' },
  { key: 'formal', label: 'Formal' },
]

export default function ProgramDesigner() {
  const [payoutUsd] = useState(10)
  const [showModel, setShowModel] = useState(false)
  const [gender, setGender] = useState('all')
  const [settlement, setSettlement] = useState('all')
  const [workerPct, setWorkerPct] = useState(15)
  const [philPct, setPhilPct] = useState(45)
  const [insPct, setInsPct] = useState(40)

  function adjustSplit(changed: 'worker' | 'phil' | 'ins', newVal: number) {
    const val = Math.max(0, Math.min(100, newVal))
    if (changed === 'phil') {
      const remaining = 100 - val
      const otherTotal = insPct + workerPct || 1
      setPhilPct(val)
      setInsPct(Math.round((remaining * insPct) / otherTotal))
      setWorkerPct(100 - val - Math.round((remaining * insPct) / otherTotal))
    } else if (changed === 'ins') {
      const remaining = 100 - val
      const otherTotal = philPct + workerPct || 1
      setInsPct(val)
      setPhilPct(Math.round((remaining * philPct) / otherTotal))
      setWorkerPct(100 - val - Math.round((remaining * philPct) / otherTotal))
    } else {
      const remaining = 100 - val
      const otherTotal = philPct + insPct || 1
      setWorkerPct(val)
      setPhilPct(Math.round((remaining * philPct) / otherTotal))
      setInsPct(100 - val - Math.round((remaining * philPct) / otherTotal))
    }
  }

  const coverage = useCoverageRecommendation(payoutUsd, `${gender}|${settlement}`)

  if (coverage.isLoading) {
    return (
      <div className="animate-slide-up">
        <div data-tour="program-title" style={{ marginBottom: '20px' }}>
          <h2 className="page-title">Coverage recommendation</h2>
        </div>
        <LoadingSpinner message="Loading coverage data…" />
      </div>
    )
  }
  if (coverage.isError) return <ErrorState onRetry={() => coverage.refetch()} />

  const rec = coverage.data?.recommendation
  const zones = coverage.data?.zones ?? []

  const annual = rec?.annual_cost_total ?? 0
  const annualPerWorker = rec?.annual_cost_per_worker ?? 0
  const philUsd = (annual * philPct) / 100
  const insUsd = (annual * insPct) / 100
  const workerUsd = (annual * workerPct) / 100
  const philPerWorker = (annualPerWorker * philPct) / 100
  const insPerWorker = (annualPerWorker * insPct) / 100
  const workerPerYear = (annualPerWorker * workerPct) / 100

  return (
    <div className="animate-slide-up">
      {/* Editorial header */}
      <div data-tour="program-title" style={{ marginBottom: '20px' }}>
        <h2 className="page-title" style={{ maxWidth: '780px' }}>
          A heat insurance program for {rec?.total_workers?.toLocaleString() ?? '—'} outdoor workers in {REGION.primaryCity}
        </h2>
        <p className="page-caption" style={{ maxWidth: '640px' }}>
          What the tool recommends based on current heat conditions and your filters.
        </p>
      </div>

      {/* Filter chips */}
      <div
        style={{
          display: 'flex',
          alignItems: 'center',
          gap: '8px',
          marginBottom: '40px',
          flexWrap: 'wrap',
        }}
      >
        <span className="eyebrow" style={{ marginRight: '4px' }}>Who</span>
        {GENDERS.map((g) => (
          <button
            key={g.key}
            onClick={() => setGender(g.key)}
            className={`chip ${gender === g.key ? 'active' : ''}`}
          >
            {g.label}
          </button>
        ))}
        <span className="eyebrow" style={{ marginLeft: '16px', marginRight: '4px' }}>
          Where
        </span>
        {SETTLEMENTS.map((s) => (
          <button
            key={s.key}
            onClick={() => setSettlement(s.key)}
            className={`chip ${settlement === s.key ? 'active' : ''}`}
          >
            {s.label}
          </button>
        ))}
      </div>

      {/* Section 1 — Scope */}
      <div data-tour="program-scope" style={{ marginBottom: '48px' }}>
        <div className="section-header">Who's covered</div>
        <div
          className="grid grid-cols-1 sm:grid-cols-2 gap-6 sm:gap-8"
          style={{
            borderTop: '1px solid #e8e5e1',
            paddingTop: '24px',
          }}
        >
          <MetricCard
            label="Workers enrolled"
            value={rec?.total_workers?.toLocaleString() ?? '—'}
            subtitle="outdoor workers in the program"
          />
          <MetricCard
            label="Neighborhoods covered"
            value={zones.length}
            subtitle={`of ${rec?.zones_total ?? '—'} monitored`}
          />
        </div>
        <p
          style={{
            marginTop: '12px',
            fontFamily: '"Space Grotesk", system-ui, sans-serif',
            fontSize: '12px',
            color: '#8d909e',
          }}
        >
          Filtered by the Who / Where selections above.
        </p>
      </div>

      {/* Section 2 — Cost */}
      <div data-tour="program-cost" style={{ marginBottom: '48px' }}>
        <div className="section-header">What it costs</div>
        <div
          className="grid grid-cols-1 md:grid-cols-[1.4fr_1fr_1fr] gap-6 md:gap-8"
          style={{
            borderTop: '1px solid #e8e5e1',
            paddingTop: '28px',
            alignItems: 'end',
          }}
        >
          {[
            {
              label: 'Annual program cost',
              value: formatUsd(rec?.annual_cost_total),
              subtitle: `to protect ${rec?.total_workers?.toLocaleString() ?? '—'} workers`,
            },
            {
              label: 'Cost per worker',
              value: `$${rec?.annual_cost_per_worker ?? '—'}`,
              subtitle: 'per year',
            },
            {
              label: '3-year total',
              value: formatUsd((rec?.annual_cost_total ?? 0) * 3),
              subtitle: 'full pilot horizon',
            },
          ].map((m) => (
            <div key={m.label}>
              <div
                style={{
                  fontFamily: '"Space Grotesk", system-ui, sans-serif',
                  fontSize: '11px',
                  fontWeight: 500,
                  letterSpacing: '0.08em',
                  textTransform: 'uppercase',
                  color: '#8d909e',
                }}
              >
                {m.label}
              </div>
              <div
                style={{
                  fontFamily: '"Source Serif 4", Georgia, serif',
                  fontSize: '44px',
                  lineHeight: '48px',
                  fontWeight: 400,
                  color: '#1b1e2d',
                  letterSpacing: '-0.01em',
                  fontVariantNumeric: 'tabular-nums',
                  marginTop: '6px',
                }}
              >
                {m.value}
              </div>
              <div
                style={{
                  fontFamily: '"Space Grotesk", system-ui, sans-serif',
                  fontSize: '12px',
                  color: '#8d909e',
                  marginTop: '6px',
                }}
              >
                {m.subtitle}
              </div>
            </div>
          ))}
        </div>
      </div>

      {/* Section 3 — Funding */}
      <div className="section-header">How it's funded</div>
      <p
        style={{
          fontFamily: '"Space Grotesk", system-ui, sans-serif',
          fontSize: '12px',
          color: '#8d909e',
          marginTop: '-4px',
          marginBottom: '16px',
          maxWidth: '720px',
        }}
      >
        Each slice of the annual program cost above goes to a different payer.
      </p>
      <div style={{ marginBottom: '40px', maxWidth: '720px' }}>
        {/* Philanthropy row */}
        <div style={{ marginBottom: '20px' }}>
          <div
            style={{
              display: 'flex',
              alignItems: 'baseline',
              justifyContent: 'space-between',
              marginBottom: '6px',
            }}
          >
            <span
              style={{
                fontFamily: '"Space Grotesk", system-ui, sans-serif',
                fontSize: '13px',
                fontWeight: 500,
                color: '#8a3d28',
              }}
            >
              Philanthropy
            </span>
            <span
              style={{
                fontFamily: '"Space Grotesk", system-ui, sans-serif',
                fontSize: '13px',
                color: '#606373',
                fontVariantNumeric: 'tabular-nums',
              }}
            >
              {philPct}% · {formatUsd(philUsd)} · ${philPerWorker.toFixed(2)}/worker
            </span>
          </div>
          <div style={{ position: 'relative', height: '6px', background: '#fcfaf7', border: '1px solid #e8e5e1' }}>
            <div
              style={{
                position: 'absolute',
                inset: 0,
                width: `${philPct}%`,
                background: '#8a3d28',
              }}
            />
          </div>
          <input
            type="range"
            min={0}
            max={100}
            step={5}
            value={philPct}
            onChange={(e) => adjustSplit('phil', Number(e.target.value))}
            style={{ width: '100%', marginTop: '8px', accentColor: '#8a3d28' }}
          />
        </div>

        {/* Insurance row */}
        <div style={{ marginBottom: '20px' }}>
          <div
            style={{
              display: 'flex',
              alignItems: 'baseline',
              justifyContent: 'space-between',
              marginBottom: '6px',
            }}
          >
            <span
              style={{
                fontFamily: '"Space Grotesk", system-ui, sans-serif',
                fontSize: '13px',
                fontWeight: 500,
                color: '#1b1e2d',
              }}
            >
              Insurance / Government
            </span>
            <span
              style={{
                fontFamily: '"Space Grotesk", system-ui, sans-serif',
                fontSize: '13px',
                color: '#606373',
                fontVariantNumeric: 'tabular-nums',
              }}
            >
              {insPct}% · {formatUsd(insUsd)} · ${insPerWorker.toFixed(2)}/worker
            </span>
          </div>
          <div style={{ position: 'relative', height: '6px', background: '#fcfaf7', border: '1px solid #e8e5e1' }}>
            <div
              style={{
                position: 'absolute',
                inset: 0,
                width: `${insPct}%`,
                background: '#606373',
              }}
            />
          </div>
          <input
            type="range"
            min={0}
            max={100}
            step={5}
            value={insPct}
            onChange={(e) => adjustSplit('ins', Number(e.target.value))}
            style={{ width: '100%', marginTop: '8px', accentColor: '#606373' }}
          />
        </div>

        {/* Worker row */}
        <div>
          <div
            style={{
              display: 'flex',
              alignItems: 'baseline',
              justifyContent: 'space-between',
              marginBottom: '6px',
            }}
          >
            <span
              style={{
                fontFamily: '"Space Grotesk", system-ui, sans-serif',
                fontSize: '13px',
                fontWeight: 500,
                color: '#8d909e',
              }}
            >
              Worker contribution
            </span>
            <span
              style={{
                fontFamily: '"Space Grotesk", system-ui, sans-serif',
                fontSize: '13px',
                color: '#606373',
                fontVariantNumeric: 'tabular-nums',
              }}
            >
              {workerPct}% · {formatUsd(workerUsd)} · ${workerPerYear.toFixed(2)}/worker/yr
            </span>
          </div>
          <div style={{ position: 'relative', height: '6px', background: '#fcfaf7', border: '1px solid #e8e5e1' }}>
            <div
              style={{
                position: 'absolute',
                inset: 0,
                width: `${workerPct}%`,
                background: '#8d909e',
              }}
            />
          </div>
          <input
            type="range"
            min={0}
            max={100}
            step={5}
            value={workerPct}
            onChange={(e) => adjustSplit('worker', Number(e.target.value))}
            style={{ width: '100%', marginTop: '8px', accentColor: '#8d909e' }}
          />
        </div>
      </div>

      {/* Section 4 — Distribution */}
      <div data-tour="program-zones" style={{ marginBottom: '40px' }}>
        <div className="section-header">Where it lands</div>
        <p
          style={{
            fontFamily: '"Space Grotesk", system-ui, sans-serif',
            fontSize: '12px',
            color: '#8d909e',
            marginTop: '-4px',
            marginBottom: '16px',
            maxWidth: '720px',
          }}
        >
          Based on 20 years of climatology, this is the expected annual flow per
          neighborhood. The column totals to the Annual program cost above.
        </p>
        <table className="etable">
          <thead>
            <tr>
              <th>Neighborhood</th>
              <th className="num">Workers enrolled</th>
              <th className="num">Trigger days / year</th>
              <th className="num">Annual $ / worker</th>
              <th className="num">Annual $ to neighborhood</th>
            </tr>
          </thead>
          <tbody>
            {[...zones]
              .map((z) => ({
                z,
                annualTotal:
                  (z.annual_cost_per_worker ?? 0) * (z.enrolled_workers ?? 0),
              }))
              .sort((a, b) => b.annualTotal - a.annualTotal)
              .map(({ z, annualTotal }) => (
                <tr key={z.zone_id}>
                  <td>
                    <div style={{ color: '#1b1e2d' }}>{z.zone_name}</div>
                    <div style={{ fontSize: '11px', color: '#8d909e' }}>
                      {z.settlement_type}
                    </div>
                  </td>
                  <td className="num">
                    {(z.enrolled_workers ?? 0).toLocaleString()}
                  </td>
                  <td className="num">{z.annual_trigger_days ?? 0}</td>
                  <td className="num">${z.annual_cost_per_worker ?? 0}</td>
                  <td
                    className="num"
                    style={{ fontWeight: 500, color: '#1b1e2d' }}
                  >
                    {`$${annualTotal.toLocaleString(undefined, { maximumFractionDigits: 0 })}`}
                  </td>
                </tr>
              ))}
          </tbody>
        </table>
      </div>

      {/* Model disclosure (collapsible) */}
      <div>
        <button
          onClick={() => setShowModel(!showModel)}
          className="text-link"
          style={{ display: 'flex', alignItems: 'center', gap: '6px', color: '#606373' }}
        >
          {showModel ? <ChevronDown size={14} /> : <ChevronRight size={14} />}
          About this model
        </button>
        {showModel && (
          <div
            style={{
              marginTop: '16px',
              paddingTop: '16px',
              borderTop: '1px solid #e8e5e1',
              maxWidth: '640px',
            }}
          >
            <p
              style={{
                fontFamily: '"Space Grotesk", system-ui, sans-serif',
                fontSize: '13px',
                lineHeight: 1.7,
                color: '#606373',
              }}
            >
              Empirical burn analysis — the same approach operational
              parametric insurers (ARC, CCRIF, SEWA pilot) use. Twenty years
              of ERA5-Land reanalysis data are replayed through the trigger
              rules, with zone-specific urban heat island correction, to
              count how often each tier would have paid out historically.
              Expected annual loss × loading factors (basis risk, admin,
              contingency) gives the loaded premium, then the SEWA funding
              split allocates cost across workers, philanthropy, and insurer.
            </p>
          </div>
        )}
      </div>
    </div>
  )
}