"use client";
'use strict';

var jsxRuntime = require('react/jsx-runtime');
var index = require('../../node_modules/.pnpm/class-variance-authority@0.7.1/node_modules/class-variance-authority/dist/index.cjs');
var React = require('react');
var select = require('../select/select.cjs');
var text = require('../text/text.cjs');
var filterChip_module = require('./filter-chip.module.css.cjs');

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

exports.Operation = Operation;
//# sourceMappingURL=filter-chip-operation.cjs.map
