import type { Metadata } from "next";
import Link from "next/link";
import Section from "@/components/Section/Section";
import Card from "@/components/Card/Card";
import Container from "@/components/Container/Container";
import Title from "@/components/Title/Title";
import titleStyles from "@/components/Title/Title.module.css";
import Carousel from "@/components/Carousel/Carousel";
import Listing from "@/components/Listing/Listing";
import Thumbnail from "@/components/Thumbnail/Thumbnail";
import formatDate from "@/utils/formatDate";
import PageTitleAlt from "@/blocks/PageTitleAlt";
import { getCachedStickyPosts, getCachedLatestCaseStudy } from "@/services/wp";
import { Organization, WithContext } from "schema-dts";

// schema
import localBusinessCompany from "@/schema/local-business-company";
import localBusinessRatings from "@/schema/local-business-ratings";
import AnimatedWords from "@/components/AnimatedWords/AnimatedWords";
import SecondaryCta from "@/components/SecondaryCta/SecondaryCta";
import TitleCtaBlock from "@/blocks/TitleCtaBlock";
import CollaborateSection from "@/components/CollaborateSection/CollaborateSection";
import TestimonialCarousel from "@/components/TestimonialCarousel/TestimonialCarousel";
import { homeTestimonials } from "@/content/homeTestimonials";

export const metadata: Metadata = {
  alternates: {
    canonical: "/",
  },
};

