Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
require("../../chunk-BN4qSVkS.cjs");
const require_styles_z_index = require("../../styles/z-index.cjs");
const require_components_Button = require("../Button.cjs");
const require_components_Select = require("../Select.cjs");
const require_components_DataManagerTable_Filter = require("./Filter.cjs");
require("./filters.cjs");
const require_components_DataManagerTable_AppliedButtonsContainer = require("./AppliedButtonsContainer.cjs");
let _emotion_react_jsx_runtime = require("@emotion/react/jsx-runtime");
let _lightsparkdev_core = require("@lightsparkdev/core");
//#region src/components/DataManagerTable/EnumFilter.tsx
const isEnumFilterState = (state) => state.type === "enum";
const getDefaultEnumFilterState = () => ({
	type: "enum",
	value: "",
	isApplied: false
});
const EnumFilter = ({ updateFilterState, state, options, placeholder, label, isMulti }) => {
	const appliedValueButtons = state.appliedValues?.map((value) => {
		return /* @__PURE__ */ (0, _emotion_react_jsx_runtime.jsx)(require_components_Button.Button, {
			kind: "primary",
			size: "ExtraSmall",
			text: value,
			icon: { name: "Close" },
			iconSide: "right",
			onClick: () => {
				updateFilterState({
					...state,
					appliedValues: state.appliedValues?.filter((appliedValue) => appliedValue !== value)
				});
			}
		}, value);
	});
	return /* @__PURE__ */ (0, _emotion_react_jsx_runtime.jsxs)(_emotion_react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, _emotion_react_jsx_runtime.jsx)(require_components_DataManagerTable_Filter.Filter, {
		label,
		children: /* @__PURE__ */ (0, _emotion_react_jsx_runtime.jsx)(require_components_Select.Select, {
			zIndex: require_styles_z_index.z.dropdown + 1,
			placeholder: "Select value",
			options,
			onChange: (option) => {
				if (option) {
					const optionValues = (0, _lightsparkdev_core.ensureArray)(option.value);
					let updatedAppliedValues = [];
					if (isMulti) updatedAppliedValues = state.appliedValues ? [...state.appliedValues.filter((appliedValue) => appliedValue !== option.value), ...optionValues] : [...optionValues];
					else updatedAppliedValues = [...optionValues];
					updateFilterState({
						...state,
						value: option.label,
						isApplied: true,
						appliedValues: updatedAppliedValues
					});
				}
			}
		})
	}), !!appliedValueButtons?.length ? /* @__PURE__ */ (0, _emotion_react_jsx_runtime.jsx)(require_components_DataManagerTable_AppliedButtonsContainer.AppliedButtonsContainer, { children: appliedValueButtons }) : null] });
};
//#endregion
exports.EnumFilter = EnumFilter;
exports.getDefaultEnumFilterState = getDefaultEnumFilterState;
exports.isEnumFilterState = isEnumFilterState;
