<commit_before>import { registerComponent } from 'meteor/vulcan:core';
import React, { useState } from 'react';
import { withStyles } from '@material-ui/core/styles';
import withNewEvents from '../../../lib/events/withNewEvents.jsx';
import withUser from '../../common/withUser';
import truncatise from 'truncatise';
import Edit from '@material-ui/icons/Edit';
import Users from 'meteor/vulcan:users';
import Tooltip from '@material-ui/core/Tooltip';
import withDialog from '../../common/withDialog'
import withErrorBoundary from '../../common/withErrorBoundary'
import { frontpageGuidelines, defaultGuidelines } from './ForumModerationGuidelinesContent'

const styles = theme => ({
  root: {
    cursor: "pointer",
    padding: theme.spacing.unit*2,
    position:"relative"
  },
  assistance: {
    color: 'rgba(0,0,0,0.6)',
  },
  'easy-going': {
    color: 'rgba(100, 169, 105, 0.9)',
  },
  'norm-enforcing': {
    color: '#2B6A99',
  },
  'reign-of-terror': {
    color: 'rgba(179,90,49,.8)',
  },
  'editButton': {
    position: 'absolute',
    right: 16,
    height: '0.8em'
  },
  collapse: {
    display:"flex",
    justifyContent:"flex-end",
    fontSize: 14,
    marginBottom: 4,
  },
  moderationGuidelines: {
    ...theme.typography.commentStyle,
    fontSize: "1.1rem",
    '& p, & ul': {
      marginTop: '.6em',
      marginBottom: '.6em'
    },
    '& li': {
      marginTop: '.4em',
      marginBottom: '.4em'
    },
    '& .dividerBlock': {
      marginTop: theme.spacing.unit,
      marginBottom: theme.spacing.unit
    }
  }
})

const ModerationGuidelinesBox = ({classes, document, recordEvent, currentUser}) => {

  const [expanded, setExpanded] = useState(false)

  if (!document) return null

  const handleClick = (e) => {
    e.preventDefault()
    e.stopPropagation()
    setExpanded(!expanded)
    if (currentUser) {
      const eventProperties = {
        userId: currentUser._id,
        important: false,
        intercom: true,
        documentId: document && document.userId,
        targetState: !this.state.open
      };
      recordEvent('toggled-user-moderation-guidelines', false, eventProperties);
    }
  }

  const getModerationGuidelines = (document, classes) => {
    const moderationStyle = document.moderationStyle || (document.user && document.user.moderationStyle)
    const truncatiseOptions = {
      TruncateLength: 275,
      TruncateBy: "characters",
      Suffix: "... (Read More)",
      Strict: false
    }
    const { html = "" } = document.moderationGuidelines || {}
    const userGuidelines = `${document.user ? `<p><em>${document.user.displayName + "'s commenting guidelines"}</em></p><p class="${classes[moderationStyle]}">${moderationStyleLookup[moderationStyle] || ""}</p>` : ""}
    ${html || ""}`

    const combinedGuidelines = `
      ${(html || moderationStyle) ? userGuidelines : ""}
      ${(html && document.frontpageDate) ? '<hr class="dividerBlock"></hr>' : ''}
      ${document.frontpageDate ?
          frontpageGuidelines :
            (
              (html || moderationStyle) ?
                "" :
                defaultGuidelines
            )
       }
    `
    const truncatedGuidelines = truncatise(combinedGuidelines, truncatiseOptions)
    return { combinedGuidelines, truncatedGuidelines }
  }

  const openEditDialog = (e) => {
    e.preventDefault()
    e.stopPropagation()
    const { document, openDialog } = this.props;
    openDialog({<commit_msg>Fix props destructuring<commit_after>import { registerComponent } from 'meteor/vulcan:core';
import React, { useState } from 'react';
import { withStyles } from '@material-ui/core/styles';
import withNewEvents from '../../../lib/events/withNewEvents.jsx';
import withUser from '../../common/withUser';
import truncatise from 'truncatise';
import Edit from '@material-ui/icons/Edit';
import Users from 'meteor/vulcan:users';
import Tooltip from '@material-ui/core/Tooltip';
import withDialog from '../../common/withDialog'
import withErrorBoundary from '../../common/withErrorBoundary'
import { frontpageGuidelines, defaultGuidelines } from './ForumModerationGuidelinesContent'

const styles = theme => ({
  root: {
    cursor: "pointer",
    padding: theme.spacing.unit*2,
    position:"relative"
  },
  assistance: {
    color: 'rgba(0,0,0,0.6)',
  },
  'easy-going': {
    color: 'rgba(100, 169, 105, 0.9)',
  },
  'norm-enforcing': {
    color: '#2B6A99',
  },
  'reign-of-terror': {
    color: 'rgba(179,90,49,.8)',
  },
  'editButton': {
    position: 'absolute',
    right: 16,
    height: '0.8em'
  },
  collapse: {
    display:"flex",
    justifyContent:"flex-end",
    fontSize: 14,
    marginBottom: 4,
  },
  moderationGuidelines: {
    ...theme.typography.commentStyle,
    fontSize: "1.1rem",
    '& p, & ul': {
      marginTop: '.6em',
      marginBottom: '.6em'
    },
    '& li': {
      marginTop: '.4em',
      marginBottom: '.4em'
    },
    '& .dividerBlock': {
      marginTop: theme.spacing.unit,
      marginBottom: theme.spacing.unit
    }
  }
})

const ModerationGuidelinesBox = ({classes, document, recordEvent, currentUser, openDialog}) => {

  const [expanded, setExpanded] = useState(false)

  if (!document) return null

  const handleClick = (e) => {
    e.preventDefault()
    e.stopPropagation()
    setExpanded(!expanded)
    if (currentUser) {
      const eventProperties = {
        userId: currentUser._id,
        important: false,
        intercom: true,
        documentId: document && document.userId,
        targetState: !this.state.open
      };
      recordEvent('toggled-user-moderation-guidelines', false, eventProperties);
    }
  }

  const getModerationGuidelines = (document, classes) => {
    const moderationStyle = document.moderationStyle || (document.user && document.user.moderationStyle)
    const truncatiseOptions = {
      TruncateLength: 275,
      TruncateBy: "characters",
      Suffix: "... (Read More)",
      Strict: false
    }
    const { html = "" } = document.moderationGuidelines || {}
    const userGuidelines = `${document.user ? `<p><em>${document.user.displayName + "'s commenting guidelines"}</em></p><p class="${classes[moderationStyle]}">${moderationStyleLookup[moderationStyle] || ""}</p>` : ""}
    ${html || ""}`

    const combinedGuidelines = `
      ${(html || moderationStyle) ? userGuidelines : ""}
      ${(html && document.frontpageDate) ? '<hr class="dividerBlock"></hr>' : ''}
      ${document.frontpageDate ?
          frontpageGuidelines :
            (
              (html || moderationStyle) ?
                "" :
                defaultGuidelines
            )
       }
    `
    const truncatedGuidelines = truncatise(combinedGuidelines, truncatiseOptions)
    return { combinedGuidelines, truncatedGuidelines }
  }

  const openEditDialog = (e) => {
    e.preventDefault()
    e.stopPropagation()
    openDialog({
{'fraction_non_alphanumeric': 0.15545175886731863, 'fraction_numerical': 0.013136768354984674, 'mean_word_length': 3.011709601873536, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 29, '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': '144301', 'n_tokens_mistral': 2219, 'n_tokens_neox': 2132, 'n_words': 418}