<commit_before>import React from 'react';
import { ThemeProvider } from 'styled-components';
import { mintTheme, aegeanTheme, noTheme, classicTheme } from '../../src/style/themes';
import addons, { makeDecorator } from '@storybook/addons';

export const ADDON_ID = 'carbon/theme-selector';
export const PARAMS_EVENT = `${ADDON_ID}/params`
const LOCAL_STORAGE_KEY = `${ADDON_ID}/theme`

export const modernThemes = [mintTheme, aegeanTheme, noTheme].reduce((themesObject, theme) => {
  themesObject[theme.name] = theme;
  return themesObject
}, {});

export function getThemeName() {
  const theme = new URLSearchParams(window.location.search).get('theme');
  return theme || window.localStorage.getItem(LOCAL_STORAGE_KEY) || mintTheme.name;
}

export function setThemeName(themeName) {
  return window.localStorage.setItem(LOCAL_STORAGE_KEY, themeName);
}

export const withThemeSelector = makeDecorator({
  name: 'withThemeSelector',
  parameterName: 'themeSelector',
  skipIfNoParametersOrOptions: false,
  allowDeprecatedUsage: false,
  wrapper: (getStory, context, { parameters = {} }) => {
    const theme = parameters.isClassic ? classicTheme : modernThemes[getThemeName()];
    const channel = addons.getChannel();
    channel.emit(PARAMS_EVENT, parameters);
    return (
      <ThemeProvider theme={theme}>
        {getStory(context)}
      </ThemeProvider>
    )<commit_msg>docs(storybook): add classic removal warning<commit_after>import React from 'react';
import { ThemeProvider } from 'styled-components';
import { mintTheme, aegeanTheme, noTheme, classicTheme } from '../../src/style/themes';
import addons, { makeDecorator } from '@storybook/addons';
import DeprecationWarning from "../../src/__internal__/DeprecationWarning";

export const ADDON_ID = 'carbon/theme-selector';
export const PARAMS_EVENT = `${ADDON_ID}/params`
const LOCAL_STORAGE_KEY = `${ADDON_ID}/theme`

export const modernThemes = [mintTheme, aegeanTheme, noTheme].reduce((themesObject, theme) => {
  themesObject[theme.name] = theme;
  return themesObject
}, {});

export function getThemeName() {
  const theme = new URLSearchParams(window.location.search).get('theme');
  return theme || window.localStorage.getItem(LOCAL_STORAGE_KEY) || mintTheme.name;
}

export function setThemeName(themeName) {
  return window.localStorage.setItem(LOCAL_STORAGE_KEY, themeName);
}

export const withThemeSelector = makeDecorator({
  name: 'withThemeSelector',
  parameterName: 'themeSelector',
  skipIfNoParametersOrOptions: false,
  allowDeprecatedUsage: false,
  wrapper: (getStory, context, { parameters = {} }) => {
    const theme = parameters.isClassic ? classicTheme : modernThemes[getThemeName()];
    const channel = addons.getChannel();
    channel.emit(PARAMS_EVENT, parameters);
    return (
      <ThemeProvider theme={theme}>
        {parameters.isClassic && <DeprecationWarning>Classic theme is not supported and is being removed</DeprecationWarning>}
        {getStory(context)}
      </ThemeProvider>
    )
{'fraction_non_alphanumeric': 0.12541694462975317, 'fraction_numerical': 0.0, 'mean_word_length': 5.353813559322034, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, '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': '107514', 'n_tokens_mistral': 898, 'n_tokens_neox': 891, 'n_words': 198}