import { gql } from 'graphql-request'
import fetchAPI from '@/lib/api/fetchAPI'

/**
 * Query a sustainablity page by uri
 */
export async function getSustainablityPage() {
  const data = await fetchAPI(
    gql`
      query SustainablityPage {
        page(id: "sustainability", idType: URI) {
          title
          seo {
            fullHead
          }
          featuredImage {
            node {
              alt: altText
              imageUrl: sourceUrl
              placeholder: sourceUrl(size: THUMBNAIL)
            }
          }
          sustainabilityPageContent {
            heroSection {
              heroTitle
              mainDescription
              subHeroTitle
              subHeroDescription
            }
            threeRsSection {
              bodySection {
                title
                bodyCopy
              }
            }
            theRsAcrossPackagingSection {
              sectionTitle
              enableFullImage
              image: fullImage {
                alt: altText
                imageUrl: sourceUrl
                placeholder: sourceUrl(size: THUMBNAIL)
              }
              imageCaption
            }
            theFourthRSection {
              sectionTitle
              title
              description
              photoSection {
                largeImagePlacement
                photoGrid {
                  image {
                    alt: altText
                    imageUrl: sourceUrl
                    placeholder: sourceUrl(size: THUMBNAIL)
                  }
                }
              }
            }
            awardsSection {
              awards {
                awardTitle
                awardBlurb
                awardDescription
                awardImage {
                  alt: altText
                  imageUrl: sourceUrl
                  placeholder: sourceUrl(size: THUMBNAIL)
                }
                awardLink {
                  title
                  url
                }
              }
            }
            awardsFullImageSection {
              enableFullImage
              image: fullImage {
                alt: altText
                imageUrl: sourceUrl
                placeholder: sourceUrl(size: THUMBNAIL)
              }
            }
            energyConservationSection {
              sectionTitle
              title
              description
            }
          }
          customCtaSection {
            enableCta
            ctaText
            ctaLink {
              title
              url
            }
          }
        }
      }
    `
  )

  return data
}
