/**
 * ThinkSchool Public Website — Role Solutions Component
 * Highlights purpose-built workflows and dashboards for verified institutional personas.
 */
function RoleSolutions() {
  const featuresConfig = window.FEATURES_CONFIG || {};
  const roles = featuresConfig.roles || [];

  const [selectedRole, setSelectedRole] = React.useState(0);
  const activeRole = roles[selectedRole] || roles[0];

  return (
    <section id="roles" className="py-24 md:py-32 bg-black relative">
      <div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
        <SectionHeading
          eyebrow="Role-Based Experiences"
          title="Engineered for every member of your school community."
          description="A one-size-fits-all dashboard creates clutter and security risks. ThinkSchool provides dedicated, privacy-scoped interfaces for each role."
          align="center"
          className="mb-16"
        />

        {/* Horizontal Role Selector Tabs */}
        <div className="flex items-center justify-start lg:justify-center overflow-x-auto pb-4 mb-12 scrollbar-none gap-2">
          {roles.map((role, idx) => {
            const isCurrent = selectedRole === idx;
            return (
              <button
                key={role.id}
                type="button"
                onClick={() => setSelectedRole(idx)}
                className={`px-4 sm:px-5 py-2.5 rounded-full text-xs sm:text-sm font-medium font-body transition-all whitespace-nowrap flex items-center gap-2 ${
                  isCurrent
                    ? "bg-white text-black font-semibold shadow-lg shadow-white/10"
                    : "bg-zinc-900/90 text-zinc-400 hover:text-white hover:bg-zinc-800 border border-white/10"
                }`}
              >
                <Icon name={role.icon || "users"} size={14} className={isCurrent ? "text-amber-500" : "text-zinc-500"} />
                <span>{role.title}</span>
              </button>
            );
          })}
        </div>

        {/* Active Role Feature Card */}
        {activeRole && (
          <div className="rounded-3xl border border-white/10 bg-gradient-to-b from-zinc-900/90 to-zinc-950 p-6 sm:p-10 lg:p-12 relative overflow-hidden shadow-2xl">
            <div className="absolute top-0 right-0 -mr-20 -mt-20 w-80 h-80 bg-amber-500/10 rounded-full blur-3xl pointer-events-none" />

            <div className="grid grid-cols-1 lg:grid-cols-12 gap-8 items-center">
              <div className="lg:col-span-6 space-y-6">
                <div>
                  <Badge variant="amber" icon={<Icon name={activeRole.icon || "users"} size={12} />}>
                    {activeRole.title}
                  </Badge>
                  <h3 className="text-2xl sm:text-4xl font-heading italic text-white mt-4 leading-tight">
                    {activeRole.tagline}
                  </h3>
                </div>

                <div className="space-y-4 pt-2">
                  <h4 className="text-xs uppercase tracking-wider font-mono text-zinc-400 font-semibold">
                    Core Workflows Enabled:
                  </h4>
                  <ul className="space-y-3">
                    {activeRole.benefits.map((benefit, i) => (
                      <li key={i} className="flex items-start gap-3 text-sm sm:text-base text-zinc-300 font-body">
                        <span className="mt-1 w-5 h-5 rounded-full bg-amber-500/15 text-amber-400 flex items-center justify-center shrink-0">
                          <Icon name="check" size={12} />
                        </span>
                        <span>{benefit}</span>
                      </li>
                    ))}
                  </ul>
                </div>

                <div className="pt-4 flex items-center gap-4">
                  <Button href="/contact/" size="md" variant="primary">
                    Explore Role Demo
                  </Button>
                  <Button href="/solutions/" size="md" variant="ghost">
                    Read Role Specifications →
                  </Button>
                </div>
              </div>

              {/* Graphical Role Simulation Box */}
              <div className="lg:col-span-6">
                <div className="p-6 sm:p-8 rounded-2xl bg-zinc-950 border border-white/10 shadow-inner space-y-4">
                  <div className="flex items-center justify-between border-b border-white/10 pb-4">
                    <div className="flex items-center gap-2.5">
                      <div className="w-7 h-7 rounded-lg bg-amber-500/20 text-amber-400 flex items-center justify-center">
                        <Icon name={activeRole.icon || "users"} size={16} />
                      </div>
                      <span className="text-xs font-mono text-zinc-300">
                        portal.thinkschool.live/{activeRole.id}
                      </span>
                    </div>
                    <span className="text-[10px] uppercase font-mono px-2 py-0.5 rounded bg-emerald-500/10 text-emerald-400 border border-emerald-500/20">
                      Scoped Access
                    </span>
                  </div>

                  <div className="space-y-3 text-xs font-body text-zinc-400">
                    <div className="p-3.5 rounded-xl bg-zinc-900/80 border border-white/5 flex items-center justify-between">
                      <span className="text-zinc-200">Organization / Campus Boundary</span>
                      <span className="text-zinc-400 font-mono">Strict Tenant Scoping</span>
                    </div>
                    <div className="p-3.5 rounded-xl bg-zinc-900/80 border border-white/5 flex items-center justify-between">
                      <span className="text-zinc-200">Session Identity Verification</span>
                      <span className="text-emerald-400 font-mono">Firebase Verified</span>
                    </div>
                    <div className="p-3.5 rounded-xl bg-zinc-900/80 border border-white/5 flex items-center justify-between">
                      <span className="text-zinc-200">Authorized Class & Section Scopes</span>
                      <span className="text-amber-400 font-mono">Assigned Only</span>
                    </div>
                  </div>

                  <div className="pt-2 text-[11px] text-zinc-500 italic text-center font-body">
                    Protected by server-side Fastify & database authorization guards.
                  </div>
                </div>
              </div>
            </div>
          </div>
        )}
      </div>
    </section>
  );
}

window.RoleSolutions = RoleSolutions;
