import { __rest, __assign } from 'tslib';
import { Customizations } from '@uifabric-vue/utilities';
import { concatStyleSetsWithProps } from '@uifabric/merge-styles';
import { getTheme, registerOnThemeChangeCallback } from '@uifabric/styling';
import Vue from 'vue';

var DefaultFields = ["theme", "styles"];
function styled(Component, baseStyles, getProps, customizable, pure) {
  var _a, _b;
  customizable = customizable || { scope: "", fields: void 0 };
  var scope = customizable.scope, _c = customizable.fields, fields = _c === void 0 ? DefaultFields : _c;
  var _styles;
  return Vue.extend({
    name: "Styled".concat(((_a = Component === null || Component === void 0 ? void 0 : Component.extendOptions) === null || _a === void 0 ? void 0 : _a.name) || Component.displayName || Component.name),
    inheritAttrs: false,
    model: (_b = Component === null || Component === void 0 ? void 0 : Component.options) === null || _b === void 0 ? void 0 : _b.model,
    props: typeof Component === "function" ? Component.options.props : Component.props,
    data: function() {
      return {
        $theme: getTheme()
      };
    },
    created: function() {
      var _this = this;
      registerOnThemeChangeCallback(function(theme) {
        _this.$data.$theme = theme;
      });
    },
    render: function(h) {
      var _this = this;
      var settings = Customizations.getSettings(fields, scope);
      var customizedStyles = settings.styles; settings.dir; var rest = __rest(settings, ["styles", "dir"]);
      var additionalProps = getProps ? getProps(this) : void 0;
      if (!_styles || customizedStyles !== _styles.__cachedInputs__[1] || !!this.styles) {
        _styles = function(styleProps) {
          return concatStyleSetsWithProps(styleProps, baseStyles, _this.styles);
        };
        _styles.__cachedInputs__ = [baseStyles, this.styles];
      }
      return h(Component, {
        on: this.$listeners,
        attrs: this.$attrs,
        props: __assign(__assign(__assign(__assign(__assign({}, rest), additionalProps), this.$attrs), this.$props), { theme: this.$data.$theme, className: this.className || this.$attrs.class || this.$vnode.data.class, styles: _styles }),
        scopedSlots: this.$scopedSlots
      }, this.$slots.default);
    }
  });
}

export { styled };
