function _typeof(obj) { 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); }

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

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }

function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

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

import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import ConfigProvider from '../config-provider';
import Icon from '../icon';
import { func, KEYCODE } from '../util';
/** Collapse.Panel */

var Panel =
/*#__PURE__*/
function (_React$Component) {
  _inherits(Panel, _React$Component);

  function Panel() {
    var _getPrototypeOf2;

    var _this;

    _classCallCheck(this, Panel);

    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    _this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(Panel)).call.apply(_getPrototypeOf2, [this].concat(args)));

    _defineProperty(_assertThisInitialized(_this), "onKeyDown", function (e) {
      var keyCode = e.keyCode;

      if (keyCode === KEYCODE.SPACE) {
        var onClick = _this.props.onClick;
        e.preventDefault();
        onClick && onClick(e);
      }
    });

    _defineProperty(_assertThisInitialized(_this), "renderTitleIcon", function () {
      var _this$props = _this.props,
          prefix = _this$props.prefix,
          icon = _this$props.icon;

      if (icon) {
        if (typeof icon === 'string') {
          return React.createElement("span", {
            className: "".concat(prefix, "collapse-panel-title-icon")
          }, React.createElement(Icon, {
            type: icon
          }));
        } else {
          return React.createElement("span", {
            className: "".concat(prefix, "collapse-panel-title-icon")
          }, icon);
        }
      }

      return null;
    });

    return _this;
  }

  _createClass(Panel, [{
    key: "render",
    value: function render() {
      var _classNames, _classNames2;

      var _this$props2 = this.props,
          title = _this$props2.title,
          icon = _this$props2.icon,
          children = _this$props2.children,
          className = _this$props2.className,
          isExpanded = _this$props2.isExpanded,
          disabled = _this$props2.disabled,
          style = _this$props2.style,
          prefix = _this$props2.prefix,
          onClick = _this$props2.onClick,
          id = _this$props2.id,
          others = _objectWithoutProperties(_this$props2, ["title", "icon", "children", "className", "isExpanded", "disabled", "style", "prefix", "onClick", "id"]);

      var cls = classNames((_classNames = {}, _defineProperty(_classNames, "".concat(prefix, "collapse-panel"), true), _defineProperty(_classNames, "".concat(prefix, "collapse-panel-expanded"), isExpanded), _defineProperty(_classNames, "".concat(prefix, "collapse-panel-disabled"), disabled), _defineProperty(_classNames, className, className), _classNames));
      var iconCls = classNames((_classNames2 = {}, _defineProperty(_classNames2, "".concat(prefix, "collapse-panel-icon"), true), _defineProperty(_classNames2, "".concat(prefix, "collapse-panel-icon-expanded"), isExpanded), _classNames2)); // 为了无障碍 需要添加两个id

      var headingId = id ? "".concat(id, "-heading") : undefined;
      var regionId = id ? "".concat(id, "-region") : undefined;
      return React.createElement("div", _extends({
        className: cls,
        style: style,
        id: id
      }, others), React.createElement("div", {
        id: headingId,
        className: "".concat(prefix, "collapse-panel-title"),
        onClick: onClick,
        onKeyDown: this.onKeyDown,
        tabIndex: "0",
        "aria-disabled": disabled,
        "aria-expanded": isExpanded,
        "aria-controls": regionId,
        role: "button"
      }, React.createElement(Icon, {
        type: "triangle-up-s",
        className: iconCls,
        "aria-hidden": "true"
      }), this.renderTitleIcon(), React.createElement("span", {
        className: "".concat(prefix, "collapse-panel-title-text")
      }, title)), React.createElement("div", {
        className: "".concat(prefix, "collapse-panel-content"),
        role: "region",
        id: regionId
      }, children));
    }
  }]);

  return Panel;
}(React.Component);

_defineProperty(Panel, "propTypes", {
  /**
   * 样式类名的品牌前缀
   */
  prefix: PropTypes.string,

  /**
   * 子组件接受行内样式
   */
  style: PropTypes.object,
  children: PropTypes.any,
  isExpanded: PropTypes.bool,

  /**
   * 是否禁止用户操作
   */
  disabled: PropTypes.bool,

  /**
   * 标题
   */
  title: PropTypes.node,

  /**
   * 标题前的icon
   */
  icon: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),

  /**
   * 扩展class
   */
  className: PropTypes.string,
  onClick: PropTypes.func,
  id: PropTypes.string
});

_defineProperty(Panel, "defaultProps", {
  prefix: 'next-',
  isExpanded: false,
  onClick: func.noop
});

_defineProperty(Panel, "isNextPanel", true);

export default ConfigProvider.config(Panel);