text: /*
  Copyright 2016 First People's Cultural Council
  
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at
  
      http://www.apache.org/licenses/LICENSE-2.0
  
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
  */
  import React, { Component } from 'react'
  import PropTypes from 'prop-types'
  // import Immutable from 'immutable'
  
  import classNames from 'classnames'
  
  // REDUX
  import { connect } from 'react-redux'
  // REDUX: actions/dispatch/func
  import { fetchBooks } from 'providers/redux/reducers/fvBook'
  import { fetchDialect2 } from 'providers/redux/reducers/fvDialect'
  import { fetchPortal } from 'providers/redux/reducers/fvPortal'
  import { pushWindowPath } from 'providers/redux/reducers/windowPath'
  
  import selectn from 'selectn'
  import ProviderHelpers from 'common/ProviderHelpers'
  import ReportBrowser from './browse-view'
  
  /**
   * Learn songs
   */
  
  const { array, func, object, string } = PropTypes
  export class PageDialectReports extends Component {
    static propTypes = {
      routeParams: object.isRequired,
      // REDUX: reducers/state
      computeBooks: object.isRequired,
      computeDialect2: object.isRequired,
      computeLogin: object.isRequired,
      computePortal: object.isRequired,
      properties: object.isRequired,
      splitWindowPath: array.isRequired,
      windowPath: string.isRequired,
      // REDUX: actions/dispatch/func
      fetchBooks: func.isRequired,
      fetchDialect2: func.isRequired,
      fetchPortal: func.isRequired,
      pushWindowPath: func.isRequired,
    }
  
    constructor(props, context) {
      super(props, context)
  
      this.state = {
        filteredList: null,
      }
  
      // Bind methods to 'this'
      //[].forEach( (method => this[method] = this[method].bind(this)) );
    }
  
    fetchData(newProps) {
      newProps.fetchDialect2(newProps.routeParams.dialect_path)
    }
  
    // Fetch data on initial render
    componentDidMount() {
      this.fetchData(this.props)
    }
  
    // Refetch data on URL change
    componentWillReceiveProps(nextProps) {
      if (nextProps.windowPath !== this.props.windowPath) {
        this.fetchData(nextProps)
      }
    }
  
    render() {
      // const computeEntities = Immutable.fromJS([
      //   {
      //     id: this.props.routeParams.dialect_path,
      //     entity: this.props.computeDialect2,
      //   },
      // ])
  
      const computeDialect2 = ProviderHelpers.getEntry(this.props.computeDialect2, this.props.routeParams.dialect_path)
  
      return (
        <div>
          <div className="row" style={{ marginBottom: '20px' }}>
            <div className={classNames('col-xs-12', 'col-md-8')}>
              <h1>{selectn('response.title', computeDialect2)} Reports</h1>
              <ReportBrowser routeParams={this.props.routeParams} />
            </div>
          </div>
        </div>
      )
    }
  }
  
  // REDUX: reducers/state
  const mapStateToProps = (state /*, ownProps*/) => {
    const { fvBook, fvDialect, fvPortal, navigation, nuxeo, windowPath } = state
  
    const { properties } = navigation
    const { computeLogin } = nuxeo
    const { computeDialect2 } = fvDialect
    const { computeBooks } = fvBook
    const { computePortal } = fvPortal
    const { splitWindowPath, _windowPath } = windowPath
  
    return {
      computeBooks,
      computeDialect2,
      computeLogin,
      computePortal,
      properties,
      splitWindowPath,
      windowPath: _windowPath,
    }
  }
  
  // REDUX: actions/dispatch/func
  const mapDispatchToProps = {
    fetchBooks,
    fetchDialect2,
    fetchPortal,
    pushWindowPath,
  }
  
  export default connect(
    mapStateToProps,
    mapDispatchToProps
  )(PageDialectReports)
  