<commit_before>import 'bunsen-core/typedefs'

import redux from 'npm:redux'
const {createStore, applyMiddleware} = redux
import thunk from 'npm:redux-thunk'
const thunkMiddleware = thunk.default
const createStoreWithMiddleware = applyMiddleware(thunkMiddleware)(createStore)
import reducer from 'bunsen-core/reducer'
import {validate, changeModel} from 'bunsen-core/actions'

import _ from 'lodash'
import Ember from 'ember'
const {Component, RSVP, typeOf} = Ember
import computed, {readOnly} from 'ember-computed-decorators'
import getOwner from 'ember-getowner-polyfill'
import PropTypeMixin, {PropTypes} from 'ember-prop-types'
import {dereference} from 'bunsen-core/dereference'
import {getDefaultView} from 'bunsen-core/generator'
import validateView, {validateModel} from 'bunsen-core/validator'
import viewV1ToV2 from 'bunsen-core/conversion/view-v1-to-v2'
import layout from 'ember-frost-bunsen/templates/components/frost-bunsen-detail'

import {deemberify, validateRenderer} from '../utils'

function getAlias (cell) {
  if (cell.label) {
    return cell.label
  }

  const words = Ember.String.dasherize(cell.model || 'Tab').replace('-', ' ')
  return Ember.String.capitalize(words)
}

/**
 * Determine if an object is an Ember.Object or not
 * @param {Object|Ember.Object} object - object to check
 * @returns {Boolean} whether or not object is an Ember.Object
 */
function isEmberObject (object) {
  return !_.isEmpty(object) && !_.isPlainObject(object)
}

