/* Flow-OS — Vista por departamento (full heatmap drilldown) */
const { useState: useSV, useEffect: useEV } = React;

function DepartmentsVistaPage() {
  const route = useRoute();
  const [metric, setMetric] = useSV('flow');
  const [sortBy, setSortBy] = useSV('flow_desc');
  const [period, setPeriod] = useSV('month');
  const [hoverTeam, setHoverTeam] = useSV(null);
  const [isMob, setIsMob] = useSV(typeof window !== 'undefined' && window.innerWidth <= 640);
  useEV(() => {
    const onR = () => setIsMob(window.innerWidth <= 640);
    window.addEventListener('resize', onR);
    return () => window.removeEventListener('resize', onR);
  }, []);

  const metricLabels = {
    flow: isMob ? 'Flow' : 'Flow Score',
    recovery: 'Recovery',
    sleep: 'Sueño',
    hrv: 'HRV'
  };
  // Short label used only in the table header column.
  const metricHeaderLabels = { flow: 'Score', recovery: 'Recovery', sleep: 'Sueño', hrv: 'HRV' };
  const periodLabels = { month: 'Último mes', q1: 'Q1', q2: 'Q2', q3: 'Q3', q4: 'Q4', h1: 'H1', h2: 'H2' };
  const periodTopLabels = { month: 'ÚLTIMO MES', q1: 'Q1 · ENE–MAR', q2: 'Q2 · ABR–JUN', q3: 'Q3 · JUL–SEP', q4: 'Q4 · OCT–DIC', h1: 'H1 · ENE–JUN', h2: 'H2 · JUL–DIC' };
  const isFlow = metric === 'flow';

  // Period configuration. Today = 4 May 2026 (Mon, week 19, month idx 4).
  // Each period renders one or more 20-cell rows (4 weeks × 5 weekdays per month).
  // Mes = 1 row. Q = 3 rows (one per month). H = 6 rows.
  // futureFrom: index within that row's 20 cells from which future starts.
  // currentMonthIdx = 4 (May). Days passed in May = 1 (Fri 1 May was last weekday before today Mon 4).
  // We approximate "future cells in May" = ~1 cell out of 20 already past, rest grey.
  const periodConfig = (() => {
    const monthShort = ['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Oct', 'Nov', 'Dic'];
    const todayMonth = 4; // May
    const todayCellInMonth = 1; // ~1 weekday of May has passed (Fri 1 May)

    const buildRows = (startMonth, count) =>
      Array.from({ length: count }, (_, i) => {
        const m = startMonth + i;
        let futureFrom = 20;
        if (m > todayMonth) futureFrom = 0;          // entire month future
        else if (m === todayMonth) futureFrom = todayCellInMonth;
        return { label: monthShort[m], futureFrom };
      });

    if (period === 'month') {
      // Only the current 4 weeks (S15-S18) – all past.
      return {
        topLabel: 'ÚLTIMAS 4 SEMANAS',
        rows: [
          { label: 'S15-S18', futureFrom: 20, weekHeaders: true }
        ]
      };
    }
    if (period.startsWith('q')) {
      const qIdx = +period[1] - 1;
      return { topLabel: `Q${qIdx + 1}`, rows: buildRows(qIdx * 3, 3) };
    }
    if (period === 'h1') return { topLabel: 'H1', rows: buildRows(0, 6) };
    if (period === 'h2') return { topLabel: 'H2', rows: buildRows(6, 6) };
    return { topLabel: '', rows: [] };
  })();

  // Get the value to display per team based on selected metric
  const getMetric = (t) => {
    if (metric === 'flow') return t.flow;
    if (metric === 'recovery') return t.recovery;
    if (metric === 'hrv') return 35 + t.hrv * 2 + (t.flow - 60) * 0.4;
    if (metric === 'sleep') {
      // parse "7h 32m" → 0–100 score
      const m = (t.sleep || '').match(/(\d+)h\s*(\d+)?/);
      const mins = m ? (+m[1]) * 60 + (+(m[2] || 0)) : 420;
      return Math.max(20, Math.min(95, (mins - 360) / 1.6 + 60));
    }
    return t.flow;
  };

  // Sort teams
  const sorted = TEAMS.slice().sort((a, b) => {
    if (sortBy === 'flow_desc') return getMetric(b) - getMetric(a);
    if (sortBy === 'flow_asc')  return getMetric(a) - getMetric(b);
    if (sortBy === 'risk')      return (a.status === 'red' ? -2 : a.status === 'amber' ? -1 : 0)
                                       - (b.status === 'red' ? -2 : b.status === 'amber' ? -1 : 0);
    if (sortBy === 'size')      return b.size - a.size;
    return 0;
  });

  const totalPeople = TEAMS.reduce((s, t) => s + t.size, 0);
  const avgValue = Math.round(TEAMS.reduce((s, t) => s + getMetric(t), 0) / TEAMS.length);
  const redCount = TEAMS.filter(t => t.status === 'red').length;
  const amberCount = TEAMS.filter(t => t.status === 'amber').length;
  const greenCount = TEAMS.filter(t => t.status === 'green').length;

  // Aggregate cell stats across all teams for the selected period (drives Verde% and Flow%)
  const periodStats = (() => {
    let total = 0, green = 0, deepFlow = 0;
    TEAMS.forEach((d, i) => {
      const v = getMetric(d);
      const seed = i * 7 + 13;
      periodConfig.rows.forEach((row, ri) => {
        for (let j = 0; j < 20; j++) {
          if (j >= row.futureFrom) continue;
          const noise = ((seed + (ri * 100) + j * 17) % 100) / 100;
          const spread = isFlow ? 36 : metric === 'sleep' ? 60 : 45;
          const offset = metric === 'sleep' ? -10 : 0;
          const base = v + offset + (noise - 0.5) * spread;
          const cv = Math.max(15, Math.min(98, base));
          total++;
          if (cv >= 70) green++;
          if (cv >= 88) deepFlow++;
        }
      });
    });
    if (total === 0) return { greenPct: 0, flowPct: 0 };
    return {
      greenPct: Math.round((green / total) * 100),
      flowPct: Math.round((deepFlow / total) * 100)
    };
  })();

  return (
    <div style={{
      position: 'relative',
      minHeight: 'calc(100vh - 81px)',
      padding: '32px 48px 80px',
      background: `
        radial-gradient(900px 500px at 90% 0%, rgba(79,214,147,0.12), transparent 60%),
        radial-gradient(700px 400px at 0% 80%, rgba(245,230,184,0.25), transparent 60%),
        var(--bg)
      `
    }}>
      {/* Breadcrumb */}
      <div style={{ display: 'flex', alignItems: 'center', gap: 8, marginBottom: 14 }}>
        <button onClick={() => route.back()} style={{
          background: 'transparent', border: 'none', cursor: 'pointer',
          display: 'flex', alignItems: 'center', gap: 6, fontSize: 12,
          color: 'var(--ink-3)', fontFamily: 'var(--mono)', padding: 0,
          letterSpacing: '0.06em'
        }}>← VOLVER</button>
        <span className="mono" style={{ fontSize: 10, color: 'var(--ink-4)' }}>/</span>
        <span className="mono" style={{ fontSize: 10, color: 'var(--ink-3)', letterSpacing: '0.12em' }}>VISTA POR DEPARTAMENTO</span>
      </div>

      {/* Title row */}
      <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-end', marginBottom: 28 }}>
        <div>
          <div style={{ fontFamily: 'var(--serif)', fontSize: 56, lineHeight: 1, letterSpacing: '-0.02em' }}>
            Vista por departamento
          </div>
          <div className="mono" style={{ fontSize: 11, color: 'var(--ink-3)', marginTop: 10, letterSpacing: '0.1em' }}>
            {TEAMS.length} EQUIPOS · {totalPeople} PERSONAS · {periodTopLabels[period] || ''}
          </div>
        </div>
        <div style={{ display: 'flex', gap: 8 }}>
          {!route.aiOpen && (
            <button onClick={() => route.toggleAi()} className="dept-mihai-btn" style={{
              padding: '10px 16px', borderRadius: 999, border: '1px solid var(--line)',
              background: 'var(--bg-card)', fontSize: 13, cursor: 'pointer',
              display: 'flex', alignItems: 'center', gap: 8
            }}>
              <span style={{ width: 18, height: 18, borderRadius: 5, overflow: 'hidden', display: 'inline-flex', alignItems: 'center', justifyContent: 'center' }}>
                <img src="assets/mihai-chat-icon.png" alt="" width="18" height="18" style={{ display: 'block', width: '100%', height: '100%', objectFit: 'cover' }}/>
              </span>
              Pregunta a Mihai
            </button>
          )}
        </div>
      </div>

      {/* Summary KPIs strip */}
      <div className="dept-kpi-strip" style={{
        display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: 14, marginBottom: 22
      }}>
        <div className="dept-kpi" data-kpi="riesgo"><SummaryStat label="En riesgo" value={redCount} sub={`${redCount === 0 ? 'Sin alertas rojas.' : 'Requieren acción inmediata.'}`} status={20} /></div>
        <div className="dept-kpi" data-kpi="vigilancia"><SummaryStat label="En vigilancia" value={amberCount} sub="Carga elevada sostenida." status={60} /></div>
        <div className="dept-kpi" data-kpi="verde"><SummaryStat label="Verde" value={`51%`} sub="Condiciones óptimas." status={80} /></div>
        <div className="dept-kpi" data-kpi="flow"><SummaryStat label="En Flow" value={`6%`} sub="Media de 9 equipos." status={avgValue} accent="#7c5fd1" valueColor="#7c5fd1" /></div>
      </div>

      {/* Filter / sort bar */}
      <div className="dept-filter-bar" style={{
        display: 'flex', justifyContent: 'space-between', alignItems: 'center',
        background: 'var(--bg-card)', border: '1px solid var(--line)',
        padding: '12px 16px', borderRadius: 16, marginBottom: 14
      }}>
        <div className="dept-metric-group" style={{ display: 'flex', alignItems: 'center', gap: 14 }}>
          <span className="mono dept-metric-label" style={{ fontSize: 10, letterSpacing: '0.12em', color: 'var(--ink-4)' }}>MÉTRICA</span>
          <div className="dept-metric-pill" style={{ display: 'flex', gap: 4, padding: 3, background: 'var(--bg)', border: '1px solid var(--line)', borderRadius: 999 }}>
            {Object.entries(metricLabels).map(([k, l]) => (
              <button key={k} onClick={() => setMetric(k)} style={{
                padding: '6px 14px', borderRadius: 999, border: 'none',
                background: metric === k ? 'var(--ink)' : 'transparent',
                color: metric === k ? '#fff' : 'var(--ink-3)',
                fontSize: 12, cursor: 'pointer', fontFamily: 'var(--sans)', fontWeight: 500
              }}>{l}</button>
            ))}
          </div>
        </div>
        <div className="dept-sort-period" style={{ display: 'flex', alignItems: 'center', gap: 14 }}>
          <span className="mono" style={{ fontSize: 10, letterSpacing: '0.12em', color: 'var(--ink-4)' }}>ORDENAR</span>
          <select value={sortBy} onChange={(e) => setSortBy(e.target.value)} style={{
            padding: '7px 12px', border: '1px solid var(--line)', borderRadius: 999,
            background: 'var(--bg)', fontSize: 12, fontFamily: 'var(--sans)', cursor: 'pointer', color: 'var(--ink)'
          }}>
            <option value="flow_desc">Mejor → peor</option>
            <option value="flow_asc">Peor → mejor</option>
            <option value="risk">Riesgo primero</option>
            <option value="size">Tamaño equipo</option>
          </select>
          <span className="mono" style={{ fontSize: 10, letterSpacing: '0.12em', color: 'var(--ink-4)' }}>PERIODO</span>
          <select value={period} onChange={(e) => setPeriod(e.target.value)} style={{
            padding: '7px 12px', border: '1px solid var(--line)', borderRadius: 999,
            background: 'var(--bg)', fontSize: 12, fontFamily: 'var(--sans)', cursor: 'pointer', color: 'var(--ink)'
          }}>
            {Object.entries(periodLabels).map(([k, l]) => (
              <option key={k} value={k}>{l}</option>
            ))}
          </select>
        </div>
      </div>

      {/* MAIN HEATMAP TABLE */}
      <div style={{
        background: 'var(--bg-card)', border: '1px solid var(--line)', borderRadius: 22,
        padding: '20px 26px', overflow: 'hidden'
      }}>
        {/* Column headers */}
        <div className="dept-table-header" style={{
          display: 'grid', gridTemplateColumns: '220px 1fr 70px 70px 100px',
          gap: 18, alignItems: 'center', padding: '0 8px 12px 8px',
          borderBottom: '1px solid var(--line)',
          fontFamily: 'var(--mono)', fontSize: 12, color: 'var(--ink)', letterSpacing: '0.12em'
        }}>
          <span className="dept-th-equipo">EQUIPO</span>
          {period === 'month' ? (
            <div className="dept-th-weeks" style={{ display: 'grid', gridTemplateColumns: 'repeat(20, 1fr)', gap: 2 }}>
              <span style={{ gridColumn: '1 / span 5', textAlign: 'left' }}>S15</span>
              <span style={{ gridColumn: '6 / span 5', textAlign: 'left' }}>S16</span>
              <span style={{ gridColumn: '11 / span 5', textAlign: 'left' }}>S17</span>
              <span style={{ gridColumn: '16 / span 5', textAlign: 'left' }}>S18</span>
            </div>
          ) : (
            <div className="dept-th-weeks" style={{ fontSize: 11, color: 'var(--ink-3)', letterSpacing: '0.12em' }}>{periodConfig.topLabel}</div>
          )}
          <span className="dept-th-score" style={{ textAlign: 'right', paddingLeft: 3 }}>SCORE</span>
          <span className="dept-th-delta" style={{ textAlign: 'right' }}>Δ 7D</span>
          <span className="dept-th-estado" style={{ textAlign: 'left' }}>ESTADO</span>
        </div>

        {sorted.map((d, i) => {
          const v = getMetric(d);
          const seed = i * 7 + 13;
          // generate cells per row (20 per row)
          const rowCells = periodConfig.rows.map((row, ri) =>
            Array.from({ length: 20 }, (_, j) => {
              const noise = ((seed + (ri * 100) + j * 17) % 100) / 100;
              const spread = isFlow ? 36 : metric === 'sleep' ? 60 : 45;
              const offset = metric === 'sleep' ? -10 : 0;
              const base = v + offset + (noise - 0.5) * spread;
              return Math.max(15, Math.min(98, base));
            })
          );

          // Highlight: Engineering Backend on Mes view → last 2 days S18 = deep flow (purple),
          // day before = high green.
          if (d.id === 'eng-be' && period === 'month' && isFlow) {
            rowCells[0][17] = 78; // green
            rowCells[0][18] = 92; // purple (deep flow)
            rowCells[0][19] = 95; // purple (deep flow)
          }
          const c = statusColor(v, isFlow);
          const isHover = hoverTeam === d.id;
          return (
            <div
              key={d.id}
              className="dept-row"
              onClick={() => route.goDept(d.id)}
              onMouseEnter={() => setHoverTeam(d.id)}
              onMouseLeave={() => setHoverTeam(null)}
              style={{
                display: 'grid', gridTemplateColumns: '220px 1fr 70px 70px 100px', gap: 18, alignItems: 'center',
                padding: '14px 8px',
                borderBottom: i < sorted.length - 1 ? '1px solid var(--line)' : 'none',
                cursor: 'pointer',
                background: isHover ? 'rgba(0,0,0,0.025)' : 'transparent',
                transition: 'background 0.15s',
                borderRadius: 6
              }}
            >
              {/* Team */}
              <div className="dept-row-team" style={{ display: 'flex', alignItems: 'center', gap: 12 }}>
                <span className="dot" style={{ width: 10, height: 10, borderRadius: '50%', background: c.bg }}></span>
                <div style={{ minWidth: 0 }}>
                  <div style={{ fontSize: 14, fontWeight: 500 }}>
                    {d.name}
                    {d.sub && <span style={{ color: 'var(--ink-3)', fontWeight: 400 }}> · {d.sub}</span>}
                  </div>
                  <div className="mono" style={{ fontSize: 9, color: 'var(--ink-4)', marginTop: 3, letterSpacing: '0.1em' }}>
                    {d.size} PERSONAS · K-MIN {d.size >= 5 ? '✓' : '✗'}
                  </div>
                </div>
              </div>

              {/* Heat strip — multi-row */}
              <div className="dept-row-heat" style={{ display: 'flex', flexDirection: 'column', gap: 2 }}>
                {rowCells.map((cells, ri) => (
                  <div key={ri} style={{ display: 'grid', gridTemplateColumns: period === 'month' ? 'repeat(20, 1fr)' : 'repeat(20, 1fr) 36px', gap: 2, alignItems: 'center' }}>
                    {cells.map((cv, j) => {
                      const isFuture = j >= periodConfig.rows[ri].futureFrom;
                      return (
                        <div key={j} className="heat-cell" style={{
                          aspectRatio: '1/1.6',
                          background: isFuture ? 'rgba(0,0,0,0.06)' : statusColor(cv, isFlow).bg,
                          opacity: isFuture ? 1 : 0.35 + (cv / 100) * 0.65,
                          borderRadius: 2,
                          transition: 'transform 0.2s',
                          transform: isHover ? 'scaleY(1.05)' : 'scaleY(1)'
                        }}></div>
                      );
                    })}
                    {period !== 'month' && (
                      <span className="mono" style={{ fontSize: 9, color: 'var(--ink-4)', letterSpacing: '0.08em', paddingLeft: 6 }}>
                        {periodConfig.rows[ri].label}
                      </span>
                    )}
                  </div>
                ))}
              </div>

              {/* Score */}
              <div className="dept-row-score" style={{ textAlign: 'right', fontFamily: 'var(--serif)', fontSize: 26, lineHeight: 1, color: c.text, fontVariantNumeric: 'tabular-nums', alignSelf: 'start' }}>
                {Math.round(v)}
              </div>

              {/* Delta */}
              <div className="dept-row-delta" style={{ textAlign: 'right', alignSelf: 'start' }}>
                <span className="mono dept-delta-span" style={{ fontSize: 12, lineHeight: 1, color: d.delta < 0 ? 'var(--red)' : 'var(--green)', display: 'inline-block', transform: 'translateY(2px)' }}>
                  {d.delta > 0 ? '▲' : '▼'} {Math.abs(d.delta)}
                </span>
              </div>

              {/* Status pill + arrow — based on TODAY's value (last cell of last row) */}
              <div className="dept-row-pill" style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 8 }}>
                {(() => {
                  const lastRow = rowCells[rowCells.length - 1];
                  // Find last non-future cell in last row
                  const lastFutureFrom = periodConfig.rows[periodConfig.rows.length - 1].futureFrom;
                  const lastIdx = Math.max(0, lastFutureFrom - 1);
                  const todayVal = lastRow[lastIdx];
                  const tc = statusColor(todayVal, isFlow);
                  const label = (isFlow && todayVal >= 85) ? 'FLOW'
                    : todayVal >= 70 ? 'VERDE'
                    : todayVal >= 55 ? 'AVISO'
                    : 'RIESGO';
                  return (
                    <span className="pill" style={{
                      background: tc.soft,
                      color: tc.text, borderColor: 'transparent', fontSize: 10, padding: '4px 10px', fontWeight: 600
                    }}>
                      {label}
                    </span>
                  );
                })()}
                <span style={{
                  width: 26, height: 26, borderRadius: '50%',
                  border: '1px solid var(--line)', display: 'flex', alignItems: 'center', justifyContent: 'center',
                  background: isHover ? 'var(--ink)' : 'var(--bg)',
                  color: isHover ? '#fff' : 'var(--ink-3)',
                  transition: 'all 0.15s'
                }}>
                  <svg width="10" height="10" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5">
                    <path d="M9 6l6 6-6 6"/>
                  </svg>
                </span>
              </div>
            </div>
          );
        })}
      </div>

      {/* Footer caption */}
      <div className="mono" style={{
        marginTop: 18, fontSize: 10, color: 'var(--ink-4)', letterSpacing: '0.1em',
        textAlign: 'center'
      }}>
        DATOS AGREGADOS · MÍNIMO 5 PERSONAS POR EQUIPO · NUNCA INDIVIDUALES
      </div>
    </div>
  );
}

