"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _vue = _interopRequireWildcard(require("vue"));

var _PanelContent = _interopRequireDefault(require("./PanelContent"));

var _propsUtil = require("../../_util/props-util");

var _commonProps = require("./commonProps");

var _BaseMixin = _interopRequireDefault(require("../../_util/BaseMixin"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (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 = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

var _default2 = {
  name: 'Panel',
  mixins: [_BaseMixin.default],
  props: (0, _propsUtil.initDefaultProps)((0, _commonProps.panelProps)(), {
    showArrow: true,
    isActive: false,
    destroyInactivePanel: false,
    headerClass: '',
    forceRender: false
  }),
  methods: {
    handleItemClick: function handleItemClick() {
      this.__emit('itemClick', this.panelKey);
    },
    handleKeyPress: function handleKeyPress(e) {
      if (e.key === 'Enter' || e.keyCode === 13 || e.which === 13) {
        this.handleItemClick();
      }
    }
  },
  render: function render() {
    var _headerCls,
        _itemCls,
        _this = this;

    var _this$$props = this.$props,
        prefixCls = _this$$props.prefixCls,
        headerClass = _this$$props.headerClass,
        isActive = _this$$props.isActive,
        showArrow = _this$$props.showArrow,
        destroyInactivePanel = _this$$props.destroyInactivePanel,
        disabled = _this$$props.disabled,
        openAnimation = _this$$props.openAnimation,
        accordion = _this$$props.accordion,
        forceRender = _this$$props.forceRender,
        expandIcon = _this$$props.expandIcon,
        extra = _this$$props.extra;

    var transitionProps = _objectSpread({
      appear: true,
      css: false
    }, openAnimation);

    var headerCls = (_headerCls = {}, _defineProperty(_headerCls, "".concat(prefixCls, "-header"), true), _defineProperty(_headerCls, headerClass, headerClass), _headerCls);
    var header = (0, _propsUtil.getComponent)(this, 'header');
    var itemCls = (_itemCls = {}, _defineProperty(_itemCls, "".concat(prefixCls, "-item"), true), _defineProperty(_itemCls, "".concat(prefixCls, "-item-active"), isActive), _defineProperty(_itemCls, "".concat(prefixCls, "-item-disabled"), disabled), _itemCls);

    var icon = _vue.createVNode("i", {
      "class": "arrow"
    }, null);

    if (showArrow && typeof expandIcon === 'function') {
      icon = expandIcon(this.$props);
    }

    var panelContent = _vue.withDirectives(_vue.createVNode(_PanelContent.default, {
      "prefixCls": prefixCls,
      "isActive": isActive,
      "destroyInactivePanel": destroyInactivePanel,
      "forceRender": forceRender,
      "role": accordion ? 'tabpanel' : null
    }, {
      default: function _default() {
        return [(0, _propsUtil.getSlot)(_this)];
      }
    }), [[_vue.vShow, isActive]]);

    return _vue.createVNode("div", {
      "class": itemCls,
      "role": "tablist"
    }, [_vue.createVNode("div", {
      "class": headerCls,
      "onClick": this.handleItemClick,
      "onKeypress": this.handleKeyPress,
      "role": accordion ? 'tab' : 'button',
      "tabindex": disabled ? -1 : 0,
      "aria-expanded": isActive
    }, [showArrow && icon, header, extra && _vue.createVNode("div", {
      "class": "".concat(prefixCls, "-extra")
    }, [extra])]), _vue.createVNode(_vue.Transition, transitionProps, {
      default: function _default() {
        return [panelContent];
      }
    })]);
  }
};
exports.default = _default2;