{"size": 764, "ext": "js", "max_stars_repo_path": "src/purgatory/TreePauseButton.js", "max_stars_repo_name": "smartprocure/contexture-react", "max_stars_repo_stars_event_min_datetime": "2019-07-26T20:10:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-02T22:01:00.000Z", "max_issues_repo_path": "src/purgatory/TreePauseButton.js", "max_issues_repo_name": "smartprocure/contexture-react", "max_issues_repo_issues_event_min_datetime": "2017-11-30T17:12:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T00:31:57.000Z", "max_forks_repo_path": "src/purgatory/TreePauseButton.js", "max_forks_repo_name": "smartprocure/contexture-react", "max_forks_repo_forks_event_min_datetime": "2019-10-25T21:19:08.000Z", "max_forks_repo_forks_event_max_datetime": "2020-03-27T14:09:28.000Z"}
{"max_stars_count": 5, "max_issues_count": 511, "max_forks_count": 6, "avg_line_length": 29.3846153846, "max_line_length": 79, "alphanum_fraction": 0.6505235602}
import React from 'react'
import _ from 'lodash/fp'
import { observer } from 'mobx-react'
import { withTheme } from '../utils/theme'

let setPausedNested = (tree, path, value) =>
  tree[`${value ? '' : 'un'}pauseNested`](path)

let TreePauseButton = ({
  children,
  theme: { AlternateButton },
  Component = AlternateButton,
}) => {
  let trees = _.flow(React.Children.toArray, _.map('props'))(children)
  let allPaused = _.every(({ tree, path }) => tree.isPausedNested(path), trees)
  let flip = () =>
    _.each(({ tree, path }) => setPausedNested(tree, path, !allPaused), trees)
  return (
    <Component onClick={flip}>
      {`${allPaused ? 'Expand' : 'Collapse'} Filters`}
    </Component>
  )
}

export default _.flow(observer, withTheme)(TreePauseButton)
