import ControllerClass from './Controller'
import UniversalControllerClass from './UniversalController'
import ModuleClass from './Module'
import { DEPRECATE } from './utils'
import * as tags from './tags'

let tagsVar = tags

if (
  process.env.NODE_ENV !== 'production' &&
  typeof window.Proxy !== 'undefined'
) {
  tagsVar = Object.keys(tags).reduce((proxyHost, key) => {
    proxyHost[key] = new Proxy(tags[key], {
      get(obj, prop) {
        throw new Error('YOU HAVE NOT ENABLED THE BABEL-PLUGIN-CEREBRAL')
      },
    })

    return proxyHost
  }, {})
}

export const props = tagsVar.props
export const path = tagsVar.path
export const state = tagsVar.state
export const sequences = tagsVar.sequences
export const computed = tagsVar.computed
export const moduleState = tagsVar.moduleState
export const moduleSequences = tagsVar.moduleSequences
export const moduleComputed = tagsVar.moduleComputed

// Needed to test for instanceof.
export { default as ModuleClass } from './Module'
export { default as ControllerClass } from './Controller'
export { default as ProviderClass } from './Provider'
export { default as BaseControllerClass } from './BaseController'

export {
  SequenceFactory as ChainSequenceFactory,
  SequenceWithPropsFactory as ChainSequenceWithPropsFactory,
} from 'function-tree/fluent'

export function Controller(rootModule, options) {
  DEPRECATE('Controller', 'Use App default import instead')
  return new ControllerClass(rootModule, options)
}

export function UniversalController(rootModule, options) {
  DEPRECATE('UniversalController', 'Use UniversalApp import instead')
  return new UniversalControllerClass(rootModule, options)
}

export function UniversalApp(rootModule, options) {
  return new UniversalControllerClass(rootModule, options)
}

export function Module(definition) {
  DEPRECATE(
    'Module',
    'Use plain object/function. Type with ModuleDefinition export'
  )
  return new ModuleClass(definition)
}

export { default as CerebralError } from './CerebralError'
export { default as Provider } from './Provider'
export { default as Compute } from './Compute'
export { default as Reaction } from './Reaction'

export { default as View } from './View'
export { createDummyController, throwError } from './utils'

export default function App(rootModule, options) {
  return new ControllerClass(rootModule, options)
}

import * as tags from './tags'

import ControllerClass from './Controller'
import { DEPRECATE } from './utils'
import ModuleClass from './Module'
import UniversalControllerClass from './UniversalController'

let tagsVar = tags

if (
  process.env.NODE_ENV !== 'production' &&
  typeof window.Proxy !== 'undefined'
) {
  tagsVar = Object.keys(tags).reduce((proxyHost, key) => {
    proxyHost[key] = new Proxy(tags[key], {
      get(obj, prop) {
        throw new Error('YOU HAVE NOT ENABLED THE BABEL-PLUGIN-CEREBRAL')
      },
    })

    return proxyHost
  }, {})
}

export const props = tagsVar.props
export const path = tagsVar.path
export const state = tagsVar.state
export const sequences = tagsVar.sequences
export const computed = tagsVar.computed
export const moduleState = tagsVar.moduleState
export const moduleSequences = tagsVar.moduleSequences
export const moduleComputed = tagsVar.moduleComputed

// Needed to test for instanceof.
export { default as ModuleClass } from './Module'
export { default as ControllerClass } from './Controller'
export { default as ProviderClass } from './Provider'
export { default as BaseControllerClass } from './BaseController'

export {
  SequenceFactory as ChainSequenceFactory,
  SequenceWithPropsFactory as ChainSequenceWithPropsFactory,
} from 'function-tree/fluent'

export { sequence, parallel } from 'function-tree'

export function Controller(rootModule, options) {
  DEPRECATE('Controller', 'Use App default import instead')
  return new ControllerClass(rootModule, options)
}

export function UniversalController(rootModule, options) {
  DEPRECATE('UniversalController', 'Use UniversalApp import instead')
  return new UniversalControllerClass(rootModule, options)
}

export function UniversalApp(rootModule, options) {
  return new UniversalControllerClass(rootModule, options)
}

export function Module(definition) {
  DEPRECATE(
    'Module',
    'Use plain object/function. Type with ModuleDefinition export'
  )
  return new ModuleClass(definition)
}

export { default as CerebralError } from './CerebralError'
export { default as Provider } from './Provider'
export { default as Compute } from './Compute'
export { default as Reaction } from './Reaction'

export { default as View } from './View'
export { createDummyController, throwError } from './utils'

export default function App(rootModule, options) {
  return new ControllerClass(rootModule, options)
}

fix missing sequence and parallel exports