<commit_before>import { Box, Sans, Spacer } from "@artsy/palette"
import { CommercialInformation_artwork } from "__generated__/CommercialInformation_artwork.graphql"
import { CommercialInformation_me } from "__generated__/CommercialInformation_me.graphql"
import {
  AuctionTimerState,
  Countdown,
  currentTimerState,
  nextTimerState,
  relevantStateData,
} from "lib/Components/Bidding/Components/Timer"
import { TimeOffsetProvider } from "lib/Components/Bidding/Context/TimeOffsetProvider"
import { StateManager as CountdownStateManager } from "lib/Components/Countdown"
import { Schema, track } from "lib/utils/track"
import { capitalize } from "lodash"
import moment from "moment"
import React from "react"
import { createFragmentContainer, graphql } from "react-relay"
import { TrackingProp } from "react-tracking"
import { ArtworkExtraLinksFragmentContainer as ArtworkExtraLinks } from "./ArtworkExtraLinks"
import { AuctionPriceFragmentContainer as AuctionPrice } from "./AuctionPrice"
import { CommercialButtonsFragmentContainer as CommercialButtons } from "./CommercialButtons/CommercialButtons"
import { CommercialEditionSetInformationFragmentContainer as CommercialEditionSetInformation } from "./CommercialEditionSetInformation"
import { CommercialPartnerInformationFragmentContainer as CommercialPartnerInformation } from "./CommercialPartnerInformation"

interface CommercialInformationProps {
  artwork: CommercialInformation_artwork
  me: CommercialInformation_me
  timerState?: AuctionTimerState
  label?: string
  duration?: moment.Duration
  tracking?: TrackingProp
}

interface CommercialInformationState {
  editionSetID: string
}

export class CommercialInformationTimerWrapper extends React.Component<
  CommercialInformationProps,
  CommercialInformationState
> {
  render() {
    if (this.props.artwork.isInAuction) {
      const {
        // @ts-ignore STRICTNESS_MIGRATION
        isPreview,
        // @ts-ignore STRICTNESS_MIGRATION
        isClosed,
        // @ts-ignore STRICTNESS_MIGRATION
        liveStartAt: liveStartsAt,
        // @ts-ignore STRICTNESS_MIGRATION
        startAt: startsAt,
        // @ts-ignore STRICTNESS_MIGRATION
        endAt: endsAt,
      } = this.props.artwork.sale

      return (
        <TimeOffsetProvider>
          <CountdownStateManager
            CountdownComponent={CommercialInformation as any}
            onCurrentTickerState={() => {
              const state = currentTimerState({ isPreview, isClosed, liveStartsAt })
              const { label, date } = relevantStateData(state, { liveStartsAt, startsAt, endsAt })
              return { label, date, state }
            }}
            onNextTickerState={({ state }) => {
              const nextState = nextTimerState(state as AuctionTimerState, { liveStartsAt })
              const { label, date } = relevantStateData(nextState, { liveStartsAt, startsAt, endsAt })
              return { state: nextState, date, label }
            }}
            {
              ...(this.props as any) /* STRICTNESS_MIGRATION */
            }
          />
        </TimeOffsetProvider>
      )
    } else {
      return <CommercialInformation {...this.props} />
    }
  }
}

@track()
export class CommercialInformation extends React.Component<CommercialInformationProps, CommercialInformationState> {
  // @ts-ignore STRICTNESS_MIGRATION
  state = {
    editionSetID: null,
  }

  interval = null

  componentDidMount = () => {
    const { artwork, timerState } = this.props
    const artworkIsInActiveAuction = artwork.isInAuction && timerState !== AuctionTimerState.CLOSED

    if (artworkIsInActiveAuction) {
      // @ts-ignore STRICTNESS_MIGRATION
      this.props.tracking.trackEvent({
        action_type: Schema.ActionNames.LotViewed,
        artwork_id: artwork.internalID,
        artwork_slug: artwork.slug,
        // @ts-ignore STRICTNESS_MIGRATION
        sale_id: artwork.sale.internalID,
        // @ts-ignore STRICTNESS_MIGRATION
        auction_slug: artwork.sale.slug,
      })
    }
  }