const Home = async () => {
  const stickyPosts = await getCachedStickyPosts(3);
  const latestCaseStudy = await getCachedLatestCaseStudy();
  const siteUrl = process.env.SITE_URL || "https://teapot.agency";

  const organizationJsonLd: WithContext<Organization> = {
    "@context": "https://schema.org",
    "@type": "Organization",
    "@id": `${siteUrl}/#organization`,
    name: "Teapot",
    url: siteUrl,
    logo: `${siteUrl}/image/teapot.svg`,
    email: "hello@teapot.agency",
    telephone: "+44 1460 281865",
    sameAs: [
      "https://uk.linkedin.com/company/teapotagency",
      "https://www.instagram.com/teapotagency/",
      "https://www.facebook.com/teapotcreativeltd/",
    ],
    contactPoint: [
      {
        "@type": "ContactPoint",
        contactType: "customer support",
        telephone: "+44 1460 281865",
        email: "hello@teapot.agency",
      },
    ],
  };

  return (
    <>
      <PageTitleAlt
        title={"We build your brand, find your tribe and grow your business."}
        supporting_title={"THE BRAND GROWTH AGENCY"}
      >
        <h3 className="mt-sm mb-none">
          <AnimatedWords
            text={"Web, marketing and design services in Somerset."}
          />
        </h3>
      </PageTitleAlt>
      <Container>
        <Section gridArea="full">
          <Carousel
            items={[
              {
                name: "B Corp",
                video: "/video/bcorp.mp4",
                videoSquare: "/video/bcorp-square.mp4",
                poster: "/video/poster/bcorp.webp",
              },
              {
                name: "Golden Hooves",
                video: "/video/gh.mp4",
                videoSquare: "/video/gh-square.mp4",
                poster: "/video/poster/gh.webp",
              },
              {
                name: "APO",
                video: "/video/apo.mp4",
                videoSquare: "/video/apo-square.mp4",
                poster: "/video/poster/apo.webp",
              },
              {
                name: "Headway",
                video: "/video/hw.mp4",
                videoSquare: "/video/hw-square.mp4",
                poster: "/video/poster/hw.webp",
              },
              {
                name: "Wilkie May & Tuckwood",
                video: "/video/wmt.mp4",
                videoSquare: "/video/wmt-square.mp4",
                poster: "/video/poster/wmt.webp",
              },
            ]}
          />
        </Section>
      </Container>
      <Container>
        <Section className="grid grid-cols-1 lg:grid-cols-3 gap-x-md gap-y-sm">
          <Card
            href={"/work/apo"}
            imageUrl="/image/work/apo-related-projects.webp"
            title={"Opening the door to a multi-channel campaign."}
          />
          <Card
            href={"/work/queens-college"}
            imageUrl="/image/work/queens-projects.webp"
            title={"A school rooted in heritage, reimagined through the Wyvern."}
          />
          <Card
            href={"/work/golden-hooves"}
            imageUrl="/image/work/gh-projects.jpg"
            title={"Stand up and be herd: Joining the Regen Revolution."}
          />
        </Section>
      </Container>
      <Container bgColor="primary">
        <Section
          className="grid auto-rows-auto grid-cols-1 lg:grid-cols-5 lg:gap-x-md"
          gridArea="thin"
        >
          <div
            className={`lg:col-span-3 mb-xs lg:mb-none flex flex-col items-start justify-center min-w-0 ${titleStyles.fluidContainer}`}
          >
            <Title color="white" size="sm" href="/services/design">
              Design.
            </Title>
            <Title color="white" size="sm" href="/services/development">
              Development.
            </Title>
            <Title color="white" size="sm" href="/services/marketing">
              Marketing.
            </Title>
          </div>
          <div className="lg:col-span-2 flex flex-col min-w-0">
            <p className="block w-full mb-xs">
              Teapot is the brand growth agency for businesses that want more. A
              B-Corp certified{" "}
              <strong>
                <Link href="/services/development">
                  web
                </Link>
              </strong>
              ,{" "}
              <strong>
                <Link href="/services/marketing">
                  marketing
                </Link>
              </strong>{" "}
              and{" "}
              <strong>
                <Link href="/services/design">
                  design
                </Link>
              </strong>{" "}
              agency in Somerset finding your tribe and growing your business.
              From{" "}
              <strong>
                <Link
                  href="/services/marketing/omnichannel-marketing-strategy"
                >
                  omnichannel marketing
                </Link>
              </strong>
              ,{" "}
              <strong>
                <Link
                  href="/services/web-development"
                >
                  creative coding
                </Link>
              </strong>
              ,{" "}
              <strong>
                <Link
                  href="/services/design/brand-development"
                >
                  brand development
                </Link>
              </strong>{" "}
              and more, we are always growing alongside our clients and community.
            </p>
            <p className="block w-full mb-xs">
              We help manufacturers and product-led businesses improve how they
              sell and operate, bringing together websites, ecommerce, connected
              systems and marketing. Explore our{" "}
              <strong>
                <Link href="/digital-agency-for-manufacturers">
                  digital services for manufacturers
                </Link>
              </strong>
              .
            </p>
            <p className="block w-full m-none">
            We are proud to be a{" "}
            <strong>
              <Link
                href="https://www.bcorporation.net/en-us/find-a-b-corp/company/teapot-creative-ltd/"
              >
                B-Corp
              </Link>
            </strong>{" "}
            certified team that creates change by empathising with your
            challenges and responding with practical, creative solutions. We
            believe in doing good as well as doing good work so are committed to
            social responsibility; from green hosting to local charities.
            </p>
          </div>
        </Section>
      </Container>
      {latestCaseStudy && latestCaseStudy.length > 0 && latestCaseStudy[0] && (
        <Container>
          <Section
            className="grid grid-cols-1 lg:grid-cols-2 gap-x-lg"
            gridArea={"thin"}
          >
            <Thumbnail
              imageUrl={latestCaseStudy[0].featured_image?.source || ""}
              width={600}
              height={600}
            />
            <div className="mt-xs lg:mt-none">
              <strong>CASE STUDY</strong>
              <p>
                {latestCaseStudy[0].author_name}&nbsp;/&nbsp;
                {formatDate(latestCaseStudy[0].date)}
              </p>
              <h2
                className="h1"
                dangerouslySetInnerHTML={{
                  __html: latestCaseStudy[0].title.rendered,
                }}
              />
              <div
                dangerouslySetInnerHTML={{
                  __html: latestCaseStudy[0].excerpt.rendered,
                }}
              />
              <Link
                href={`/work/${latestCaseStudy[0].slug}`}
                title={`${latestCaseStudy[0].title.rendered} case study`}
                aria-label={latestCaseStudy[0].title.rendered}
              >
                <SecondaryCta />
              </Link>
            </div>
          </Section>
        </Container>
      )}

      <TitleCtaBlock title="Do good work" ctaLabel="About us" />

      {homeTestimonials.length > 0 && (
        <TestimonialCarousel testimonials={homeTestimonials} />
      )}

      <Listing posts={stickyPosts} />
      <CollaborateSection />
      <script
        type="application/ld+json"
        dangerouslySetInnerHTML={{
          __html: JSON.stringify(localBusinessCompany),
        }}
      />
      <script
        type="application/ld+json"
        dangerouslySetInnerHTML={{
          __html: JSON.stringify(localBusinessRatings),
        }}
      />
      <script
        type="application/ld+json"
        dangerouslySetInnerHTML={{
          __html: JSON.stringify(organizationJsonLd),
        }}
      />
    </>
  );
};

export default Home;
