"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var _chunkY45PAGZ2cjs = require('./chunk-Y45PAGZ2.cjs');


var _chunk6HFFGWQXcjs = require('./chunk-6HFFGWQX.cjs');


var _chunkZUAO4DW3cjs = require('./chunk-ZUAO4DW3.cjs');


var _chunkKKOBB4X5cjs = require('./chunk-KKOBB4X5.cjs');


var _chunkZU72XWNEcjs = require('./chunk-ZU72XWNE.cjs');



var _chunkZ6EUSUADcjs = require('./chunk-Z6EUSUAD.cjs');

// src/components/DataManagerTable/EnumFilter.tsx
var _styled = require('@emotion/styled'); var _styled2 = _interopRequireDefault(_styled);
var _core = require('@lightsparkdev/core');
var _jsxruntime = require('@emotion/react/jsx-runtime');
var isEnumFilterState = (state) => state.type === "enum" /* ENUM */;
var getDefaultEnumFilterState = () => ({
  type: "enum" /* ENUM */,
  value: "",
  isApplied: false
});
var EnumFilter = ({
  updateFilterState,
  state,
  options,
  placeholder,
  label,
  isMulti
}) => {
  var _a;
  const appliedValueButtons = (_a = state.appliedValues) == null ? void 0 : _a.map((value) => {
    return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, 
      _chunkKKOBB4X5cjs.Button,
      {
        kind: "primary",
        size: "ExtraSmall",
        text: value,
        icon: { name: "Close" },
        iconSide: "right",
        onClick: () => {
          var _a2;
          updateFilterState(_chunkZ6EUSUADcjs.__spreadProps.call(void 0, _chunkZ6EUSUADcjs.__spreadValues.call(void 0, {}, state), {
            appliedValues: (_a2 = state.appliedValues) == null ? void 0 : _a2.filter(
              (appliedValue) => appliedValue !== value
            )
          }));
        }
      },
      value
    );
  });
  return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
    /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkY45PAGZ2cjs.Filter, { label, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, 
      _chunk6HFFGWQXcjs.Select_default,
      {
        zIndex: _chunkZU72XWNEcjs.z.dropdown + 1,
        placeholder: "Select value",
        options,
        onChange: (option) => {
          if (option) {
            const optionValues = _core.ensureArray.call(void 0, option.value);
            let updatedAppliedValues = [];
            if (isMulti) {
              updatedAppliedValues = state.appliedValues ? [
                ...state.appliedValues.filter(
                  (appliedValue) => appliedValue !== option.value
                ),
                ...optionValues
              ] : [...optionValues];
            } else {
              updatedAppliedValues = [...optionValues];
            }
            updateFilterState(_chunkZ6EUSUADcjs.__spreadProps.call(void 0, _chunkZ6EUSUADcjs.__spreadValues.call(void 0, {}, state), {
              value: option.label,
              isApplied: true,
              appliedValues: updatedAppliedValues
            }));
          }
        }
      }
    ) }),
    !!(appliedValueButtons == null ? void 0 : appliedValueButtons.length) ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, AppliedButtonsContainer, { children: appliedValueButtons }) : null
  ] });
};
var AppliedButtonsContainer = _styled2.default.div`
  margin-top: ${_chunkZUAO4DW3cjs.Spacing.px.sm};
  display: flex;
  gap: ${_chunkZUAO4DW3cjs.Spacing.px.xs};
  flex-wrap: wrap;
`;





exports.isEnumFilterState = isEnumFilterState; exports.getDefaultEnumFilterState = getDefaultEnumFilterState; exports.EnumFilter = EnumFilter;