  renderSingleEditionArtwork = () => {
    const { artwork, timerState } = this.props
    const artworkIsInClosedAuction = artwork.isInAuction && timerState === AuctionTimerState.CLOSED

    let saleMessage
    if (artworkIsInClosedAuction) {
      saleMessage = "Bidding closed"
    } else if (artwork.saleMessage === "Contact For Price") {
      saleMessage = "Contact for price"
    } else {
      saleMessage = artwork.saleMessage
    }

    return (
      <Box>
        <Sans size="4t" weight="medium">
          {saleMessage
            ? saleMessage
            : capitalize(
                // @ts-ignore STRICTNESS_MIGRATION
                artwork.availability
              )}
        </Sans>
        {!artworkIsInClosedAuction && <CommercialPartnerInformation artwork={artwork} />}
      </Box>
    )
  }

  renderPriceInformation = () => {
    const { artwork, timerState } = this.props
    const { isInAuction, isForSale } = artwork
    if (isInAuction && isForSale) {
      if (timerState === AuctionTimerState.LIVE_INTEGRATION_ONGOING) {
        return null
      } else {
        return <AuctionPrice artwork={artwork} auctionState={timerState as AuctionTimerState} />
      }
    } else if (artwork.editionSets && artwork.editionSets.length > 1) {
      return this.renderEditionSetArtwork()
    } else {
      return this.renderSingleEditionArtwork()
    }
  }