// Compact KPI card for the summary strip
function SummaryStat({ label, value, sub, status, accent, valueColor }) {
  const c = statusColor(status);
  return (
    <div style={{
      background: 'var(--bg-card)', border: '1px solid var(--line)',
      borderRadius: 18, padding: 18, position: 'relative', overflow: 'hidden'
    }}>
      <div style={{ position: 'absolute', top: 0, left: 0, right: 0, height: 2, background: accent || c.bg }}></div>
      <div className="mono" style={{ fontSize: 9, letterSpacing: '0.12em', color: 'var(--ink-3)', textTransform: 'uppercase' }}>{label}</div>
      <div style={{ fontFamily: 'var(--serif)', fontSize: 44, lineHeight: 1, marginTop: 10, color: valueColor || c.text, fontVariantNumeric: 'tabular-nums' }}>{value}</div>
      <div style={{ fontSize: 11, color: 'var(--ink-3)', marginTop: 8 }}>{sub}</div>
    </div>
  );
}

Object.assign(window, { DepartmentsVistaPage });

function MobilePeriodoButton() {
  const [val, setVal] = useSV(() => (typeof window !== 'undefined' && window.__sharedTimeRange) || 'today');
  const [open, setOpen] = useSV(false);
  useEV(() => {
    const onChange = (e) => setVal(e.detail);
    window.addEventListener('shared-time-range-change', onChange);
    return () => window.removeEventListener('shared-time-range-change', onChange);
  }, []);
  const items = [
    { id: 'today',   l: 'Lun 4 may 2026', d: 'Hoy' },
    { id: 'week',    l: 'Esta semana',    d: '28 abr – 4 may' },
    { id: 'month',   l: 'Este mes',       d: 'Mayo 2026' },
    { id: 'quarter', l: 'Este trimestre', d: 'Q2 · abr – jun' }
  ];
  const current = items.find(i => i.id === val) || items[0];
  const set = (id) => {
    setVal(id);
    setOpen(false);
    window.__sharedTimeRange = id;
    window.dispatchEvent(new CustomEvent('shared-time-range-change', { detail: id }));
  };
  return (
    <div className="mob-periodo-block" style={{ position: 'relative', marginBottom: 14 }}>
      <button onClick={() => setOpen(o => !o)} style={{
        width: '100%', display: 'flex', alignItems: 'center', justifyContent: 'space-between',
        padding: '14px 16px', borderRadius: 14,
        background: '#fff', border: '1px solid var(--line)',
        color: 'var(--ink)', cursor: 'pointer', textAlign: 'left'
      }}>
        <div style={{ display: 'flex', flexDirection: 'column' }}>
          <div className="mono" style={{ fontSize: 9, letterSpacing: '0.14em', color: 'var(--ink-3)' }}>PERIODO</div>
          <div style={{ fontSize: 14, fontWeight: 500, marginTop: 3 }}>{current.l}</div>
        </div>
        <span className="mono" style={{ fontSize: 11, color: 'var(--ink-3)' }}>{open ? '▲' : '▼'}</span>
      </button>
      {open && (
        <div style={{
          position: 'absolute', top: 'calc(100% + 6px)', left: 0, right: 0, zIndex: 20,
          background: '#fff', border: '1px solid var(--line)', borderRadius: 14,
          boxShadow: '0 8px 32px rgba(0,0,0,0.08)', padding: 6, display: 'flex', flexDirection: 'column', gap: 2
        }}>
          {items.map(it => {
            const active = val === it.id;
            return (
              <button key={it.id} onClick={() => set(it.id)} style={{
                display: 'flex', alignItems: 'center', justifyContent: 'space-between',
                padding: '12px 14px', borderRadius: 10, border: 'none',
                background: active ? 'var(--ink)' : 'transparent',
                color: active ? '#fff' : 'var(--ink)',
                cursor: 'pointer', textAlign: 'left', width: '100%'
              }}>
                <div>
                  <div style={{ fontSize: 14, fontWeight: 500 }}>{it.l}</div>
                  <div className="mono" style={{ fontSize: 10, letterSpacing: '0.12em', color: active ? 'rgba(255,255,255,0.55)' : 'var(--ink-3)', marginTop: 3 }}>{it.d}</div>
                </div>
                <span style={{ opacity: active ? 1 : 0.4 }}>{active ? '✓' : ''}</span>
              </button>
            );
          })}
        </div>
      )}
    </div>
  );
}

Object.assign(window, { MobilePeriodoButton });
