"use client";
import { jsx, jsxs } from 'react/jsx-runtime';
import { cx } from '../../node_modules/.pnpm/class-variance-authority@0.7.1/node_modules/class-variance-authority/dist/index.js';
import { useCallback } from 'react';
import { Select } from '../select/select.js';
import { Text } from '../text/text.js';
import styles from './filter-chip.module.css.js';

const Operation = ({ label, value, onChange, operations, showAlternateLabel = false }) => {
    const operationValue = value?.value ?? '';
    const handleValueChange = useCallback((newValue) => {
        const operation = operations.find(o => o.value === newValue);
        if (operation)
            onChange(operation);
    }, [operations, onChange]);
    if (operations.length === 1)
        return (jsx(Text, { variant: 'secondary', className: cx(styles.selectValue, styles.operationValue), children: operations[0].label }));
    return (jsxs(Select, { value: operationValue, onValueChange: handleValueChange, "aria-labelledby": `${label}-label`, children: [jsx(Select.Trigger, { variant: 'text', className: cx(styles.selectValue, styles.operationValue), "aria-label": `${label} filter operation`, iconProps: {
                    style: {
                        display: 'none'
                    }
                }, children: jsx(Select.Value, { placeholder: 'Select operation', className: styles.operationText }) }), jsx(Select.Content, { "data-variant": 'filter', children: operations.map(operation => {
                    return (jsx(Select.Item, { value: operation.value, "aria-label": `Filter ${label} ${operation.label}`, children: showAlternateLabel && operation?.alternateLabel
                            ? operation.alternateLabel
                            : operation.label }, operation.value));
                }) })] }));
};

export { Operation };
//# sourceMappingURL=filter-chip-operation.js.map
