// Abstract floating UI fragments — no phone shell, just elements suspended in space
// Each fragment animates independently, drifts on hover, transforms with scroll
const { useState, useEffect, useRef } = React;

const CYAN = "#39D1FF";

// Service card (e.g. "Маникюр / 2ч / 200 000")
function ServiceFragment({ title, sub, price, delay = 0, float = "a" }) {
  return (
    <div className={`frag float-${float}`} style={{ animationDelay: `${delay}s` }}>
      <div style={{
        background: "#16191F", border: "1px solid rgba(255,255,255,0.08)",
        borderRadius: 18, padding: "16px 20px", minWidth: 240,
        boxShadow: "0 30px 60px -30px rgba(0,0,0,0.5), 0 0 0 1px rgba(57,209,255,0.04) inset",
        backdropFilter: "blur(20px)"
      }}>
        <div style={{ display: "flex", justifyContent: "space-between", alignItems: "flex-start", gap: 12 }}>
          <div>
            <div style={{ fontSize: 14, fontWeight: 600, color: "#fff", letterSpacing: -0.2 }}>{title}</div>
            <div style={{ fontSize: 11.5, color: "rgba(255,255,255,0.5)", marginTop: 3 }}>{sub}</div>
          </div>
          <div style={{
            padding: "4px 10px", borderRadius: 999,
            background: "rgba(57,209,255,0.12)", color: CYAN,
            fontSize: 11, fontWeight: 700
          }}>{price}</div>
        </div>
      </div>
    </div>
  );
}

// Time chip
function TimeChip({ time, selected = false, delay = 0, float = "b" }) {
  return (
    <div className={`frag float-${float}`} style={{ animationDelay: `${delay}s` }}>
      <div style={{
        padding: "12px 22px", borderRadius: 14,
        background: selected ? CYAN : "#16191F",
        border: `1px solid ${selected ? CYAN : "rgba(255,255,255,0.08)"}`,
        color: selected ? "#000" : "#fff",
        fontSize: 16, fontWeight: 700,
        boxShadow: selected ? "0 20px 50px -20px rgba(57,209,255,0.6)" : "0 20px 40px -25px rgba(0,0,0,0.5)",
        fontFeatureSettings: '"tnum"',
      }}>{time}</div>
    </div>
  );
}

// Master pill (avatar + name + rating)
function MasterPill({ name, craft, rating, hue, delay = 0, float = "a" }) {
  return (
    <div className={`frag float-${float}`} style={{ animationDelay: `${delay}s` }}>
      <div style={{
        background: "#16191F", border: "1px solid rgba(255,255,255,0.08)",
        borderRadius: 999, padding: "8px 14px 8px 8px",
        display: "inline-flex", alignItems: "center", gap: 10,
        boxShadow: "0 24px 50px -28px rgba(0,0,0,0.5)"
      }}>
        <div style={{
          width: 32, height: 32, borderRadius: "50%",
          background: `linear-gradient(135deg, oklch(0.78 0.1 ${hue}), oklch(0.55 0.12 ${hue}))`,
          flexShrink: 0
        }}/>
        <div style={{ display: "flex", flexDirection: "column", lineHeight: 1.15 }}>
          <span style={{ fontSize: 13, fontWeight: 600, color: "#fff" }}>{name}</span>
          <span style={{ fontSize: 11, color: "rgba(255,255,255,0.5)" }}>{craft}</span>
        </div>
        <div style={{ display: "flex", alignItems: "center", gap: 3, marginLeft: 4 }}>
          <svg width="11" height="11" viewBox="0 0 24 24" fill={CYAN}><path d="M12 2l2.9 6.9L22 10l-5.5 4.8L18 22l-6-3.6L6 22l1.5-7.2L2 10l7.1-1.1z"/></svg>
          <span style={{ fontSize: 12, fontWeight: 700, color: "#fff" }}>{rating}</span>
        </div>
      </div>
    </div>
  );
}