  renderEditionSetArtwork = () => {
    const { artwork } = this.props
    return (
      <CommercialEditionSetInformation
        artwork={artwork}
        setEditionSetId={editionSetID => {
          this.setState({
            editionSetID,
          })<commit_msg>WIP add colored dot for availability status<commit_after>import { Box, color, Sans, Spacer } from "@artsy/palette"
import { CommercialInformation_artwork } from "__generated__/CommercialInformation_artwork.graphql"
import { CommercialInformation_me } from "__generated__/CommercialInformation_me.graphql"
import {
  AuctionTimerState,
  Countdown,
  currentTimerState,
  nextTimerState,
  relevantStateData,
} from "lib/Components/Bidding/Components/Timer"
import { TimeOffsetProvider } from "lib/Components/Bidding/Context/TimeOffsetProvider"
import { StateManager as CountdownStateManager } from "lib/Components/Countdown"
import { Schema, track } from "lib/utils/track"
import { capitalize } from "lodash"
import moment from "moment"
import React from "react"
import { createFragmentContainer, graphql } from "react-relay"
import { TrackingProp } from "react-tracking"
import styled from "styled-components/native"
import { ArtworkExtraLinksFragmentContainer as ArtworkExtraLinks } from "./ArtworkExtraLinks"
import { AuctionPriceFragmentContainer as AuctionPrice } from "./AuctionPrice"
import { CommercialButtonsFragmentContainer as CommercialButtons } from "./CommercialButtons/CommercialButtons"
import { CommercialEditionSetInformationFragmentContainer as CommercialEditionSetInformation } from "./CommercialEditionSetInformation"
import { CommercialPartnerInformationFragmentContainer as CommercialPartnerInformation } from "./CommercialPartnerInformation"

interface CommercialInformationProps {
  artwork: CommercialInformation_artwork
  me: CommercialInformation_me
  timerState?: AuctionTimerState
  label?: string
  duration?: moment.Duration
  tracking?: TrackingProp
}

interface CommercialInformationState {
  editionSetID: string
}

export class CommercialInformationTimerWrapper extends React.Component<
  CommercialInformationProps,
  CommercialInformationState
> {
  render() {
    if (this.props.artwork.isInAuction) {
      const {
        // @ts-ignore STRICTNESS_MIGRATION
        isPreview,
        // @ts-ignore STRICTNESS_MIGRATION
        isClosed,
        // @ts-ignore STRICTNESS_MIGRATION
        liveStartAt: liveStartsAt,
        // @ts-ignore STRICTNESS_MIGRATION
        startAt: startsAt,
        // @ts-ignore STRICTNESS_MIGRATION
        endAt: endsAt,
      } = this.props.artwork.sale

      return (
        <TimeOffsetProvider>
          <CountdownStateManager
            CountdownComponent={CommercialInformation as any}
            onCurrentTickerState={() => {
              const state = currentTimerState({ isPreview, isClosed, liveStartsAt })
              const { label, date } = relevantStateData(state, { liveStartsAt, startsAt, endsAt })
              return { label, date, state }
            }}
            onNextTickerState={({ state }) => {
              const nextState = nextTimerState(state as AuctionTimerState, { liveStartsAt })
              const { label, date } = relevantStateData(nextState, { liveStartsAt, startsAt, endsAt })
              return { state: nextState, date, label }
            }}
            {
              ...(this.props as any) /* STRICTNESS_MIGRATION */
            }
          />
        </TimeOffsetProvider>
      )
    } else {
      return <CommercialInformation {...this.props} />
    }
  }
}

const ColoredDot = styled(Box)<{ dotColor: string }>`
  background-color: ${({ dotColor }: any) => dotColor};
  border-radius: 50%;
  width: 15px;
  height: 15px;
`
// ${props => props.dotColor && `background-color: ${props.dotColor}px;`}

const SaleAvailability: React.FC<{ dotColor?: string; saleMessage: string }> = ({ dotColor, saleMessage }) => {
  return (
    <Box>
      {!!dotColor && <ColoredDot dotColor={dotColor} />}
      <Sans size="4t" weight="medium">
        {saleMessage}
      </Sans>
    </Box>
  )
}

@track()
export class CommercialInformation extends React.Component<CommercialInformationProps, CommercialInformationState> {
  // @ts-ignore STRICTNESS_MIGRATION
  state = {
    editionSetID: null,
  }

  interval = null

  componentDidMount = () => {
    const { artwork, timerState } = this.props
    const artworkIsInActiveAuction = artwork.isInAuction && timerState !== AuctionTimerState.CLOSED

    if (artworkIsInActiveAuction) {
      // @ts-ignore STRICTNESS_MIGRATION
      this.props.tracking.trackEvent({
        action_type: Schema.ActionNames.LotViewed,
        artwork_id: artwork.internalID,
        artwork_slug: artwork.slug,
        // @ts-ignore STRICTNESS_MIGRATION
        sale_id: artwork.sale.internalID,
        // @ts-ignore STRICTNESS_MIGRATION
        auction_slug: artwork.sale.slug,
      })
    }
  }

  renderSingleEditionArtwork = () => {
    const { artwork, timerState } = this.props
    const artworkIsInClosedAuction = artwork.isInAuction && timerState === AuctionTimerState.CLOSED
    const saleMessage = artwork.saleMessage
      ? artwork.saleMessage
      : capitalize(
          // @ts-ignore STRICTNESS_MIGRATION
          artwork.availability
        )
    let otherColor
    if (artwork.availability === "On Loan") {
      otherColor = color("yellow100")
    } else if (artwork.availability === "Sold") {
      otherColor = color("red100")
    }

    if (artworkIsInClosedAuction) {
      return <SaleAvailability saleMessage="Bidding closed" />
    } else if (artwork.saleMessage === "Contact For Price") {
      return <SaleAvailability dotColor={color("green100")} saleMessage="For sale" />
    } else if (!artworkIsInClosedAuction) {
      return (
        <>
          <SaleAvailability saleMessage={saleMessage} />
          <CommercialPartnerInformation artwork={artwork} />
        </>
      )
    } else {
      return <SaleAvailability dotColor={otherColor} saleMessage={saleMessage} />
    }
  }

  renderPriceInformation = () => {
    const { artwork, timerState } = this.props
    const { isInAuction, isForSale } = artwork
    if (isInAuction && isForSale) {
      if (timerState === AuctionTimerState.LIVE_INTEGRATION_ONGOING) {
        return null
      } else {
        return <AuctionPrice artwork={artwork} auctionState={timerState as AuctionTimerState} />
      }
    } else if (artwork.editionSets && artwork.editionSets.length > 1) {
      return this.renderEditionSetArtwork()
    } else {
      return this.renderSingleEditionArtwork()
    }
  }

  renderEditionSetArtwork = () => {
    const { artwork } = this.props
    return (
      <CommercialEditionSetInformation
        artwork={artwork}
        setEditionSetId={editionSetID => {
          this.setState({
            editionSetID,
          })
{'fraction_non_alphanumeric': 0.09763458401305057, 'fraction_numerical': 0.0015497553017944535, 'mean_word_length': 3.103413654618474, 'pattern_counts': {'":': 0, '<': 38, '<?xml version=': 0, '>': 55, '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': '7318912', 'n_tokens_mistral': 3481, 'n_tokens_neox': 3429, 'n_words': 710}