import {
  Filter
} from "./chunk-LAIAW5BT.js";
import {
  TextInput
} from "./chunk-H5MRGJQP.js";
import {
  Spacing
} from "./chunk-E5DUKMCU.js";
import {
  Button
} from "./chunk-SIPHI6JZ.js";
import {
  __spreadProps,
  __spreadValues
} from "./chunk-W7FAWX6T.js";

// src/components/DataManagerTable/StringFilter.tsx
import styled from "@emotion/styled";
import { Fragment, jsx, jsxs } from "@emotion/react/jsx-runtime";
var isStringFilterState = (state) => state.type === "string" /* STRING */;
var getDefaultStringFilterState = () => ({
  type: "string" /* STRING */,
  value: "",
  isApplied: false
});
var StringFilter = ({
  updateFilterState,
  state,
  placeholder,
  label
}) => {
  var _a;
  const handleChange = (value) => {
    updateFilterState(__spreadProps(__spreadValues({}, state), {
      value,
      isApplied: !!value
    }));
  };
  const appliedValueButtons = (_a = state.appliedValues) == null ? void 0 : _a.map((value) => {
    return /* @__PURE__ */ jsx(
      Button,
      {
        kind: "primary",
        size: "ExtraSmall",
        text: value,
        icon: { name: "Close" },
        iconSide: "right",
        onClick: () => {
          var _a2;
          updateFilterState(__spreadProps(__spreadValues({}, state), {
            appliedValues: (_a2 = state.appliedValues) == null ? void 0 : _a2.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 == null ? void 0 : appliedValueButtons.length) ? /* @__PURE__ */ jsx(AppliedButtonsContainer, { children: appliedValueButtons }) : null
  ] });
};
var AppliedButtonsContainer = styled.div`
  margin-top: ${Spacing.px.sm};
  display: flex;
  gap: ${Spacing.px.xs};
  flex-wrap: wrap;
`;

export {
  isStringFilterState,
  getDefaultStringFilterState,
  StringFilter
};