// Mini calendar with one date highlighted
function CalendarFragment({ delay = 0 }) {
  const days = [27, 28, 29, 30, 1, 2];
  const labels = ["ПН","ВТ","СР","ЧТ","ПТ","СБ"];
  return (
    <div className="frag float-c" style={{ animationDelay: `${delay}s` }}>
      <div style={{
        background: "#16191F", border: "1px solid rgba(255,255,255,0.08)",
        borderRadius: 20, padding: 18, width: 320,
        boxShadow: "0 40px 80px -30px rgba(0,0,0,0.6)"
      }}>
        <div style={{ fontSize: 11.5, color: "rgba(255,255,255,0.5)", marginBottom: 12, fontWeight: 600 }}>Выберите день</div>
        <div style={{ display: "grid", gridTemplateColumns: "repeat(6,1fr)", gap: 6 }}>
          {days.map((d, i) => {
            const sel = i === 2;
            return (
              <div key={d} style={{
                textAlign: "center", padding: "8px 0", borderRadius: 10,
                background: sel ? CYAN : "rgba(255,255,255,0.04)",
                color: sel ? "#000" : "#fff",
                fontWeight: 700,
                transition: "all .3s"
              }}>
                <div style={{ fontSize: 9, opacity: 0.7 }}>{labels[i]}</div>
                <div style={{ fontSize: 14, marginTop: 2 }}>{d}</div>
              </div>
            );
          })}
        </div>
      </div>
    </div>
  );
}

// Confirmation toast
function ConfirmToast({ delay = 0 }) {
  return (
    <div className="frag float-b" style={{ animationDelay: `${delay}s` }}>
      <div style={{
        background: "rgba(57,209,255,0.12)",
        border: `1px solid ${CYAN}`,
        backdropFilter: "blur(20px)",
        borderRadius: 999, padding: "12px 20px 12px 12px",
        display: "inline-flex", alignItems: "center", gap: 12,
        boxShadow: "0 30px 60px -20px rgba(57,209,255,0.4)"
      }}>
        <div style={{
          width: 24, height: 24, borderRadius: "50%", background: CYAN,
          display: "grid", placeItems: "center"
        }}>
          <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="#000" strokeWidth="3.5"><path d="M5 12l5 5 9-11"/></svg>
        </div>
        <span style={{ fontSize: 13.5, fontWeight: 600, color: "#fff" }}>Запись подтверждена</span>
      </div>
    </div>
  );
}

// Search bar fragment
function SearchFragment({ delay = 0, placeholder = "Маникюр рядом" }) {
  return (
    <div className="frag float-a" style={{ animationDelay: `${delay}s` }}>
      <div style={{
        background: "#16191F", border: `1.5px solid ${CYAN}`,
        borderRadius: 14, padding: "10px 14px", width: 280,
        display: "flex", alignItems: "center", gap: 10,
        boxShadow: `0 30px 60px -25px rgba(57,209,255,0.4)`
      }}>
        <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke={CYAN} strokeWidth="2.4"><circle cx="11" cy="11" r="7"/><path d="m20 20-3.5-3.5"/></svg>
        <span style={{ fontSize: 14, color: "#fff" }}>{placeholder}</span>
        <span style={{ width: 1.5, height: 14, background: "#fff", animation: "caret 1s steps(2) infinite", marginLeft: -4 }}/>
      </div>
    </div>
  );
}

// Glowing orb (visual accent)
function Orb({ size = 200, hue = 200, delay = 0, opacity = 0.5 }) {
  return (
    <div className="orb" style={{
      width: size, height: size, borderRadius: "50%",
      background: `radial-gradient(circle, ${hue === "cyan" ? "rgba(57,209,255,0.4)" : `oklch(0.7 0.18 ${hue} / 0.4)`}, transparent 70%)`,
      filter: "blur(40px)",
      opacity,
      animationDelay: `${delay}s`,
    }}/>
  );
}

window.YookieFragments = {
  ServiceFragment, TimeChip, MasterPill, CalendarFragment, ConfirmToast, SearchFragment, Orb
};
