function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

/*
Copyright (c) 2018-2019 Uber Technologies, Inc.

This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
*/
import * as React from 'react';
import { createStyled, withStyle as styletronWithStyle, useStyletron as styletronUseStyletron } from 'styletron-react';
import { driver, getInitialStyle } from 'styletron-standard';
import { ThemeContext } from './theme-provider.js';

const wrapper = StyledComponent => {
  return React.forwardRef((props, ref) => React.createElement(ThemeContext.Consumer, null, theme => React.createElement(StyledComponent, _extends({
    ref: ref
  }, props, {
    $theme: theme
  }))));
};
/* eslint-disable flowtype/generic-spacing */

/* eslint-disable flowtype/no-weak-types */


/* eslint-enable flowtype/generic-spacing */

/* eslint-enable flowtype/no-weak-types */
export function createThemedStyled() {
  return createStyled({
    wrapper,
    getInitialStyle,
    driver // eslint-disable-next-line flowtype/no-weak-types

  });
}
export const styled = createThemedStyled();
export function createThemedWithStyle() {
  // eslint-disable-next-line flowtype/no-weak-types
  return styletronWithStyle;
}
export const withStyle = createThemedWithStyle();
export function createThemedUseStyletron() {
  return function () {
    // eslint-disable-next-line flowtype/no-weak-types
    const theme = React.useContext(ThemeContext);
    const [useCss] = styletronUseStyletron();
    return [useCss, theme];
  };
}
export const useStyletron = createThemedUseStyletron();