<commit_before>import React, { useState } from "react"
import {
  Box,
  BoxProps,
  Carousel,
  CarouselCell,
  CarouselRail,
  ProgressDots,
  Swiper,
  SwiperCell,
  SwiperRail,
} from "@artsy/palette"
import { createFragmentContainer, graphql, QueryRenderer } from "react-relay"
import { ShowBannersRail_partner } from "v2/__generated__/ShowBannersRail_partner.graphql"
import { ShowBannersRailRendererQuery } from "v2/__generated__/ShowBannersRailRendererQuery.graphql"
import { compact, take, uniqBy } from "lodash"
import { ShowBannerFragmentContainer } from "../PartnerShows"
import { useSystemContext } from "v2/Artsy"
import { ShowBannersRailPlaceholder } from "./ShowBannersRailPlaceholder"
import { Media } from "v2/Utils/Responsive"

interface ShowBannersRailProps extends BoxProps {
  partner: ShowBannersRail_partner
}

export const ShowBannersRailContainer: React.FC<{
  children: JSX.Element[]
  onChange?(index: number): void
}> = ({ children, ...rest }) => {
  return (
    <>
      <Media greaterThan="xs">
        <Carousel
          {...rest}
          Cell={React.forwardRef((props, ref) => {
            return (
              <CarouselCell
                {...props}
                ref={ref as any}
                display="inline-flex"
                width="100%"
                pr={0}
              />
            )
          })}
          Rail={props => {
            return <CarouselRail {...props} transition="none" display="block" />
          }}
        >
          {children}
        </Carousel>
      </Media>
      <Media at="xs">
        <Swiper
          {...rest}
          mx={-1}
          Cell={React.forwardRef((props, ref) => {
            return (
              <SwiperCell
                {...props}
                ref={ref as any}
                display="inline-flex"
                width="100%"
                px={1}
              />
            )
          })}
          Rail={props => {
            return <SwiperRail {...props} display="block" />
          }}
        >
          {children}
        </Swiper>
      </Media>
    </>
  )
}

const ShowBannersRail: React.FC<ShowBannersRailProps> = ({
  partner,
  ...rest
}) => {
  const [currentCarouselPage, setCurrentCarouselPage] = useState(0)

  if (!partner) return null

  const {
    // @ts-expect-error STRICT_NULL_CHECK
    featuredShow: { edges: featured },
    // @ts-expect-error STRICT_NULL_CHECK
    currentShows: { edges: current },
    // @ts-expect-error STRICT_NULL_CHECK
    upcomingShows: { edges: upcoming },
    // @ts-expect-error STRICT_NULL_CHECK
    pastShows: { edges: past },
  } = partner

  let shows = take(
    uniqBy(compact([...featured, ...current, ...upcoming]), "node.id"),
    10
  )

  // Display past shows only if no Featured, Current, or Upcoming shows.
  if (shows.length === 0) {
    shows = compact(past)
  }

  if (shows.length === 0) {
    return null
  }

  return (
    <Box {...rest}>
      <ShowBannersRailContainer onChange={setCurrentCarouselPage}>
        {shows.map((edge, i) => {
          return (
            <ShowBannerFragmentContainer
              withAnimation
              selected={i === currentCarouselPage}
              key={edge.node.id}
              show={edge.node}
            />
          )
        })}
      </ShowBannersRailContainer>
      <ProgressDots
        mt={[2, 6]}
        activeIndex={currentCarouselPage}
        amount={shows.length}
      />
    </Box>
  )
}<commit_msg>Hide dots for if only one show visible<commit_after>import React, { useState } from "react"
import {
  Box,
  BoxProps,
  Carousel,
  CarouselCell,
  CarouselRail,
  ProgressDots,
  Swiper,
  SwiperCell,
  SwiperRail,
} from "@artsy/palette"
import { createFragmentContainer, graphql, QueryRenderer } from "react-relay"
import { ShowBannersRail_partner } from "v2/__generated__/ShowBannersRail_partner.graphql"
import { ShowBannersRailRendererQuery } from "v2/__generated__/ShowBannersRailRendererQuery.graphql"
import { compact, take, uniqBy } from "lodash"
import { ShowBannerFragmentContainer } from "../PartnerShows"
import { useSystemContext } from "v2/Artsy"
import { ShowBannersRailPlaceholder } from "./ShowBannersRailPlaceholder"
import { Media } from "v2/Utils/Responsive"

interface ShowBannersRailProps extends BoxProps {
  partner: ShowBannersRail_partner
}

export const ShowBannersRailContainer: React.FC<{
  children: JSX.Element[]
  onChange?(index: number): void
}> = ({ children, ...rest }) => {
  return (
    <>
      <Media greaterThan="xs">
        <Carousel
          {...rest}
          Cell={React.forwardRef((props, ref) => {
            return (
              <CarouselCell
                {...props}
                ref={ref as any}
                display="inline-flex"
                width="100%"
                pr={0}
              />
            )
          })}
          Rail={props => {
            return <CarouselRail {...props} transition="none" display="block" />
          }}
        >
          {children}
        </Carousel>
      </Media>
      <Media at="xs">
        <Swiper
          {...rest}
          mx={-1}
          Cell={React.forwardRef((props, ref) => {
            return (
              <SwiperCell
                {...props}
                ref={ref as any}
                display="inline-flex"
                width="100%"
                px={1}
              />
            )
          })}
          Rail={props => {
            return <SwiperRail {...props} display="block" />
          }}
        >
          {children}
        </Swiper>
      </Media>
    </>
  )
}

const ShowBannersRail: React.FC<ShowBannersRailProps> = ({
  partner,
  ...rest
}) => {
  const [currentCarouselPage, setCurrentCarouselPage] = useState(0)

  if (!partner) return null

  const {
    // @ts-expect-error STRICT_NULL_CHECK
    featuredShow: { edges: featured },
    // @ts-expect-error STRICT_NULL_CHECK
    currentShows: { edges: current },
    // @ts-expect-error STRICT_NULL_CHECK
    upcomingShows: { edges: upcoming },
    // @ts-expect-error STRICT_NULL_CHECK
    pastShows: { edges: past },
  } = partner

  let shows = take(
    uniqBy(compact([...featured, ...current, ...upcoming]), "node.id"),
    10
  )

  // Display past shows only if no Featured, Current, or Upcoming shows.
  if (shows.length === 0) {
    shows = compact(past)
  }

  if (shows.length === 0) {
    return null
  }

  return (
    <Box {...rest}>
      <ShowBannersRailContainer onChange={setCurrentCarouselPage}>
        {shows.map((edge, i) => {
          return (
            <ShowBannerFragmentContainer
              withAnimation
              selected={i === currentCarouselPage}
              key={edge.node.id}
              show={edge.node}
            />
          )
        })}
      </ShowBannersRailContainer>
      {shows.length > 1 && (
        <ProgressDots
          mt={[2, 6]}
          activeIndex={currentCarouselPage}
          amount={shows.length}
        />
      )}
    </Box>
  )
}
{'fraction_non_alphanumeric': 0.1310492505353319, 'fraction_numerical': 0.005852962169878658, 'mean_word_length': 1.9106771915247196, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 62, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1887800', 'n_tokens_mistral': 2187, 'n_tokens_neox': 2088, 'n_words': 417}