"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports["default"] = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
var _react = _interopRequireWildcard(require("react"));
require("./index.scss");
var _addressListItem = _interopRequireDefault(require("./address-list-item"));
var _excluded = ["dataList", "onClick", "onSelect", "children"];
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
/**
 * 数据
 */

var AddressList = function AddressList(_ref) {
  var dataList = _ref.dataList,
    _ref$onClick = _ref.onClick,
    onClick = _ref$onClick === void 0 ? function () {} : _ref$onClick,
    onSelect = _ref.onSelect,
    children = _ref.children,
    otherProps = (0, _objectWithoutPropertiesLoose2["default"])(_ref, _excluded);
  var _useState = (0, _react.useState)(-1),
    selectedIndex = _useState[0],
    setSelectedIndex = _useState[1];
  var _otherProps = otherProps || {};
  var handleSelect = function handleSelect(index) {
    setSelectedIndex(index);
    onSelect === null || onSelect === void 0 ? void 0 : onSelect(index);
  };
  return /*#__PURE__*/_react["default"].createElement("div", (0, _extends2["default"])({
    className: "address-list"
  }, _otherProps), dataList ? dataList.map(function (item, index) {
    return /*#__PURE__*/_react["default"].createElement(_addressListItem["default"], (0, _extends2["default"])({
      key: index,
      onClick: function onClick() {
        return handleSelect(index);
      },
      selected: selectedIndex === index,
      onRemove: function onRemove() {
        return console.log('remove', index);
      },
      onEdit: function onEdit() {
        return console.log('edit', index);
      }
    }, item), children);
  }) : /*#__PURE__*/_react["default"].createElement("div", null, "\u6682\u65E0\u6570\u636E"));
};
AddressList.displayName = 'AddressList';
var _default = exports["default"] = AddressList;