"use client";

import { useState } from "react";
import Image from "next/image";
import "./Selection.css";

export default function Selection({
  plataformasInscritas = [],
  onSelect,
}: {
  plataformasInscritas: string[];
  onSelect: (plataforma: string | null) => void;
}) {
  const [selected, setSelected] = useState<string | null>(null);

  const handleSelect = (optionName: string) => {
    const value = selected === optionName ? null : optionName;
    setSelected(value);
    onSelect(value);
  };
  const options = [
    {
      name: "WINDOWS",
      img: "/windows.png",
    },
    {
      name: "MACINTOSH",
      img: "/apple.png",
    },
    {
      name: "PROFESORES",
      img: "/teacher.png",
    },
  ];

  const opcionesDisponibles = options.filter(
    (option) => !plataformasInscritas.includes(option.name),
  );

  return (
    <section className="selection">
      {opcionesDisponibles.map((option, index) => (
        <div
          key={index}
          className="selectionItem"
          onClick={() => handleSelect(option.name)}
        >
          <button
            className={`buttonSelection ${selected === option.name ? "active" : ""
              }`}
          >
            <div className="imageSelection">
              <Image
                src={option.img}
                alt={option.name.toLowerCase()}
                fill
              />
            </div>
          </button>
          <span className="buttonLabel">{option.name}</span>
        </div>
      ))}

      {opcionesDisponibles.length === 0 && (
        <p style={{ opacity: 0.6 }}>
          El alumno ya está inscrito en todas las plataformas
        </p>
      )}
    </section>
  );
}
//IO