import _extends from "@babel/runtime/helpers/esm/extends";
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
import { useStyleRegister } from '@ant-design/cssinjs';
import { useContext } from 'react';
import { genLinkStyle } from '../../style';
import { ConfigContext } from '../../config-provider/context';
import { mergeToken, statisticToken, useToken } from '../index';
import warning from '../../_util/warning';
export default function genComponentStyleHook(component, styleFn, getDefaultToken) {
  return function (prefixCls) {
    var _useToken = useToken(),
        _useToken2 = _slicedToArray(_useToken, 3),
        theme = _useToken2[0],
        token = _useToken2[1],
        hashId = _useToken2[2];

    var _useContext = useContext(ConfigContext),
        getPrefixCls = _useContext.getPrefixCls,
        iconPrefixCls = _useContext.iconPrefixCls;

    var rootPrefixCls = getPrefixCls();

    if (process.env.NODE_ENV !== 'production' && process.env.NODE_ENV !== 'test') {
      /* istanbul ignore next */
      process.env.NODE_ENV !== "production" ? warning(false, 'Next', '\n\nYou are using dev version, ' + 'which is used for validating and may not same as final release version.\n\n' + 'DO NOT USE IN YOUR PRODUCTION!\n\n' + 'Ref:#33862 - What is in experimental?\n' + 'https://github.com/ant-design/ant-design/issues/33862#user-content-alpha-offset') : void 0;
    } // Generate style for all a tags in antd component.


    useStyleRegister({
      theme: theme,
      token: token,
      hashId: hashId,
      path: ['Link']
    }, function () {
      return {
        '&': genLinkStyle(token)
      };
    });
    return [useStyleRegister({
      theme: theme,
      token: token,
      hashId: hashId,
      path: [component, prefixCls]
    }, function () {
      var _statisticToken = statisticToken(token),
          proxyToken = _statisticToken.token,
          flush = _statisticToken.flush;

      var defaultComponentToken = typeof getDefaultToken === 'function' ? getDefaultToken(proxyToken) : getDefaultToken;
      var overrideComponentToken = token[component]; // Only merge token specified in interface

      var mergedComponentToken = _extends({}, defaultComponentToken);

      if (overrideComponentToken) {
        Object.keys(mergedComponentToken).forEach(function (key) {
          var _a;

          mergedComponentToken[key] = (_a = overrideComponentToken[key]) !== null && _a !== void 0 ? _a : mergedComponentToken[key];
        });
      }

      var componentCls = ".".concat(prefixCls);
      var mergedToken = mergeToken(proxyToken, {
        componentCls: componentCls,
        prefixCls: prefixCls,
        iconCls: ".".concat(iconPrefixCls),
        antCls: ".".concat(rootPrefixCls)
      }, mergedComponentToken);
      var styleInterpolation = styleFn(mergedToken, {
        hashId: hashId,
        prefixCls: prefixCls,
        rootPrefixCls: rootPrefixCls,
        iconPrefixCls: iconPrefixCls
      });
      flush(component, mergedComponentToken);
      return styleInterpolation;
    }), hashId];
  };
}