/**
 * tdesign v0.32.0
 * (c) 2021 tdesign
 * @license MIT
 */

import { h as helper } from '../_chunks/dep-42d5c87e.js';
import _typeof from '@babel/runtime/helpers/typeof';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { CloseIcon } from 'tdesign-icons-vue';
import { prefix } from '../config.js';
import { Button } from '../button/index.js';
import props from './props.js';
import { renderContent, renderTNodeJSX } from '../utils/render-tnode.js';
import mixins from '../utils/mixins.js';
import getConfigReceiverMixins from '../config-provider/config-receiver.js';
import TransferDom from '../utils/transfer-dom.js';
import { emitEvent } from '../utils/event.js';
import ActionMixin from '../dialog/actions.js';
import '../button/button.js';
import 'vue';
import '../utils/classnames.js';
import '../loading/index.js';
import '../loading/loading.js';
import '../loading/icon/gradient.js';
import '../utils/set-style.js';
import '../utils/dom.js';
import 'raf';
import 'lodash/isString';
import '../utils/easing.js';
import '../loading/props.js';
import '../utils/withInstall.js';
import 'lodash/capitalize';
import './style/index.js';
import '../loading/type.js';
import '../loading/plugin.js';
import '../button/props.js';
import '../utils/ripple.js';
import '../button/type.js';
import '../config-provider/zh_CN_config.js';
import '../config-provider/type.js';
import '../utils/helper.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import '@babel/runtime/helpers/slicedToArray';
import 'lodash/camelCase';
import 'lodash/isObject';

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
var name = "".concat(prefix, "-drawer");
var _Drawer = mixins(ActionMixin, getConfigReceiverMixins("drawer")).extend({
  name: "TDrawer",
  components: {
    TIconClose: CloseIcon,
    TButton: Button
  },
  props: _objectSpread({}, props),
  directives: {
    TransferDom: TransferDom
  },
  computed: {
    drawerClasses: function drawerClasses() {
      var _ref;

      return [name, "".concat(name, "--").concat(this.placement), (_ref = {}, _defineProperty(_ref, "".concat(name, "--open"), this.visible), _defineProperty(_ref, "".concat(name, "--attach"), this.showInAttachedElement), _defineProperty(_ref, "".concat(name, "--without-mask"), !this.showOverlay), _ref)];
    },
    sizeValue: function sizeValue() {
      var defaultSize = isNaN(Number(this.size)) ? this.size : "".concat(this.size, "px");
      return {
        small: "300px",
        medium: "500px",
        large: "760px"
      }[this.size] || defaultSize;
    },
    wrapperStyles: function wrapperStyles() {
      return {
        transform: this.visible ? "translateX(0)" : void 0,
        width: ["left", "right"].includes(this.placement) ? this.sizeValue : "",
        height: ["top", "bottom"].includes(this.placement) ? this.sizeValue : ""
      };
    },
    wrapperClasses: function wrapperClasses() {
      return ["".concat(name, "__content-wrapper"), "".concat(name, "__content-wrapper--").concat(this.placement)];
    },
    parentNode: function parentNode() {
      return this.$el && this.$el.parentNode;
    },
    modeAndPlacement: function modeAndPlacement() {
      return [this.mode, this.placement].join();
    },
    footerStyle: function footerStyle() {
      return {
        display: "flex",
        justifyContent: this.placement === "right" ? "flex-start" : "flex-end"
      };
    }
  },
  watch: {
    modeAndPlacement: {
      handler: function handler() {
        this.handlePushMode();
      },
      immediate: true
    }
  },
  updated: function updated() {
    this.updatePushMode();
  },
  render: function render() {
    var h = arguments[0];
    if (this.destroyOnClose && !this.visible) return;
    var defaultCloseBtn = h("t-icon-close", {
      "class": "t-submenu-icon"
    });
    var body = renderContent(this, "default", "body");
    var defaultFooter = this.getDefaultFooter();
    return h("div", {
      "class": this.drawerClasses,
      "style": {
        zIndex: this.zIndex
      },
      "on": {
        "keydown": this.onKeyDown
      },
      "directives": [{
        name: "transfer-dom",
        value: this.attach
      }]
    }, [this.showOverlay && h("div", {
      "class": "".concat(name, "__mask"),
      "on": {
        "click": this.handleWrapperClick
      }
    }), h("div", {
      "class": this.wrapperClasses,
      "style": this.wrapperStyles
    }, [this.header !== false ? h("div", {
      "class": "".concat(name, "__header")
    }, [renderTNodeJSX(this, "header")]) : null, this.closeBtn !== false ? h("div", {
      "class": "".concat(name, "__close-btn"),
      "on": {
        "click": this.handleCloseBtnClick
      }
    }, [renderTNodeJSX(this, "closeBtn", defaultCloseBtn)]) : null, h("div", {
      "class": "".concat(name, "__body")
    }, [body]), this.footer !== false ? h("div", {
      "class": "".concat(name, "__footer")
    }, [renderTNodeJSX(this, "footer", defaultFooter)]) : null])]);
  },
  methods: {
    handlePushMode: function handlePushMode() {
      var _this = this;

      if (this.mode !== "push") return;
      this.$nextTick(function () {
        if (!_this.parentNode) return;
        _this.parentNode.style.cssText = "transition: margin 300ms cubic-bezier(0.7, 0.3, 0.1, 1) 0s;";
      });
    },
    updatePushMode: function updatePushMode() {
      if (!this.parentNode) return;
      if (this.mode !== "push" || !this.parentNode) return;
      var marginStr = {
        left: "margin: 0 0 0 ".concat(this.sizeValue),
        right: "margin: 0 0 0 -".concat(this.sizeValue),
        top: "margin: ".concat(this.sizeValue, " 0 0 0"),
        bottom: "margin: -".concat(this.sizeValue, " 0 0 0")
      }[this.placement];

      if (this.visible) {
        this.parentNode.style.cssText += marginStr;
      } else {
        this.parentNode.style.cssText = this.parentNode.style.cssText.replace(/margin:.+;/, "");
      }
    },
    getDefaultBtn: function getDefaultBtn(btnType, btnApi) {
      var h = this.$createElement;
      var isCancel = btnType === "cancel";
      var clickAction = isCancel ? this.cancelBtnAction : this.confirmBtnAction;
      var theme = isCancel ? "default" : "primary";
      var isApiObject = _typeof(btnApi) === "object";
      return h("t-button", helper([{
        "attrs": {
          "theme": theme
        },
        "on": {
          "click": clickAction
        }
      }, {
        "props": isApiObject ? btnApi : {}
      }, {
        "class": "".concat(name, "-").concat(btnType)
      }]), [btnApi && _typeof(btnApi) === "object" ? btnApi.content : btnApi]);
    },
    isUseDefault: function isUseDefault(btnApi) {
      var baseTypes = ["string", "object"];
      return Boolean(btnApi && baseTypes.includes(_typeof(btnApi)));
    },
    getDefaultFooter: function getDefaultFooter() {
      var h = this.$createElement;
      var confirmBtn = this.getConfirmBtn({
        confirmBtn: this.confirmBtn,
        globalConfirm: this.global.confirm,
        className: "".concat(prefix, "-drawer__confirm")
      });
      var cancelBtn = this.getCancelBtn({
        cancelBtn: this.cancelBtn,
        globalCancel: this.global.cancel,
        className: "".concat(prefix, "-drawer__cancel")
      });
      return h("div", {
        "style": this.footerStyle
      }, [this.placement === "right" ? confirmBtn : null, cancelBtn, this.placement !== "right" ? confirmBtn : null]);
    },
    handleCloseBtnClick: function handleCloseBtnClick(e) {
      emitEvent(this, "close-btn-click", {
        e: e
      });
      this.closeDrawer({
        trigger: "close-btn",
        e: e
      });
    },
    handleWrapperClick: function handleWrapperClick(e) {
      emitEvent(this, "overlay-click", {
        e: e
      });

      if (this.closeOnOverlayClick) {
        this.closeDrawer({
          trigger: "overlay",
          e: e
        });
      }
    },
    onKeyDown: function onKeyDown(e) {
      if (e.key === "Escape") {
        emitEvent(this, "esc-keydown", {
          e: e
        });

        if (this.closeOnEscKeydown) {
          this.closeDrawer({
            trigger: "esc",
            e: e
          });
        }
      }
    },
    confirmBtnAction: function confirmBtnAction(e) {
      emitEvent(this, "confirm", {
        e: e
      });
    },
    cancelBtnAction: function cancelBtnAction(e) {
      emitEvent(this, "cancel", {
        e: e
      });
      this.closeDrawer({
        trigger: "cancel",
        e: e
      });
    },
    closeDrawer: function closeDrawer(params) {
      emitEvent(this, "close", params);
      this.$emit("update:visible", false);
    }
  }
});

export { _Drawer as default };
//# sourceMappingURL=drawer.js.map
