"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "ExistRender", {
    enumerable: true,
    get: function() {
        return ExistRender;
    }
});
var _interop_require_default = require("@swc/helpers/_/_interop_require_default");
var _object_spread = require("@swc/helpers/_/_object_spread");
var _object_without_properties = require("@swc/helpers/_/_object_without_properties");
var _react = /*#__PURE__*/ _interop_require_default._(require("react"));
var _iconsreacttaro = require("@nutui/icons-react-taro");
var _components = require("@tarojs/components");
var _index = require("../configprovider/index");
var defaultProps = {
    type: 'exist',
    existList: [],
    defaultIcon: null,
    selectIcon: null,
    custom: false
};
var ExistRender = function ExistRender(props) {
    var locale = (0, _index.useConfig)().locale;
    var _ref = (0, _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 = (0, _object_without_properties._)(_ref, [
        "children",
        "type",
        "existList",
        "selectIcon",
        "defaultIcon",
        "custom",
        "onSelect",
        "onSwitch"
    ]);
    var classPrefix = 'nut-address';
    var selectedExist = function selectedExist(item) {
        existList.forEach(function(list, index) {
            ;
            list.selectedAddress = false;
        });
        item.selectedAddress = true;
        onSelect && onSelect(item);
    };
    var onClick = function onClick(e) {
        e.stopPropagation();
        onSwitch && onSwitch({
            type: type === 'exist' ? 'cascader' : 'exist'
        });
    };
    return /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/ _react.default.createElement(_components.ScrollView, {
        scrollY: true,
        style: {
            height: '100%'
        }
    }, /*#__PURE__*/ _react.default.createElement("ul", {
        className: "".concat(classPrefix, "-exist")
    }, existList.map(function(item, index) {
        return /*#__PURE__*/ _react.default.createElement("li", {
            className: "".concat(classPrefix, "-exist-item ").concat(item.selectedAddress ? 'active' : ''),
            key: index,
            onClick: function onClick(e) {
                e.stopPropagation();
                selectedExist(item);
            }
        }, item.selectedAddress ? /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/ _react.default.isValidElement(selectIcon) ? selectIcon : /*#__PURE__*/ _react.default.createElement(_iconsreacttaro.Check, {
            color: "var(--nutui-color-primary, #ff0f23)"
        })) : /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/ _react.default.isValidElement(defaultIcon) ? defaultIcon : /*#__PURE__*/ _react.default.createElement(_iconsreacttaro.Location, null)), /*#__PURE__*/ _react.default.createElement(_components.View, {
            className: "".concat(classPrefix, "-exist-item-info")
        }, item.name && item.phone && /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/ _react.default.createElement(_components.View, null, item.name), /*#__PURE__*/ _react.default.createElement(_components.View, null, item.phone)), /*#__PURE__*/ _react.default.createElement(_components.View, null, item.provinceName + item.cityName + item.countyName + item.townName + item.addressDetail)));
    }))), (custom || custom && locale.address.chooseAnotherAddress) && /*#__PURE__*/ _react.default.createElement(_components.View, {
        className: "".concat(classPrefix, "-footer"),
        onClick: onClick
    }, /*#__PURE__*/ _react.default.createElement(_components.View, {
        className: "".concat(classPrefix, "-footer-btn")
    }, custom)));
};
