<commit_before>import { buildClientApp } from "reaction/Artsy/Router/client"
import { routes } from "reaction/Apps/Artwork/routes"
import { data as sd } from "sharify"
import React from "react"
import ReactDOM from "react-dom"
import { enableIntercom } from "lib/intercom"
import { recordArtworkView } from "lib/components/record_artwork_view"
import { ModalType } from "@artsy/reaction/dist/Components/Authentication/Types"

const $ = require("jquery")

const mediator = require("desktop/lib/mediator.coffee")
const User = require("desktop/models/user.coffee")
const Artwork = require("desktop/models/artwork.coffee")
const ArtworkInquiry = require("desktop/models/artwork_inquiry.coffee")
const openInquiryQuestionnaireFor = require("desktop/components/inquiry_questionnaire/index.coffee")
const openAuctionBuyerPremium = require("desktop/apps/artwork/components/buyers_premium/index.coffee")
const ViewInRoomView = require("desktop/components/view_in_room/view.coffee")
const splitTest = require("desktop/components/split_test/index.coffee")

buildClientApp({
  routes,
  context: {
    user: sd.CURRENT_USER,
    mediator,
  },
})
  .then(({ ClientApp }) => {
    ReactDOM.hydrate(<ClientApp />, document.getElementById("react-root"))
  })
  .catch(error => {
    console.error(error)
  })

if (module.hot) {
  module.hot.accept()
}

