import { Button } from "../Button.js";
import { TextInput } from "../TextInput.js";
import { Filter } from "./Filter.js";
import "./filters.js";
import { AppliedButtonsContainer } from "./AppliedButtonsContainer.js";
import { Fragment, jsx, jsxs } from "@emotion/react/jsx-runtime";
//#region src/components/DataManagerTable/StringFilter.tsx
const isStringFilterState = (state) => state.type === "string";
const getDefaultStringFilterState = () => ({
	type: "string",
	value: "",
	isApplied: false
});
const StringFilter = ({ updateFilterState, state, placeholder, label }) => {
	const handleChange = (value) => {
		updateFilterState({
			...state,
			value,
			isApplied: !!value
		});
	};
	const appliedValueButtons = state.appliedValues?.map((value) => {
		return /* @__PURE__ */ jsx(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__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Filter, {
		label,
		children: /* @__PURE__ */ jsx(TextInput, {
			placeholder: placeholder || "",
			onChange: handleChange,
			value: state.value
		})
	}), !!appliedValueButtons?.length ? /* @__PURE__ */ jsx(AppliedButtonsContainer, { children: appliedValueButtons }) : null] });
};
//#endregion
export { StringFilter, getDefaultStringFilterState, isStringFilterState };
