import React, { forwardRef } from "react";
import { GRADIENT_TEXT_CLASS } from "../../utils/constants";
import cls from "classnames";
import { IconClose } from "../_Icon/Icons/IconClose";
import { base as viewCSS } from "./variations/_view/base";
import { base as sizeCSS } from "./variations/_size/base";
import { base as disabledCSS } from "./variations/_disabled/base";
import { base as readonlyCSS } from "./variations/_readonly/base";
import { base as focusedCSS } from "./variations/_focused/base";
import { base as pilledCSS } from "./variations/_pilled/base";
import { StyledContentClear, StyledContentLeft, StyledContentMain, StyledContentRight, base } from "./Chip.styles";
import { classes, tokens } from "./Chip.tokens";
export const chipRoot = (Root)=>/*#__PURE__*/ forwardRef((props, ref)=>{
        const { children, text, contentLeft, contentRight, contentClearButton, hasClear = true, size, className, onClear, onClick, onClickClose, pilled = false, readOnly = false, disabled = false, // @ts-ignore
        _forceChipManipulationWithReadonly, // @ts-ignore
        chipClickArea, ...rest } = props;
        const txt = !text && typeof children === 'string' ? children : text;
        const pilledClass = pilled ? classes.pilled : undefined;
        const handleClick = (event)=>{
            // TODO: #1547
            // eslint-disable-next-line no-underscore-dangle
            if (disabled || readOnly && !_forceChipManipulationWithReadonly) {
                return;
            }
            onClick?.(event);
        };
        const handleClickClose = (event)=>{
            if (disabled || readOnly && !_forceChipManipulationWithReadonly || !onClickClose) {
                return;
            }
            event.stopPropagation();
            onClickClose(event);
            if (onClear) {
                onClear();
            }
        };
        return /*#__PURE__*/ React.createElement(Root, {
            type: "button",
            ref: ref,
            className: cls(pilledClass, classes.chipItem, className, {}),
            tabIndex: readOnly ? -1 : 0,
            onClick: handleClick,
            disabled: disabled,
            readOnly: !disabled && readOnly && !_forceChipManipulationWithReadonly,
            size: size,
            ...rest
        }, contentLeft && /*#__PURE__*/ React.createElement(StyledContentLeft, null, contentLeft), txt ? /*#__PURE__*/ React.createElement(StyledContentMain, {
            className: GRADIENT_TEXT_CLASS
        }, txt) : children, contentRight && /*#__PURE__*/ React.createElement(StyledContentRight, {
            hasClear: hasClear
        }, contentRight), hasClear && (contentClearButton || /*#__PURE__*/ React.createElement(StyledContentClear, {
            onClick: handleClickClose
        }, /*#__PURE__*/ React.createElement(IconClose, {
            sizeCustomProperty: tokens.closeIconSize,
            color: "inherit"
        }))));
    });
export const chipConfig = {
    name: 'Chip',
    tag: 'button',
    layout: chipRoot,
    base,
    variations: {
        view: {
            css: viewCSS
        },
        size: {
            css: sizeCSS
        },
        disabled: {
            css: disabledCSS,
            attrs: true
        },
        readOnly: {
            css: readonlyCSS,
            attrs: true
        },
        focused: {
            css: focusedCSS
        },
        pilled: {
            css: pilledCSS,
            attrs: true
        }
    },
    defaults: {
        view: 'default',
        size: 'm'
    }
};
