import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
var _excluded = ["dataList", "onClick", "onSelect", "children"];
import React, { useState } from 'react';
import "./index.scss";
import AddressListItem from "./address-list-item";

/**
 * 数据
 */

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 = _objectWithoutPropertiesLoose(_ref, _excluded);
  var _useState = 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.createElement("div", _extends({
    className: "address-list"
  }, _otherProps), dataList ? dataList.map(function (item, index) {
    return /*#__PURE__*/React.createElement(AddressListItem, _extends({
      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.createElement("div", null, "\u6682\u65E0\u6570\u636E"));
};
AddressList.displayName = 'AddressList';
export default AddressList;