import { kebabCase, pluralize } from 'skypager-util/lib/string'
import uniq from 'lodash/uniq'

export const instanceOptions = {
  propUtils: false,
  lodash: false,
  chain: false
}

export function routeNames(options = {}, context = {}) {
  const { project = this } = context

  return uniq(project.helpers.available.concat(
    project.getOption('helperNames', [])
  ))
}

export function routes(options = {}, context = {}) {
  const { project = this } = context
  const { names = routeNames.call(this, options, context) } = options

  return uniq([
    ...names.map(s => pluralize(s)),
    ...names.map(s => pluralize(s).toLowerCase()),
    ...names.map(s => pluralize(kebabCase(s))),
    ...names.map(s => pluralize(kebabCase(s)).toLowerCase()),
  ]).map(n => `*/${n}/*.js`)
}

export function idBuilder(result) {
  return result.id.replace(/^(src|app)\//i, '').replace(/^helpers\//i,'').replace(/\/index$/,'')
}

export function collectionMethods(options = {}, context = {}) {
  const { project = this } = context

  return {}
}

export function instanceMethods(options = {}, context = {}) {
  return {
    moduleInfo() {
      return this.pick('frontmatter', 'imports', 'exports', 'id')
    },
  } 
}