"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.BasicChips = void 0;
const react_1 = __importDefault(require("react"));
const ChipItem_1 = require("../ChipItem");
const ChipsFrame_1 = require("../ChipsFrame");
const BasicChips = (props) => {
    const showResetIcon = props.value.length > 0;
    const handleClickResetIcon = () => {
        props.onChange([]);
    };
    const iconProps = showResetIcon
        ? { type: 'reset', onClick: handleClickResetIcon }
        : undefined;
    const handleClickItem = (selectedValue) => {
        const index = props.value.findIndex((target) => target === selectedValue);
        if (index === -1) {
            props.onChange([...props.value, selectedValue]);
        }
        else {
            const prev = props.value;
            const result = [...prev.slice(0, index), ...prev.slice(index + 1)];
            props.onChange(result);
        }
    };
    return (react_1.default.createElement(ChipsFrame_1.ChipsFrame, { colorType: props.colorType, type: "basic", icon: iconProps }, props.list.map((item, index) => {
        return (react_1.default.createElement(ChipItem_1.ChipItem, { key: index, type: "basic", colorType: props.colorType, displayValue: item.label, selected: props.value.includes(item.value), onClick: () => handleClickItem(item.value), onReset: () => handleClickItem(item.value) }));
    })));
};
exports.BasicChips = BasicChips;
