"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "TextFieldChipNew", {
    enumerable: true,
    get: function() {
        return TextFieldChipNew;
    }
});
const _react = /*#__PURE__*/ _interop_require_default(require("react"));
const _TextFieldChipstyles = require("../TextFieldChip/TextFieldChip.styles");
const _TextFieldstyles = require("../../TextField.styles");
const _TextFieldtokens = require("../../TextField.tokens");
const _TextFieldChipNewstyles = require("./TextFieldChipNew.styles");
function _interop_require_default(obj) {
    return obj && obj.__esModule ? obj : {
        default: obj
    };
}
const TextFieldChipNew = ({ chips, onChipCloseClick, getRef, handleChipKeyDown, onChipClear, readOnly, chipType, view, chipClickArea = 'full', _forceChipManipulationWithReadonly })=>{
    return /*#__PURE__*/ _react.default.createElement(_TextFieldstyles.StyledChips, {
        className: _TextFieldtokens.classes.chipsWrapper
    }, chips.map(({ value, label, disabled }, index)=>{
        const chipId = `${index}_${value}`;
        const handleChipClick = (event)=>{
            event.stopPropagation();
        };
        const onKeyDownHandle = (event)=>{
            if (handleChipKeyDown) {
                handleChipKeyDown(event, chipId, index);
            }
            if (event.key === 'Enter' || event.key === 'Backspace') {
                if (onChipCloseClick) {
                    onChipCloseClick({
                        value,
                        label,
                        disabled
                    });
                }
            }
        };
        const handleCloseClick = (event)=>{
            event.stopPropagation();
            if (onChipCloseClick) {
                onChipCloseClick({
                    value,
                    label,
                    disabled
                });
            }
            if (onChipClear) {
                onChipClear(chipId, index);
            }
        };
        return chipType === 'default' ? /*#__PURE__*/ _react.default.createElement(_TextFieldChipNewstyles.StyledChip, {
            key: chipId,
            ref: (element)=>getRef(element, index),
            tabIndex: -1,
            disabled: disabled,
            hasClear: !disabled,
            readOnly: readOnly,
            onKeyDown: onKeyDownHandle,
            onClear: ()=>onChipClear(chipId, index),
            text: label,
            view: view,
            chipClickArea: chipClickArea,
            ...chipClickArea === 'full' ? {
                onClick: handleCloseClick
            } : {
                onClick: handleChipClick,
                onClickClose: handleCloseClick
            },
            // TODO: #1547
            // eslint-disable-next-line @typescript-eslint/ban-ts-comment
            // @ts-ignore
            _forceChipManipulationWithReadonly: _forceChipManipulationWithReadonly
        }) : /*#__PURE__*/ _react.default.createElement(_TextFieldChipstyles.TextChip, {
            tabIndex: -1,
            onClick: handleCloseClick,
            onKeyDown: onKeyDownHandle
        }, label);
    }));
};
