import { __extends, __decorate, __metadata } from 'tslib';
import { Prop, Component } from 'vue-property-decorator';
import BaseComponent from '../BaseComponent.js';
import { getBaseButtonClassNames } from './BaseButton.classNames.js';
import { DirectionalHint } from '../../common/DirectionalHint.js';
import { ContextualMenu } from '../ContextualMenu/ContextualMenu.js';
import { Icon } from '../Icon/Icon.js';
import { FontIcon } from '../Icon/FontIcon.js';

var BaseButton = function(_super) {
  __extends(BaseButton2, _super);
  function BaseButton2() {
    var _this = _super !== null && _super.apply(this, arguments) || this;
    _this.menuHidden = true;
    _this.menuOpen = false;
    return _this;
  }
  Object.defineProperty(BaseButton2.prototype, "MenuType", {
    get: function() {
      return this.menuAs || ContextualMenu;
    },
    enumerable: false,
    configurable: true
  });
  Object.defineProperty(BaseButton2.prototype, "component", {
    get: function() {
      var _a = this, disabled = _a.disabled, href = _a.href;
      var renderAsAnchor = !disabled && !!href;
      return renderAsAnchor ? "a" : "button";
    },
    enumerable: false,
    configurable: true
  });
  Object.defineProperty(BaseButton2.prototype, "isSplitButton", {
    get: function() {
      return !!this.menuProps && this.split === true;
    },
    enumerable: false,
    configurable: true
  });
  Object.defineProperty(BaseButton2.prototype, "shouldRenderMenu", {
    get: function() {
      var menuHidden = this.menuHidden;
      var _a = this, persistMenu = _a.persistMenu, renderPersistedMenuHiddenOnMount = _a.renderPersistedMenuHiddenOnMount;
      if (!menuHidden) {
        return true;
      } else if (persistMenu && renderPersistedMenuHiddenOnMount) {
        return true;
      }
      return false;
    },
    enumerable: false,
    configurable: true
  });
  Object.defineProperty(BaseButton2.prototype, "classNames", {
    get: function() {
      var _a = this, theme = _a.theme, styles = _a.styles, className = _a.className, iconProps = _a.iconProps, menuIconProps = _a.menuIconProps, variantClassName = _a.variantClassName, disabled = _a.disabled, primaryDisabled = _a.primaryDisabled, checked = _a.checked, getClassNames = _a.getClassNames;
      var isPrimaryButtonDisabled = disabled || primaryDisabled;
      return getClassNames ? getClassNames(theme, className, variantClassName, iconProps && iconProps.className, menuIconProps && menuIconProps.className, isPrimaryButtonDisabled, checked, !this.menuHidden, !!this.menuProps, this.split, !!this.allowDisabledFocus) : getBaseButtonClassNames(theme, styles, className, variantClassName, iconProps && iconProps.className, menuIconProps && menuIconProps.className, isPrimaryButtonDisabled, !!this.menuProps, checked, !this.menuHidden, this.split);
    },
    enumerable: false,
    configurable: true
  });
  BaseButton2.prototype.render = function(h) {
    var _this = this;
    var ButtonComponent = this.component;
    var MenuComponent = this.MenuType;
    var _a = this, classNames = _a.classNames, href = _a.href, iconProps = _a.iconProps, className = _a.className, css = _a.css, secondaryText = _a.secondaryText, isSplitButton = _a.isSplitButton, menuProps = _a.menuProps, menuIconProps = _a.menuIconProps, shouldRenderMenu = _a.shouldRenderMenu;
    return h(ButtonComponent, {
      ref: "buttonElement",
      class: classNames.root,
      attrs: { href: href },
      on: {
        click: function(ev) {
          return _this.$emit("click", ev);
        }
      }
    }, [
      h("span", { class: classNames.flexContainer }, [
        iconProps && h(Icon, {
          class: css(classNames.icon, className),
          props: iconProps
        }),
        this.$scopedSlots.flex && this.$scopedSlots.flex({}),
        this.$scopedSlots.default && h("span", { class: classNames.textContainer }, [
          h("span", { class: classNames.label }, this.$scopedSlots.default({})),
          secondaryText && h("span", { class: classNames.description }, secondaryText)
        ]),
        !isSplitButton && menuProps && h(FontIcon, {
          class: classNames.menuIcon,
          attrs: {
            iconName: "ChevronDown"
          },
          props: menuIconProps
        }),
        menuProps && !menuProps.doNotLayer && shouldRenderMenu && h(MenuComponent, {
          class: css("ms-BaseButton-menuhost", menuProps.className),
          attrs: {
            directionalHint: DirectionalHint.bottomLeftEdge,
            target: isSplitButton ? this.$refs.splitButtonContainer : this.$refs.buttonElement
          },
          props: menuProps,
          on: {
            dismiss: function() {
              return _this.menuHidden = true;
            }
          }
        })
      ])
    ]);
  };
  __decorate([
    Prop({ type: String, default: null }),
    __metadata("design:type", String)
  ], BaseButton2.prototype, "href", void 0);
  __decorate([
    Prop({ type: Boolean, default: false }),
    __metadata("design:type", Boolean)
  ], BaseButton2.prototype, "checked", void 0);
  __decorate([
    Prop({ type: Boolean, default: false }),
    __metadata("design:type", Boolean)
  ], BaseButton2.prototype, "split", void 0);
  __decorate([
    Prop({ type: Boolean, default: false }),
    __metadata("design:type", Boolean)
  ], BaseButton2.prototype, "disabled", void 0);
  __decorate([
    Prop({ type: Boolean, default: false }),
    __metadata("design:type", Boolean)
  ], BaseButton2.prototype, "primaryDisabled", void 0);
  __decorate([
    Prop({ type: Boolean, default: false }),
    __metadata("design:type", Boolean)
  ], BaseButton2.prototype, "allowDisabledFocus", void 0);
  __decorate([
    Prop({ type: String, default: null }),
    __metadata("design:type", String)
  ], BaseButton2.prototype, "variantClassName", void 0);
  __decorate([
    Prop({ type: Object, default: function() {
    } }),
    __metadata("design:type", Object)
  ], BaseButton2.prototype, "iconProps", void 0);
  __decorate([
    Prop({ type: Object, default: function() {
    } }),
    __metadata("design:type", Object)
  ], BaseButton2.prototype, "menuIconProps", void 0);
  __decorate([
    Prop({ type: Object, default: null }),
    __metadata("design:type", Object)
  ], BaseButton2.prototype, "menuAs", void 0);
  __decorate([
    Prop({ type: Object, default: null }),
    __metadata("design:type", Object)
  ], BaseButton2.prototype, "menuProps", void 0);
  __decorate([
    Prop({ type: Boolean, default: false }),
    __metadata("design:type", Boolean)
  ], BaseButton2.prototype, "persistMenu", void 0);
  __decorate([
    Prop({ type: Boolean, default: false }),
    __metadata("design:type", Boolean)
  ], BaseButton2.prototype, "renderPersistedMenuHiddenOnMount", void 0);
  __decorate([
    Prop({ type: String, default: null }),
    __metadata("design:type", String)
  ], BaseButton2.prototype, "secondaryText", void 0);
  __decorate([
    Prop({ type: Function, default: null }),
    __metadata("design:type", Function)
  ], BaseButton2.prototype, "getClassNames", void 0);
  BaseButton2 = __decorate([
    Component
  ], BaseButton2);
  return BaseButton2;
}(BaseComponent);

export { BaseButton };
