/* ==========================================================================
   Dusty.jsx | 08 Meet Dusty
   Mascot section. Hovering over Dusty is a gentle pat: Dusty wakes, looks
   happy and follows the pointer. A tap or click (or "Another tip") also swaps
   the cleaning tip. Dusty's artwork comes from MC_ASSETS.dusty only.
   ========================================================================== */

const MC_DUSTY_TIPS = [
  'Clean from top to bottom, so dust lands on areas you haven’t done yet.',
  'Give your spray a minute to sit before wiping. It does more of the work for you.',
  'Shake out doormats often. Less grit comes inside on everyone’s shoes.',
  'Wipe the kitchen sink dry at night for a fresher start in the morning.',
  'A quick squeegee after each shower helps keep the glass clearer for longer.',
];

function MCDustySection() {
  const [dustyTip, setDustyTip] = React.useState(0);
  const [dustyPats, setDustyPats] = React.useState(0);
  const [dustyFocus, setDustyFocus] = React.useState(false);

  const nextTip = () => {
    setDustyTip((tip) => (tip + 1) % MC_DUSTY_TIPS.length);
    setDustyPats((count) => count + 1);
  };

  return (
    <section className="mc-section mc-dusty-sec" id="dusty" aria-labelledby="mc-dusty-title">
      <div className="mc-wrap">
        <div className="mc-dusty-sec__panel" data-reveal>
          <div className="mc-dusty-sec__art mc-on-support">
            <MCIcon name="moon" className="mc-dusty-sec__moon mc-deco" />
            <MCSparkle className="mc-dusty-sec__spark mc-dusty-sec__spark--1" />
            <MCSparkle className="mc-dusty-sec__spark mc-dusty-sec__spark--2" optional />
            <MCStamp className="mc-dusty-sec__stamp" text="Dusty approved ✦ Dusty approved ✦ " />

            <button
              type="button"
              className="mc-dusty-sec__pet"
              onClick={nextTip}
              onFocus={() => setDustyFocus(true)}
              onBlur={() => setDustyFocus(false)}
              aria-label="Give Dusty a pat for a cleaning tip"
            >
              <span className="mc-dusty-breathe mc-anim">
                <MCDusty decorative forceAwake={dustyFocus} petSignal={dustyPats} />
              </span>
            </button>

            <p className="mc-dusty-sec__caption">Give Dusty a gentle pat for a tip.</p>
          </div>

          <div className="mc-dusty-sec__copy">
            <MCEyebrow>Your little cleaning companion</MCEyebrow>
            <h2 className="mc-h2" id="mc-dusty-title">
              Every little corner deserves a little care. Dusty agrees.
            </h2>
            <p className="mc-dusty-sec__body">
              Meet Dusty, the face (and the name) of Dusty Cleaning and a reminder that cleaning can feel a little lighter. Dusty
              brings the personality (and the naps). The careful cleaning is all us.
            </p>

            <div className="mc-dusty-tip">
              <p className="mc-dusty-tip__label">
                <MCIcon name="sparkle" />
                Dusty’s tip
              </p>
              <p className="mc-dusty-tip__text" key={dustyTip} aria-live="polite">
                {MC_DUSTY_TIPS[dustyTip]}
              </p>
            </div>

            <div className="mc-dusty-sec__row">
              <button type="button" className="mc-btn mc-btn--sm mc-btn--ghost" onClick={nextTip}>
                Another tip
              </button>
              <ul className="mc-dusty-sec__badges" role="list" aria-label="Dusty’s titles">
                <li>
                  <MCIcon name="check" />
                  Dusty approved
                </li>
                <li>
                  <MCIcon name="magnifier" />
                  Corner patrol
                </li>
              </ul>
            </div>
          </div>
        </div>
      </div>
    </section>
  );
}

Object.assign(window, { MCDustySection });
