import _ from 'lodash'
import chalk from 'chalk'

const featureFlags = {
  future: [],
  experimental: ['uniformColorPalette'],
}

export function flagEnabled(config, flag) {
  if (featureFlags.future.includes(flag)) {
    return _.get(config, ['future', flag], false)
  }

  if (featureFlags.experimental.includes(flag)) {
    return _.get(config, ['experimental', flag], false)
  }

  return false
}

export function issueFlagNotices(config) {
  const log = {
    info(message) {
      console.log(chalk.bold.cyan('    info'), '-', message)
    },
    warn(message) {
      console.log(chalk.bold.yellow('    warn'), '-', message)
    },
    risk(message) {
      console.log(chalk.bold.magenta('    risk'), '-', message)
    },
  }

  if (_.some(featureFlags.future, flag => _.get(config, ['future', flag], false))) {
    const changes = Object.keys(config.future)
      .filter(flag => featureFlags.future.includes(flag) && config.future[flag])
      .map(s => chalk.cyan(s))
      .join(', ')
    console.log()
    log.info(`You have opted-in to future-facing breaking changes: ${changes}`)
    log.info(
      'These changes are stable and will be the default behavior in the next major version of Tailwind.'
    )
  }

  if (_.some(featureFlags.experimental, flag => _.get(config, ['experimental', flag], false))) {
    const changes = Object.keys(config.experimental)
      .filter(flag => featureFlags.experimental.includes(flag) && config.experimental[flag])
      .map(s => chalk.yellow(s))
      .join(', ')
    console.log()
    log.warn(`You have enabled experimental features: ${changes}`)
    log.warn(
      'Experimental features are not covered by semver, may introduce breaking changes, and can change at any time.'
    )
  }

  if (Object.keys(_.get(config, 'future', {})).length < featureFlags.future.length) {
    const changes = featureFlags.future
      .filter(flag => !_.has(config, ['future', flag]))
      .map(s => chalk.magenta(s))
      .join(', ')
    console.log()
    log.risk(`There are upcoming breaking changes: ${changes}`)
    log.risk(
      'We highly recommend opting-in to these changes now to simplify upgrading Tailwind in the future.'
    )
  }
}

export default featureFlags

@@ -214,32 +214,59 @@
 g)) %7B%0A    return
+ config.future === 'all' %7C%7C
  _.get(config, %5B
@@ -354,16 +354,49 @@
   return
+ config.experimental === 'all' %7C%7C
  _.get(c
@@ -452,24 +452,717 @@
 rn false%0A%7D%0A%0A
+function futureFlagsEnabled(config) %7B%0A  if (config.future === 'all') %7B%0A    return featureFlags.future%0A  %7D%0A%0A  return Object.keys(_.get(config, 'future', %7B%7D)).filter(%0A    flag =%3E featureFlags.future.includes(flag) && config.future%5Bflag%5D%0A  )%0A%7D%0A%0Afunction experimentalFlagsEnabled(config) %7B%0A  if (config.experimental === 'all') %7B%0A    return featureFlags.experimental%0A  %7D%0A%0A  return Object.keys(_.get(config, 'experimental', %7B%7D)).filter(%0A    flag =%3E featureFlags.experimental.includes(flag) && config.experimental%5Bflag%5D%0A  )%0A%7D%0A%0Afunction futureFlagsAvailable(config) %7B%0A  if (config.future === 'all') %7B%0A    return %5B%5D%0A  %7D%0A%0A  return featureFlags.future.filter(flag =%3E !_.has(config, %5B'future', flag%5D))%0A%7D%0A%0A
 export funct
@@ -1263,20 +1263,16 @@
 d.cyan('
-    
 info'), 
@@ -1349,20 +1349,16 @@
 yellow('
-    
 warn'), 
@@ -1436,20 +1436,16 @@
 agenta('
-    
 risk'), 
@@ -1480,213 +1480,94 @@
 if (
-_.some(featureFlags.future, flag =%3E _.get(config, %5B'future', flag%5D, false))) %7B%0A    const changes = Object.keys(config.future)%0A      .filter(flag =%3E featureFlags.future.includes(flag) && config.future%5Bflag%5D
+futureFlagsEnabled(config).length %3E 0) %7B%0A    const changes = futureFlagsEnabled(config
 )%0A  
@@ -1605,32 +1605,33 @@
     .join(', ')%0A
+%0A
     console.log(
@@ -1852,243 +1852,106 @@
 if (
-_.some(featureFlags.experimental, flag =%3E _.get(config, %5B'experimental', flag%5D, false))) %7B%0A    const changes = Object.keys(config.experimental)%0A      .filter(flag =%3E featureFlags.experimental.includes(flag) && config.experimental%5Bflag%5D
+experimentalFlagsEnabled(config).length %3E 0) %7B%0A    const changes = experimentalFlagsEnabled(config
 )%0A  
@@ -1991,32 +1991,33 @@
     .join(', ')%0A
+%0A
     console.log(
@@ -2237,84 +2237,47 @@
 if (
-Object.keys(_.get(config, 'future', %7B%7D)).length %3C featureFlags.future.length
+futureFlagsAvailable(config).length %3E 0
 ) %7B%0A
@@ -2297,18 +2297,17 @@
 nges = f
-ea
+u
 tureFlag
@@ -2311,70 +2311,24 @@
 lags
-.future%0A      .filter(flag =%3E !_.has(config, %5B'future', flag%5D)
+Available(config
 )%0A  
@@ -2377,16 +2377,17 @@
 n(', ')%0A
+%0A
     cons

Support 'all' keyword for feature flags