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); }

import * as React from 'react';
import { JssProvider, ThemeProvider as BaseProvider } from '@fluent-ui/styles';
import createTheme from '../styles/createTheme';

const generateId = (rule, sheet) => {
  const prefix = sheet && sheet.options.classNamePrefix.replace(/-/g, '');
  return prefix ? `F${prefix}-${rule.key}` : rule.key;
};

const ThemeProvider = ({
  theme,
  registry,
  children,
  ...rest
}) => {
  const customTheme = createTheme(theme);
  return React.createElement(JssProvider, _extends({
    generateId: generateId,
    registry: registry
  }, rest), React.createElement(BaseProvider, {
    theme: customTheme
  }, children));
};

export default ThemeProvider;