import { computed } from 'vue';
import '../../../components/config-provider/src/context/index.mjs';
import '../../cssinjs/index.mjs';
import { genLinkStyle, genCommonStyle } from '../../style/index.mjs';
import { useToken } from '../internal.mjs';
import statisticToken, { merge } from './statistic.mjs';
import { useConfigContextInject } from '../../../components/config-provider/src/context/context.mjs';
import useStyleRegister from '../../cssinjs/hooks/useStyleRegister/index.mjs';

function genComponentStyleHook(component, styleFn, getDefaultToken) {
  return (_prefixCls) => {
    const prefixCls = computed(() => _prefixCls == null ? void 0 : _prefixCls.value);
    const [theme, token, hashId] = useToken();
    const { getPrefixCls, iconPrefixCls } = useConfigContextInject();
    const rootPrefixCls = computed(() => getPrefixCls());
    const sharedInfo = computed(() => {
      return {
        theme: theme.value,
        token: token.value,
        hashId: hashId.value,
        path: ["Shared", rootPrefixCls.value]
      };
    });
    useStyleRegister(sharedInfo, () => [
      {
        // Link
        "&": genLinkStyle(token.value)
      }
    ]);
    const componentInfo = computed(() => {
      return {
        theme: theme.value,
        token: token.value,
        hashId: hashId.value,
        path: [component, prefixCls.value, iconPrefixCls.value]
      };
    });
    return [
      useStyleRegister(componentInfo, () => {
        const { token: proxyToken, flush } = statisticToken(token.value);
        const defaultComponentToken = typeof getDefaultToken === "function" ? getDefaultToken(proxyToken) : getDefaultToken;
        const mergedComponentToken = { ...defaultComponentToken, ...token.value[component] };
        const componentCls = `.${prefixCls.value}`;
        const mergedToken = merge(
          proxyToken,
          {
            componentCls,
            prefixCls: prefixCls.value,
            iconCls: `.${iconPrefixCls.value}`,
            antCls: `.${rootPrefixCls.value}`
          },
          mergedComponentToken
        );
        const styleInterpolation = styleFn(mergedToken, {
          hashId: hashId.value,
          prefixCls: prefixCls.value,
          rootPrefixCls: rootPrefixCls.value,
          iconPrefixCls: iconPrefixCls.value,
          overrideComponentToken: token.value[component]
        });
        flush(component, mergedComponentToken);
        return [genCommonStyle(token.value, prefixCls.value), styleInterpolation];
      }),
      hashId
    ];
  };
}

export { genComponentStyleHook as default };
//# sourceMappingURL=genComponentStyleHook.mjs.map
