/* global React */

function ProblemIcon({ kind }) {
  // Three distinct minimal animated glyphs
  if (kind === 'clock') {
    return (
      <svg className="p-icon" viewBox="0 0 56 56" fill="none">
        <circle cx="28" cy="28" r="22" stroke="var(--warn)" strokeWidth="1.2" opacity="0.4"/>
        <circle cx="28" cy="28" r="14" stroke="var(--warn)" strokeWidth="1.2"/>
        <line x1="28" y1="28" x2="28" y2="17" stroke="var(--warn)" strokeWidth="1.5" strokeLinecap="round">
          <animateTransform attributeName="transform" type="rotate" from="0 28 28" to="360 28 28" dur="6s" repeatCount="indefinite"/>
        </line>
        <line x1="28" y1="28" x2="36" y2="28" stroke="var(--warn)" strokeWidth="1.5" strokeLinecap="round" opacity="0.6">
          <animateTransform attributeName="transform" type="rotate" from="0 28 28" to="360 28 28" dur="72s" repeatCount="indefinite"/>
        </line>
        <circle cx="28" cy="28" r="2" fill="var(--warn)"/>
      </svg>
    );
  }
  if (kind === 'phone') {
    return (
      <svg className="p-icon" viewBox="0 0 56 56" fill="none">
        <rect x="14" y="6" width="28" height="44" rx="5" stroke="var(--warn)" strokeWidth="1.2"/>
        <line x1="22" y1="44" x2="34" y2="44" stroke="var(--warn)" strokeWidth="1.2" strokeLinecap="round"/>
        <g>
          <circle cx="28" cy="20" r="3" fill="var(--warn)">
            <animate attributeName="opacity" values="0.3;1;0.3" dur="1.4s" repeatCount="indefinite"/>
          </circle>
          <circle cx="28" cy="20" r="6" stroke="var(--warn)" strokeWidth="1" fill="none">
            <animate attributeName="r" values="3;14;14" dur="1.4s" repeatCount="indefinite"/>
            <animate attributeName="opacity" values="0.8;0;0" dur="1.4s" repeatCount="indefinite"/>
          </circle>
        </g>
        <line x1="20" y1="32" x2="36" y2="32" stroke="var(--warn)" strokeWidth="1" opacity="0.5"/>
        <line x1="20" y1="36" x2="32" y2="36" stroke="var(--warn)" strokeWidth="1" opacity="0.5"/>
      </svg>
    );
  }
  // 'gap'
  return (
    <svg className="p-icon" viewBox="0 0 56 56" fill="none">
      <rect x="4" y="14" width="20" height="28" rx="2" stroke="var(--warn)" strokeWidth="1.2"/>
      <rect x="32" y="14" width="20" height="28" rx="2" stroke="var(--warn)" strokeWidth="1.2"/>
      <line x1="10" y1="22" x2="18" y2="22" stroke="var(--warn)" strokeWidth="1" opacity="0.6"/>
      <line x1="10" y1="26" x2="18" y2="26" stroke="var(--warn)" strokeWidth="1" opacity="0.6"/>
      <line x1="38" y1="22" x2="46" y2="22" stroke="var(--warn)" strokeWidth="1" opacity="0.6"/>
      <line x1="38" y1="26" x2="46" y2="26" stroke="var(--warn)" strokeWidth="1" opacity="0.6"/>
      <path d="M24 28 L32 28" stroke="var(--warn)" strokeWidth="1.5" strokeDasharray="2 2">
        <animate attributeName="stroke-dashoffset" from="0" to="-8" dur="1.5s" repeatCount="indefinite"/>
      </path>
      <circle cx="28" cy="28" r="3" fill="none" stroke="var(--warn)" strokeWidth="1.2">
        <animate attributeName="opacity" values="1;0.3;1" dur="2s" repeatCount="indefinite"/>
      </circle>
    </svg>
  );
}

function Problem() {
  const cards = [
    {
      n: '01', icon: 'clock',
      title: 'You find out too late',
      body: 'Your cleaner is running behind but nobody updated Breezeway. A same-day booking has no clean scheduled. By the time you know, check-in is two hours away.',
    },
    {
      n: '02', icon: 'phone',
      title: 'Your owners are anxious',
      body: 'They want to know what happened at their property, why April was slow, whether that guest complaint got resolved. Your team spends hours writing updates that should be automatic.',
    },
    {
      n: '03', icon: 'gap',
      title: 'Your property management system schedules the work. It doesn\u2019t finish it.',
      body: 'Breezeway and Turno are great at creating jobs. They don\u2019t notice when those jobs are at risk of not getting done in time. That gap still lives in your coordinator\u2019s head.',
    },
  ];
  return (
    <section id="problem">
      <span className="section-mark">§ 01 / Problem</span>
      <div className="wrap">
        <Reveal>
          <span className="eyebrow">The reality on the ground</span>
        </Reveal>
        <Reveal delay={80}>
          <h2 className="h-section" style={{ marginTop: 22, maxWidth: 16 + 'ch' }}>
            Sound <em>familiar?</em>
          </h2>
        </Reveal>
        <div className="problem-grid">
          {cards.map((c, i) => (
            <Reveal key={c.n} delay={120 + i * 100}>
              <div className="p-card">
                <span className="index">{c.n}</span>
                <ProblemIcon kind={c.icon} />
                <h3>{c.title}</h3>
                <p>{c.body}</p>
              </div>
            </Reveal>
          ))}
        </div>
      </div>
    </section>
  );
}

window.Problem = Problem;