export default Component.extend(PropTypeMixin, {
  // == Component Properties ===================================================

  layout,

  // == State Properties =======================================================

  propTypes: {
    bunsenModel: PropTypes.oneOfType([
      PropTypes.EmberObject,
      PropTypes.object
    ]).isRequired,
    bunsenView: PropTypes.oneOfType([
      PropTypes.EmberObject,
      PropTypes.object
    ]),
    hook: PropTypes.string,
    onChange: PropTypes.func,
    onError: PropTypes.func,
    onValidation: PropTypes.func,
    registeredComponents: PropTypes.array,
    renderers: PropTypes.oneOfType([
      PropTypes.EmberObject,
      PropTypes.object
    ]),
    value: PropTypes.oneOfType([
      PropTypes.EmberObject,
      PropTypes.null,
      PropTypes.object
    ])
  },

  getDefaultProps () {
    return {
      classNames: ['frost-bunsen-detail'],
      disabled: false,
      hook: 'bunsenDetail',
      renderers: {},
      registeredComponents: [],
      showAllErrors: false,
      validators: [],
      value: null
    }
  },

  // == Computed Properties ====================================================

  @readOnly
  @computed('errors')
  renderErrors (errors) {
    return errors || {}
  },

  @readOnly
  @computed('reduxModel')
  renderModel (model) {
    return dereference(model || {}).schema
  },

  @readOnly
  @computed('renderModel', 'bunsenView')
  /**
   * Get the view to render (generate one if consumer doesn't supply a view)
   * @param {BunsenModel} model - the model schema to use to generate a view (if view is undefined)
   * @param {BunsenView} bunsenView - the view to use (if given)
   * @returns {BunsenView} the view to render
   */
  renderView (model, bunsenView) {
    if (_.isEmpty(bunsenView)) {
      return getDefaultView(model)
    }

    if (bunsenView.version === '1.0') {
      bunsenView = viewV1ToV2(bunsenView)

      if (bunsenView.cells.length === 1) {
        delete bunsenView.cells[0].label
      }

      return bunsenView
    }

    if (typeOf(bunsenView.get) === 'function' && bunsenView.get('view') === '1.0') {
      bunsenView = viewV1ToV2(deemberify(bunsenView))

      if (bunsenView.cells.length === 1) {
        delete bunsenView.cells[0].label
      }

      return bunsenView
    }

    return _.cloneDeep(bunsenView)
  },

  @readOnly
  @computed('renderView')
  cellTabs () {
    const cells = this.get('renderView.cells')

    // If there is only one cell then we don't need to render tabs
    if (cells.length === 1) {
      return Ember.A([])
    }

    const tabs = cells.map((cell, index) => {
      const alias = getAlias(cell)

      // Since label is used for tab text don't render a label within tab as well
      delete cell.label

      return {
        alias,
        cell,
        id: `${index}-${Date.now()}`,
        classNames: Ember.String.dasherize(alias)
      }<commit_msg>Fix lint error<commit_after>import 'bunsen-core/typedefs'

import redux from 'npm:redux'
const {createStore, applyMiddleware} = redux
import thunk from 'npm:redux-thunk'
const thunkMiddleware = thunk.default
const createStoreWithMiddleware = applyMiddleware(thunkMiddleware)(createStore)
import reducer from 'bunsen-core/reducer'
import {validate, changeModel} from 'bunsen-core/actions'

import _ from 'lodash'
import Ember from 'ember'
const {Component, RSVP, typeOf} = Ember
import computed, {readOnly} from 'ember-computed-decorators'
import getOwner from 'ember-getowner-polyfill'
import PropTypeMixin, {PropTypes} from 'ember-prop-types'
import {dereference} from 'bunsen-core/dereference'
import {getDefaultView} from 'bunsen-core/generator'
import validateView, {validateModel} from 'bunsen-core/validator'
import viewV1ToV2 from 'bunsen-core/conversion/view-v1-to-v2'
import layout from 'ember-frost-bunsen/templates/components/frost-bunsen-detail'

import {deemberify, validateRenderer} from '../utils'

function getAlias (cell) {
  if (cell.label) {
    return cell.label
  }

  const words = Ember.String.dasherize(cell.model || 'Tab').replace('-', ' ')
  return Ember.String.capitalize(words)
}

/**
 * Determine if an object is an Ember.Object or not
 * @param {Object|Ember.Object} object - object to check
 * @returns {Boolean} whether or not object is an Ember.Object
 */
function isEmberObject (object) {
  return !_.isEmpty(object) && !_.isPlainObject(object)
}

/**
 * Convert v1 view to v2 view
 * @param {Object} bunsenView - v1 bunsen view
 * @returns {Object} v2 bunsen view
 */
function v2View (bunsenView) {
  bunsenView = viewV1ToV2(bunsenView)

  if (bunsenView.cells.length === 1) {
    delete bunsenView.cells[0].label
  }

  return bunsenView
}

export default Component.extend(PropTypeMixin, {
  // == Component Properties ===================================================

  layout,

  // == State Properties =======================================================

  propTypes: {
    bunsenModel: PropTypes.oneOfType([
      PropTypes.EmberObject,
      PropTypes.object
    ]).isRequired,
    bunsenView: PropTypes.oneOfType([
      PropTypes.EmberObject,
      PropTypes.object
    ]),
    hook: PropTypes.string,
    onChange: PropTypes.func,
    onError: PropTypes.func,
    onValidation: PropTypes.func,
    registeredComponents: PropTypes.array,
    renderers: PropTypes.oneOfType([
      PropTypes.EmberObject,
      PropTypes.object
    ]),
    value: PropTypes.oneOfType([
      PropTypes.EmberObject,
      PropTypes.null,
      PropTypes.object
    ])
  },

  getDefaultProps () {
    return {
      classNames: ['frost-bunsen-detail'],
      disabled: false,
      hook: 'bunsenDetail',
      renderers: {},
      registeredComponents: [],
      showAllErrors: false,
      validators: [],
      value: null
    }
  },

  // == Computed Properties ====================================================

  @readOnly
  @computed('errors')
  renderErrors (errors) {
    return errors || {}
  },

  @readOnly
  @computed('reduxModel')
  renderModel (model) {
    return dereference(model || {}).schema
  },

  @readOnly
  @computed('renderModel', 'bunsenView')
  /**
   * Get the view to render (generate one if consumer doesn't supply a view)
   * @param {BunsenModel} model - the model schema to use to generate a view (if view is undefined)
   * @param {BunsenView} bunsenView - the view to use (if given)
   * @returns {BunsenView} the view to render
   */
  renderView (model, bunsenView) {
    if (_.isEmpty(bunsenView)) {
      return getDefaultView(model)
    }

    if (bunsenView.version === '1.0') {
      return v2View(bunsenView)
    }

    if (typeOf(bunsenView.get) === 'function' && bunsenView.get('view') === '1.0') {
      return v2View(deemberify(bunsenView))
    }

    return _.cloneDeep(bunsenView)
  },

  @readOnly
  @computed('renderView')
  cellTabs () {
    const cells = this.get('renderView.cells')

    // If there is only one cell then we don't need to render tabs
    if (cells.length === 1) {
      return Ember.A([])
    }

    const tabs = cells.map((cell, index) => {
      const alias = getAlias(cell)

      // Since label is used for tab text don't render a label within tab as well
      delete cell.label

      return {
        alias,
        cell,
        id: `${index}-${Date.now()}`,
        classNames: Ember.String.dasherize(alias)
      }
{'fraction_non_alphanumeric': 0.15343615332274893, 'fraction_numerical': 0.00419596280335677, 'mean_word_length': 3.4450604838709675, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '7288846', 'n_tokens_mistral': 2837, 'n_tokens_neox': 2788, 'n_words': 673}