import Layout from "@/components/layout/Layout";
import Link from "next/link";
import { notFound } from "next/navigation";
import { servicesList } from "@/utils/Services.utils";

const notFoundSlugs = [
  "cardiac-rehabilitation-etobicoke",
  "compression-stockings-etobicoke",
  "cranio-sacral-therapy-etobicoke",
  "cupping-therapy-etobicoke",
  "fascial-stretch-therapy-etobicoke",
  "gait-assessment-etobicoke",
  "intramuscular-stimulation-ims-etobicoke",
  "kids-physiotherapy-etobicoke",
  "motor-vehicle-accident-rehabilitation-etobicoke",
  "neuro-fascial-therapy-etobicoke",
  "orthotics-etobicoke",
  "pre-post-operative-management-etobicoke",
  "psychotherapy-etobicoke",
  "shiatsu-therapy-etobicoke",
  "shockwave-therapy-etobicoke",
  "surgical-rehab-etobicoke",
  "deep-tissue-massage-etobicoke",

];


export async function generateStaticParams() {
  const serviceParams = servicesList.map(item => ({ slug: item.slug }));

  const redirectParams = notFoundSlugs.map(slug => ({ slug }));

  // combine both arrays
  return [...serviceParams, ...redirectParams];
}

export async function generateMetadata({ params }) {
  const service = servicesList.find((item) => item.slug === params.slug);

  if (!service) {
    return {
      title: "Service Not Found",
      description: "The requested service could not be found.",
    };
  }

  return {
    title: `${service.metaTitle || service.shortTitle || service.title}`,
    description: service.metaDiscription || service.shortDesc,
  };
}

export default function ServiceDetailPage({ params }) {
  const service = servicesList.find((item) => item.slug === params.slug);

  if (!service) return notFound();

  const altText = service.title ? service.title.toUpperCase() : "SERVICE";

  return (
    <Layout
      headerStyle={1}
      footerStyle={1}
      breadcrumbTitle={service.shortTitle}
      bannerImage={service.bannerImage}
    >
      <section className="service-details pt_90 pb_90">
        <div className="auto-container">
          <div className="row clearfix">
            {/* Sidebar */}
            <div className="col-lg-4 col-md-12 col-sm-12 sidebar-side">
              <div className="default-sidebar service-sidebar mr_15">
                {/* Categories */}
                <div className="sidebar-widget category-widget">
                  <div className="widget-title">
                    <h2>Services</h2>
                  </div>
                  <div className="widget-content">
                    <ul className="category-list clearfix">
                      {servicesList.map((item, index) => (
                        <li key={index}>
                          <Link
                            href={`/etobicoke-treatment-service/${item.slug}`}
                            className={item.slug === service.slug ? "current" : ""}
                            aria-label="Etobicoke treatment service">
                            {item.shortTitle}
                          </Link>
                        </li>
                      ))}
                    </ul>
                  </div>
                </div>

                <div className="service-block-one">
                  <div className="inner-box">
                    <div className="image-box">
                      <figure className="image">
                        <img src={service.sidebarImg} alt={altText} />
                      </figure>
                    </div>
                    <div className="lower-content">
                      <div className="icon-box">
                        <img src={service.icon} alt={`${service.title} Icon`} />
                      </div>
                      <h2>{service.shortTitle}</h2>
                      <p>{service.shortDescription}</p>
                    </div>
                  </div>
                </div>
              </div>
            </div>

            <div className="col-lg-8 col-md-12 col-sm-12 content-side">
              <div className="service-details-content">
                <div className="content-one mb_60">
                  <figure className="image-box mb_40">
                    <img src={service.bigImg} alt={altText} loading="lazy" />
                  </figure>
                  <div
                    className="service-details-description"
                    dangerouslySetInnerHTML={{ __html: service.description }}
                  />
                </div>
              </div>
            </div>
          </div>
        </div>
      </section>
    </Layout>
  );
}
