import type { Metadata } from "next";
import PageTitle from "@/blocks/PageTitle";
import TwoColumnWithTitle from "@/blocks/TwoColumnWithTitle";
import Section from "@/components/Section/Section";
import Container from "@/components/Container/Container";
import { PureMasonryImageGrid } from "@/blocks/MasonryImageGrid";
import GreenWithLargeTitle from "@/blocks/GreenWithLargeTitle";
import TeamMarquee from "@/components/TeamMarquee/TeamMarquee";
import Link from "next/link";
import { getCachedUsers } from "@/services/wp";
import { Organization, WithContext } from "schema-dts";

import { DEFAULT_OG_IMAGE, SITE_NAME } from "@/utils/constants";
import localBusinessCompany from "@/schema/local-business-company";
import localBusinessRatings from "@/schema/local-business-ratings";

const title = `Who We Are | ${SITE_NAME}`;
const description = "Teapot's fantastic team of creative professionals who are passionate about helping people achieve their goals.";
const image = DEFAULT_OG_IMAGE;

export const metadata: Metadata = {
  metadataBase: new URL(process.env.SITE_URL),
  title: title,
  description: description,
  alternates: {
    canonical: "/about",
  },
  openGraph: {
    title: title,
    description: description,
    url: `${process.env.SITE_URL}about`,
    siteName: SITE_NAME,
    images: [
      {
        url: image,
        width: 1200,
        height: 630,
      },
    ],
    locale: "en_GB",
    type: "website",
  },
  twitter: {
    card: "summary_large_image",
    title: title,
    description: description,
    images: [image],
  },
};

const About = async () => {
  let membersOne: any[] = [];
  let membersTwo: any[] = [];

  const users = await getCachedUsers();

  const safeUsers = Array.isArray(users) ? users : [];

  const m = Math.floor(safeUsers.length / 2);

  const [leftSide, rightSide] = [
    safeUsers.slice(0, m),
    safeUsers.slice(m),
  ];
  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://www.linkedin.com/company/teapot-creative/",
      "https://www.instagram.com/teapotagency/",
      "https://codepen.io/Teapot-codes/",
      "https://www.facebook.com/teapotcreativeltd/",
    ],
    contactPoint: [
      {
        "@type": "ContactPoint",
        contactType: "customer support",
        telephone: "+44 1460 281865",
        email: "hello@teapot.agency",
      },
    ],
  };


  leftSide.map((user: any) =>
    membersOne.push({
      source: user.acf.profile_image,
      alt: user.name,
      height: 200,
      width: 200,
      name: user.name,
      role: user.acf.role,
    }),
  );

  rightSide.map((user: any) =>
    membersTwo.push({
      source: user.acf.profile_image,
      alt: user.name,
      height: 200,
      width: 200,
      name: user.name,
      role: user.acf.role,
    }),
  );

  return (
    <>
      <script
        type="application/ld+json"
        dangerouslySetInnerHTML={{
          __html: JSON.stringify(organizationJsonLd),
        }}
      />
      <script
        type="application/ld+json"
        dangerouslySetInnerHTML={{
          __html: JSON.stringify(localBusinessCompany),
        }}
      />
      <script
        type="application/ld+json"
        dangerouslySetInnerHTML={{
          __html: JSON.stringify(localBusinessRatings),
        }}
      />
      <PageTitle
        title={
          "A creative digital agency driving digital innovation, presence and performance."
        }
        supporting_title={"WE ARE TEAPOT"}
      />
      <Container>
        <Section gridArea="wide" className="lg:px-md">
          <PureMasonryImageGrid
            media={[
              {
                sourceUrl: "/image/about/tp-masonry-2.webp",
                alt: "Teapotter Dale",
                rowSpan: 2,
                colSpan: 2,
                mediaType: "image",
              },
              {
                sourceUrl: "/image/about/tp-masonry-1.webp",
                alt: "Teapotter Barry",
                rowSpan: 1,
                colSpan: 1,
                mediaType: "image",
              },
              {
                sourceUrl: "/image/about/tp-masonry-6.webp",
                alt: "Beach scene",
                rowSpan: 1,
                colSpan: 1,
                mediaType: "image",
              },
            ]}
          />
        </Section>
      </Container>
      <TwoColumnWithTitle
        title={"Create. Change. Grow."}
        left_content={
          "Nobody does this like Teapot. It all started in a drafty garage and now we’re a fully integrated agency, having evolved our skills over the years to grow alongside our clients. Our name began as a welcoming metaphor - we’ll put the kettle on and find out how we can help - and it’s that authentic approach to collaboration that has helped us build long-term partnerships."
        }
        right_content={
          "We cover brand development, creative coding, digital marketing, and more thanks to a team that empathises with your challenges and responds with sustainable, inspiring solutions. Teapot believes in doing good as well as doing good work, so are committed to social responsibility; from green hosting to local charities."
        }
      />
      <Container>
        <Section gridArea="full" className="m-none overflow-hidden">
          <div className="mb-sm">
            <TeamMarquee direction={"left"} members={membersOne} />
          </div>
          <div className="mb-sm">
            <TeamMarquee direction={"right"} members={membersTwo} />
          </div>
        </Section>
      </Container>
      <Container>
        <Section gridArea="thin">
          <h2 className="h1">
            We are growth partners, working collaboratively towards a
            stronger future.
          </h2>
          <h3>Create.</h3>
          <p>
            Teapot is a diverse group of makers, planners and analysers, brought
            together by a shared curiosity - finding creative solutions to
            client problems. We encourage multi-disciplinary learning to broaden
            our offering as well as for individual development.
          </p>
          <h3>Change.</h3>
          <p>
            Building meaningful digital experiences is our daily drive but we
            have a hidden agenda; to leave the world a better place. By
            championing new, sustainable methods we hope to leave a mark that
            goes beyond great websites.
          </p>
          <h3>Grow.</h3>
          <p>
            Our experience of working with clients at all stages of their
            business journey means that we’re well-positioned to help others
            along the path to success. Is it time for a pivot in branding, a
            more robust eCommerce site or a better competitor understanding?
          </p>
        </Section>
      </Container>
      <GreenWithLargeTitle title="Creatively focused, digitally driven." />
      <Container>
        <Section gridArea="wide" className="lg:px-md">
          <PureMasonryImageGrid
            media={[
              {
                sourceUrl: "/image/about/tp-masonry-4.webp",
                alt: "The team in the office",
                rowSpan: 2,
                colSpan: 2,
                mediaType: "image",
              },
              {
                sourceUrl: "/image/about/tp-masonry-3.webp",
                alt: "The team in the office",
                rowSpan: 1,
                colSpan: 1,
                mediaType: "image",
              },
              {
                sourceUrl: "/image/about/tp-masonry-5.webp",
                alt: "The team out for a social",
                rowSpan: 1,
                colSpan: 1,
                mediaType: "image",
              },
            ]}
          />
        </Section>
        <Section gridArea="thin">
          <h3>
            Start your journey here at
            <br />
            <Link
              title="Email us"
              className="text-green"
              href="mailto:hello@teapot.agency"
            >
              hello@teapot.agency
            </Link>
          </h3>
        </Section>
      </Container>
    </>
  );
};

export default About;
