"use client";

import { useEffect, useState } from "react";

interface IntroContent {
  section_name: string;
  html_content?: string | null;
}

interface SyllabusItem {
  id: string;
  level_name: string;
  pdf_url: string;
}

const SampadaCertificate = () => {
  const [intro, setIntro] = useState<IntroContent | null>(null);
  const [syllabusLinks, setSyllabusLinks] = useState<SyllabusItem[]>([]);
  const [loading, setLoading] = useState(true);

  useEffect(() => {
    const fetchData = async () => {
      try {
        const [introRes, syllabusRes] = await Promise.all([
          fetch("/api/cms/kuchipudi-exams"),
          fetch("/api/cms/kuchipudi-exams/syllabus"),
        ]);

        const introResult = await introRes.json();
        const syllabusResult = await syllabusRes.json();

        if (introResult.success) setIntro(introResult.data);
        if (syllabusResult.success) setSyllabusLinks(syllabusResult.data);
      } catch (err) {
        console.error(err);
      } finally {
        setLoading(false);
      }
    };

    fetchData();
  }, []);

  if (loading || !intro) return null;

  return (
    <>
      <section className="aboutinnercontainer academycontainer">
        <div className="container container-xxl">
          <div className="row gx-xl-5">
            <div
              className="col-12"
              data-aos="fade-up"
              data-aos-duration="700"
              data-aos-delay="800"
            >
              <div className="aboutinnercontent pt-0">
                <div className="section-heading mb-3 mb-xxl-4">
                  <h2>
                    <span>{intro.section_name}</span>
                  </h2>
                </div>

                {intro.html_content && (
                  <div dangerouslySetInnerHTML={{ __html: intro.html_content }} />
                )}

                {syllabusLinks.length > 0 && (
                  <div className="table-responsive mt-3">
                    <div className="syllabus-table">
                      <table className="table">
                        <thead>
                          <tr>
                            <th>Syllabus</th>
                            <th>Download</th>
                          </tr>
                        </thead>
                        <tbody>
                          {syllabusLinks.map((item) => (
                            <tr key={item.id}>
                              <td>{item.level_name}</td>
                              <td>
                                <a
                                  href={item.pdf_url}
                                  download
                                  target="_blank"
                                  rel="noopener noreferrer"
                                >
                                  Click this link to download syllabus
                                </a>
                              </td>
                            </tr>
                          ))}
                        </tbody>
                      </table>
                    </div>
                  </div>
                )}
              </div>
            </div>
          </div>
        </div>
      </section>
    </>
  );
};

export default SampadaCertificate;
























// "use client";

// const SampadaCertificate = () => {
//   const syllabusLinks = [
//     {
//       level: "Level 1 Syllabus - 2020",
//       href: "https://www.rkda.org/wp-content/uploads/2020/10/Kuchipudi-Level-1.pdf",
//     },
//     {
//       level: "Level 2 Syllabus - 2020",
//       href: "https://www.rkda.org/wp-content/uploads/2020/10/Kuchipudi-Level-2.pdf",
//     },
//     {
//       level: "Level 3 Syllabus - 2020",
//       href: "https://www.rkda.org/wp-content/uploads/2020/10/Kuchipudi-Level-3.pdf",
//     },
//     {
//       level: "Level 4 Syllabus - 2020",
//       href: "https://www.rkda.org/wp-content/uploads/2020/10/Kuchipudi-Level-4.pdf",
//     },
//   ];

//   return (
//     <>
//       <section className="aboutinnercontainer academycontainer">
//         <div className="container container-xxl">
//           <div className="row gx-xl-5">
//             <div
//               className="col-12"
//               data-aos="fade-up"
//               data-aos-duration="700"
//               data-aos-delay="800"
//             >
//               <div className="aboutinnercontent pt-0">
//                 <div className="section-heading mb-3 mb-xxl-4">
//                   <h2>
//                     <span>SAMPADA Certificate</span> from SiliconAndhra
//                   </h2>
//                 </div>

//                 <p>
//                   SAMPADA is a certificate program for students learning
//                   Kuchipudi Dance. SAMPADA certification is done by
//                   SiliconAndhra in affiliation with Potti Sreeramulu Telugu
//                   University (PSTU), a NAAC accredited institution. RKDA is
//                   affiliated to SAMPADA and can have their students pursue
//                   Junior/Senior Certificate Programs in Kuchipudi. Students
//                   will receive 16 University Credits for each level.
//                 </p>

//                 <ul>
//                   <li>
//                     <strong>Junior Certificate</strong> – 2 Years (Level 1 +
//                     Level 2)
//                   </li>
//                   <li>
//                     <strong>Senior Certificate</strong> – 4 Years (Level 1 +
//                     Level 2 + Level 3 + Level 4)
//                   </li>
//                 </ul>

//                 <p>
//                   RKDA students have been taking Level 1, Level 2, Level 3,
//                   and Level 4 exams since 2016. Exams are conducted once a
//                   year, with each exam consisting of a 3-hour theory paper
//                   and a 1 to 1.5-hour practical exam, depending on the level.
//                 </p>

//                 <p>
//                   Students who clear all 4 levels in 4 consecutive years will
//                   complete the equivalent of 2.5 years of a Bachelor&apos;s
//                   degree in Fine Arts from SiliconAndhra University,
//                   California. These students can further pursue the
//                   remaining 1.5 years of the Bachelor&apos;s degree directly
//                   from SiliconAndhra University to complete their degree.
//                 </p>

//                 <h3>Why SAMPADA?</h3>
//                 <ul>
//                   <li>
//                     University certificate with credits is very useful for
//                     college applications and interviews.
//                   </li>
//                   <li>
//                     Flexibility to learn from the student&apos;s own Guru.
//                     Many RKDA students have been pursuing these exams since
//                     2016 and can act as a reference guide for new students
//                     pursuing these exams.
//                   </li>
//                   <li>
//                     Opportunity to earn academic credits (16 Jr. Cert + 16
//                     Sr. Cert).
//                   </li>
//                   <li>
//                     Opportunity to learn the theoretical aspects of the art
//                     form.
//                   </li>
//                   <li>
//                     Uses a state-of-the-art LMS (Canvas Learning Management
//                     System).
//                   </li>
//                 </ul>

//                 <p>
//                   Refer to the exam syllabus table below, or download the
//                   syllabus documents directly. Please verify your
//                   level&apos;s current updated syllabus (if any) at{" "}
//                   <a
//                     href="https://sampada.siliconandhra.org/kuchipudi/"
//                     target="_blank"
//                     rel="noopener noreferrer"
//                   >
//                     sampada.siliconandhra.org/kuchipudi
//                   </a>
//                   .
//                 </p>

//                 <div className="table-responsive mt-3">
//                   <div className="syllabus-table">
//                     <table className="table">
//                       <thead>
//                         <tr>
//                           <th>Syllabus</th>
//                           <th>Download</th>
//                         </tr>
//                       </thead>
//                       <tbody>
//                         {syllabusLinks.map((item) => (
//                           <tr key={item.level}>
//                             <td>{item.level}</td>
//                             <td>
//                               <a
//                                 href={item.href}
//                                 download
//                                 target="_blank"
//                                 rel="noopener noreferrer"
//                               >
//                                 Click this link to download syllabus
//                               </a>
//                             </td>
//                           </tr>
//                         ))}
//                       </tbody>
//                     </table>
//                   </div>
//                 </div>
//               </div>
//             </div>
//           </div>
//         </div>
//       </section>
//     </>
//   );
// };

// export default SampadaCertificate;