"use strict";

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

require("./demo14.css");

var _react = _interopRequireDefault(require("react"));

var _reactDom = _interopRequireDefault(require("react-dom"));

var _ = _interopRequireDefault(require(".."));

var _classnames = _interopRequireDefault(require("classnames"));

var _excluded = ["className"];

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": 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); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }

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 } }); Object.defineProperty(subClass, "prototype", { writable: false }); 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 _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }

function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }

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

function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }

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

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

/* eslint-disable react/prop-types, react/no-multi-comp */
// prevent onBlur
function preventDefault(e) {
  e.preventDefault();
}

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

  var _super = _createSuper(CustomMenu);

  function CustomMenu(props) {
    var _this;

    _classCallCheck(this, CustomMenu);

    _this = _super.call(this, props);

    _defineProperty(_assertThisInitialized(_this), "data", void 0);

    _this.data = [{
      label: 'value1',
      value: 1
    }, {
      label: 'value2',
      value: 2
    }];
    return _this;
  }

  _createClass(CustomMenu, [{
    key: "onClick",
    value: function onClick(item) {
      this.props.onChange(item);
    }
  }, {
    key: "renderItems",
    value: function renderItems() {
      var _this2 = this;

      return this.data.map(function (item) {
        return /*#__PURE__*/_react["default"].createElement("li", {
          onClick: _this2.onClick.bind(_this2, item),
          key: item.value
        }, item.label);
      });
    }
  }, {
    key: "render",
    value: function render() {
      var _this$props = this.props,
          className = _this$props.className,
          others = _objectWithoutProperties(_this$props, _excluded);

      var cls = (0, _classnames["default"])('overlay-content', className);
      return /*#__PURE__*/_react["default"].createElement("ul", _extends({
        className: cls
      }, others), this.renderItems());
    }
  }]);

  return CustomMenu;
}(_react["default"].Component);

var Demo = /*#__PURE__*/function (_React$Component2) {
  _inherits(Demo, _React$Component2);

  var _super2 = _createSuper(Demo);

  function Demo(props) {
    var _this3;

    _classCallCheck(this, Demo);

    _this3 = _super2.call(this, props);

    _defineProperty(_assertThisInitialized(_this3), "handleSelect", void 0);

    _defineProperty(_assertThisInitialized(_this3), "onVisibleChange", void 0);

    _this3.handleSelect = function (value) {
      _this3.setState({
        value: value,
        visible: false
      });
    };

    _this3.onVisibleChange = function (visible) {
      _this3.setState({
        visible: visible
      });
    };

    _this3.state = {
      value: null,
      visible: false
    };
    return _this3;
  }

  _createClass(Demo, [{
    key: "render",
    value: function render() {
      var popupContent = /*#__PURE__*/_react["default"].createElement("div", {
        style: {
          border: '1px solid',
          background: 'white'
        }
      }, /*#__PURE__*/_react["default"].createElement("div", {
        style: {
          borderBottom: '1px solid',
          background: 'white',
          padding: 10,
          fontSize: '12px'
        }
      }, "custom header"), /*#__PURE__*/_react["default"].createElement(CustomMenu, {
        className: "",
        onChange: this.handleSelect,
        onMouseDown: preventDefault
      }), /*#__PURE__*/_react["default"].createElement("div", {
        style: {
          borderTop: '1px solid',
          background: 'white',
          padding: 10,
          fontSize: '12px'
        }
      }, "custom footer"));

      var popupProps = {
        triggerClickKeycode: [13, 32, 40] // space, enter, down-arrow

      };
      return /*#__PURE__*/_react["default"].createElement("div", {
        className: "demo-container"
      }, /*#__PURE__*/_react["default"].createElement(_["default"], {
        placeholder: "custom popupContent",
        visible: this.state.visible,
        onVisibleChange: this.onVisibleChange,
        value: this.state.value,
        popupProps: popupProps,
        popupContent: popupContent,
        style: {
          width: 200
        }
      }));
    }
  }]);

  return Demo;
}(_react["default"].Component);

_reactDom["default"].render( /*#__PURE__*/_react["default"].createElement(Demo, null), document.getElementById('select-demo-14'));