/* eslint-disable @typescript-eslint/camelcase */
import { createContext } from "react";
import { Locale } from "../i18n";
import { AttachContainer } from "../_util/get-overlay-root";

declare const TEA_CLASS_PREFIX: string;
declare const WEBPACK_BUILD_LOCALE: "zh" | "en" | "ko" | "ja";

// 支持 webpack 注入
export const DEFAULT_CLASS_PREFIX =
  typeof TEA_CLASS_PREFIX !== "undefined" ? TEA_CLASS_PREFIX : "tea";
export const DEFAULT_LOCALE =
  typeof WEBPACK_BUILD_LOCALE !== "undefined" ? WEBPACK_BUILD_LOCALE : "zh";

export interface Config {
  /**
   * 组件类名前缀
   *
   * @default "tea"
   */
  classPrefix?: string;

  /**
   * 组件语言包配置
   *
   * **内置语言包可从组件 [/lib/i18n/locale](https://unpkg.com/tea-component/lib/i18n/locale/) 目录下引入**
   *
   * @docType Locale
   */
  locale?: "zh" | "en" | "ko" | "ja" | Locale;

  /**
   * 挂载弹出组件的结点
   * @default document.body
   * @since 2.5.0
   */
  popupContainer?: AttachContainer;
}

export const ConfigContext = createContext<Config>({
  classPrefix: DEFAULT_CLASS_PREFIX,
  locale: DEFAULT_LOCALE,
});
