import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
import { _ as _object_without_properties } from "@swc/helpers/_/_object_without_properties";
import React from "react";
import { Check, Location } from "@nutui/icons-react";
import { useConfig } from "../configprovider";
var defaultProps = {
    type: 'custom',
    existList: [],
    defaultIcon: null,
    selectIcon: null,
    custom: false
};
export var ExistRender = function(props) {
    var locale = useConfig().locale;
    var _ref = _object_spread({}, defaultProps, props), children = _ref.children, type = _ref.type, existList = _ref.existList, selectIcon = _ref.selectIcon, defaultIcon = _ref.defaultIcon, custom = _ref.custom, onSelect = _ref.onSelect, onSwitch = _ref.onSwitch, rest = _object_without_properties(_ref, [
        "children",
        "type",
        "existList",
        "selectIcon",
        "defaultIcon",
        "custom",
        "onSelect",
        "onSwitch"
    ]);
    var classPrefix = 'nut-address';
    var selectedExist = function(item) {
        existList.forEach(function(list, index) {
            ;
            list.selectedAddress = false;
        });
        item.selectedAddress = true;
        onSelect && onSelect(item);
    };
    var onClick = function(e) {
        e.stopPropagation();
        onSwitch && onSwitch({
            type: type === 'exist' ? 'custom' : 'exist'
        });
    };
    return /*#__PURE__*/ React.createElement(React.Fragment, null, /*#__PURE__*/ React.createElement("ul", {
        className: "".concat(classPrefix, "-exist")
    }, existList.map(function(item, index) {
        return /*#__PURE__*/ React.createElement("li", {
            className: "".concat(classPrefix, "-exist-item ").concat(item.selectedAddress ? 'active' : ''),
            key: index,
            onClick: function(e) {
                e.stopPropagation();
                selectedExist(item);
            }
        }, item.selectedAddress ? /*#__PURE__*/ React.createElement(React.Fragment, null, /*#__PURE__*/ React.isValidElement(selectIcon) ? selectIcon : /*#__PURE__*/ React.createElement(Check, {
            color: "var(--nutui-color-primary)"
        })) : /*#__PURE__*/ React.createElement(React.Fragment, null, /*#__PURE__*/ React.isValidElement(defaultIcon) ? defaultIcon : /*#__PURE__*/ React.createElement(Location, null)), /*#__PURE__*/ React.createElement("div", {
            className: "".concat(classPrefix, "-exist-item-info")
        }, item.name && item.phone && /*#__PURE__*/ React.createElement(React.Fragment, null, /*#__PURE__*/ React.createElement("div", null, item.name), /*#__PURE__*/ React.createElement("div", null, item.phone)), /*#__PURE__*/ React.createElement("div", null, item.provinceName + item.cityName + item.countyName + item.townName + item.addressDetail)));
    })), (custom || custom && locale.address.chooseAnotherAddress) && /*#__PURE__*/ React.createElement("div", {
        className: "".concat(classPrefix, "-footer"),
        onClick: onClick
    }, /*#__PURE__*/ React.createElement("div", {
        className: "".concat(classPrefix, "-footer-btn")
    }, custom)));
};