const artworkSlug = location.pathname.replace(/\/artwork\//, "")
recordArtworkView(artworkSlug, sd.CURRENT_USER)

const openInquireableModal = (artworkId: string, { ask_specialist }) => {
  if (!artworkId) return
  const user = User.instantiate()
  const inquiry = new ArtworkInquiry({ notification_delay: 600 })
  const artwork = new Artwork({ id: artworkId })

  artwork.fetch().then(() => {
    openInquiryQuestionnaireFor({
      user,
      artwork,
      inquiry,
      ask_specialist,
    })
  })
}

export const handleOpenAuthModal = options => {
  mediator.trigger("open:auth", {
    mode: ModalType.signup,
    signupIntent: "signup",
    type: "signup",
    trigger: "click",
    destination: location.href,
    ...options,
  })
}

const shouldViewExperiment = () => {
  return sd.INQUIRY_AUTH === "experiment" && !sd.CURRENT_USER
}

mediator.on("launchInquiryFlow", options => {
  // TODO: Remove after inquiry a/b test
  splitTest("inquiry_auth").view()
  if (shouldViewExperiment()) {
    const authOptions = {
      intent: "Contact Gallery",
      contextModule: "Artwork CTA",
      modal_copy: "Sign up to contact gallery",
    }
    handleOpenAuthModal(authOptions)
  } else {
    openInquireableModal(options.artworkId, { ask_specialist: false })
  }
})

mediator.on("openBuyNowAskSpecialistModal", options => {
  // TODO: Remove after inquiry a/b test
  splitTest("inquiry_auth").view()
  if (shouldViewExperiment()) {
    const authOptions = {
      intent: "Ask a specialist",
      contextModule: "Artwork CTA",
      modal_copy: "Sign up to ask a specialist",
    }
    handleOpenAuthModal(authOptions)
  } else {
    openInquireableModal(options.artworkId, { ask_specialist: true })
  }
})

mediator.on("openAuctionAskSpecialistModal", options => {
  // TODO: Remove after inquiry a/b test
  splitTest("inquiry_auth").view()
  if (shouldViewExperiment()) {
    const authOptions = {
      intent: "Ask a specialist",
      contextModule: "Artwork CTA",
      modal_copy: "Sign up to ask a specialist",
    }
    handleOpenAuthModal(authOptions)
  } else {
    const artworkId = options.artworkId
    if (artworkId) {
      const user = User.instantiate()
      const inquiry = new ArtworkInquiry({ notification_delay: 600 })
      const artwork = new Artwork({ id: artworkId })

      artwork.fetch().then(() => {
        artwork.set("is_in_auction", true)<commit_msg>only fire test for logged out users<commit_after>import { buildClientApp } from "reaction/Artsy/Router/client"
import { routes } from "reaction/Apps/Artwork/routes"
import { data as sd } from "sharify"
import React from "react"
import ReactDOM from "react-dom"
import { enableIntercom } from "lib/intercom"
import { recordArtworkView } from "lib/components/record_artwork_view"
import { ModalType } from "@artsy/reaction/dist/Components/Authentication/Types"

const $ = require("jquery")
const mediator = require("desktop/lib/mediator.coffee")
const User = require("desktop/models/user.coffee")
const Artwork = require("desktop/models/artwork.coffee")
const ArtworkInquiry = require("desktop/models/artwork_inquiry.coffee")
const openInquiryQuestionnaireFor = require("desktop/components/inquiry_questionnaire/index.coffee")
const openAuctionBuyerPremium = require("desktop/apps/artwork/components/buyers_premium/index.coffee")
const ViewInRoomView = require("desktop/components/view_in_room/view.coffee")
const splitTest = require("desktop/components/split_test/index.coffee")

buildClientApp({
  routes,
  context: {
    user: sd.CURRENT_USER,
    mediator,
  },
})
  .then(({ ClientApp }) => {
    ReactDOM.hydrate(<ClientApp />, document.getElementById("react-root"))
  })
  .catch(error => {
    console.error(error)
  })

if (module.hot) {
  module.hot.accept()
}

const artworkSlug = location.pathname.replace(/\/artwork\//, "")
recordArtworkView(artworkSlug, sd.CURRENT_USER)

const openInquireableModal = (artworkId: string, { ask_specialist }) => {
  if (!artworkId) return
  const user = User.instantiate()
  const inquiry = new ArtworkInquiry({ notification_delay: 600 })
  const artwork = new Artwork({ id: artworkId })

  artwork.fetch().then(() => {
    openInquiryQuestionnaireFor({
      user,
      artwork,
      inquiry,
      ask_specialist,
    })
  })
}

export const handleOpenAuthModal = options => {
  mediator.trigger("open:auth", {
    mode: ModalType.signup,
    signupIntent: "signup",
    type: "signup",
    trigger: "click",
    destination: location.href,
    ...options,
  })
}

const shouldViewExperiment = () => {
  return sd.INQUIRY_AUTH === "experiment" && !sd.CURRENT_USER
}

const maybeFireTestView = () => {
  !sd.CURRENT_USER && splitTest("inquiry_auth").view()
}

mediator.on("launchInquiryFlow", options => {
  // TODO: Remove after inquiry a/b test
  maybeFireTestView()
  if (shouldViewExperiment()) {
    const authOptions = {
      intent: "Contact Gallery",
      contextModule: "Artwork CTA",
      modal_copy: "Sign up to contact gallery",
    }
    handleOpenAuthModal(authOptions)
  } else {
    openInquireableModal(options.artworkId, { ask_specialist: false })
  }
})

mediator.on("openBuyNowAskSpecialistModal", options => {
  // TODO: Remove after inquiry a/b test
  maybeFireTestView()
  if (shouldViewExperiment()) {
    const authOptions = {
      intent: "Ask a specialist",
      contextModule: "Artwork CTA",
      modal_copy: "Sign up to ask a specialist",
    }
    handleOpenAuthModal(authOptions)
  } else {
    openInquireableModal(options.artworkId, { ask_specialist: true })
  }
})

mediator.on("openAuctionAskSpecialistModal", options => {
  // TODO: Remove after inquiry a/b test
  maybeFireTestView()
  if (shouldViewExperiment()) {
    const authOptions = {
      intent: "Ask a specialist",
      contextModule: "Artwork CTA",
      modal_copy: "Sign up to ask a specialist",
    }
    handleOpenAuthModal(authOptions)
  } else {
    const artworkId = options.artworkId
    if (artworkId) {
      const user = User.instantiate()
      const inquiry = new ArtworkInquiry({ notification_delay: 600 })
      const artwork = new Artwork({ id: artworkId })

      artwork.fetch().then(() => {
        artwork.set("is_in_auction", true)
{'fraction_non_alphanumeric': 0.12934465375431148, 'fraction_numerical': 0.0015919342000530645, 'mean_word_length': 4.059731543624161, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 26, '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': '4105789', 'n_tokens_mistral': 2439, 'n_tokens_neox': 2355, 'n_words': 499}