import {
  Filter
} from "./chunk-LAIAW5BT.js";
import {
  NumberInput_default
} from "./chunk-M7P5MYNB.js";
import {
  ButtonRow
} from "./chunk-VHHLWRJS.js";
import {
  __spreadProps,
  __spreadValues
} from "./chunk-W7FAWX6T.js";

// src/components/DataManagerTable/CurrencyFilter.tsx
import styled from "@emotion/styled";
import { CurrencyUnit } from "@lightsparkdev/core";
import { useState } from "react";
import { jsx, jsxs } from "@emotion/react/jsx-runtime";
var isCurrencyFilterState = (state) => state.type === "currency" /* CURRENCY */;
var getDefaultCurrencyFilterState = () => ({
  type: "currency" /* CURRENCY */,
  min_amount: null,
  max_amount: null,
  isApplied: false
});
var CurrencyFilter = ({
  updateFilterState,
  state,
  label
}) => {
  var _a, _b, _c, _d;
  const [filterRangeType, setFilterRangeType] = useState(
    "Less than" /* LessThan */
  );
  const isMinDisplayed = filterRangeType !== "Less than" /* LessThan */;
  const isMaxDisplayed = filterRangeType !== "More than" /* MoreThan */;
  const handleMinChange = (value) => {
    updateFilterState(__spreadProps(__spreadValues({}, state), {
      min_amount: value ? { value: parseInt(value), unit: CurrencyUnit.SATOSHI } : null,
      isApplied: state.max_amount !== null || !!value
    }));
  };
  const handleMaxChange = (value) => {
    updateFilterState(__spreadProps(__spreadValues({}, state), {
      max_amount: value ? { value: parseInt(value), unit: CurrencyUnit.SATOSHI } : null,
      isApplied: state.min_amount !== null || !!value
    }));
  };
  const handleClick = (type) => {
    setFilterRangeType(type);
    updateFilterState(__spreadProps(__spreadValues({}, state), {
      min_amount: null,
      max_amount: null,
      isApplied: false
    }));
  };
  return /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsxs(Filter, { label, children: [
    /* @__PURE__ */ jsx(
      NumberButtonRowContainer,
      {
        smSticky: false,
        bottomBorder: false,
        buttons: [
          {
            text: "Less than",
            kind: filterRangeType === "Less than" /* LessThan */ ? "primary" : void 0,
            onClick: () => handleClick("Less than" /* LessThan */),
            size: "ExtraSmall"
          },
          {
            text: "Between",
            kind: filterRangeType === "Between" /* Between */ ? "primary" : void 0,
            onClick: () => handleClick("Between" /* Between */),
            size: "ExtraSmall"
          },
          {
            text: "More than",
            kind: filterRangeType === "More than" /* MoreThan */ ? "primary" : void 0,
            onClick: () => handleClick("More than" /* MoreThan */),
            size: "ExtraSmall"
          }
        ]
      }
    ),
    /* @__PURE__ */ jsxs(InputContainer, { children: [
      isMinDisplayed && /* @__PURE__ */ jsx(
        NumberInput_default,
        {
          placeholder: "0",
          onChange: handleMinChange,
          value: ((_b = (_a = state.min_amount) == null ? void 0 : _a.value) == null ? void 0 : _b.toString()) || "",
          icon: { name: "Satoshi", side: "left", width: 8 },
          typography: { color: "black" },
          allowNegativeValue: true
        }
      ),
      isMinDisplayed && isMaxDisplayed && /* @__PURE__ */ jsx(Divider, {}),
      isMaxDisplayed && /* @__PURE__ */ jsx(
        NumberInput_default,
        {
          placeholder: "0",
          onChange: handleMaxChange,
          value: ((_d = (_c = state.max_amount) == null ? void 0 : _c.value) == null ? void 0 : _d.toString()) || "",
          icon: { name: "Satoshi", side: "left", width: 8 },
          typography: { color: "black" },
          allowNegativeValue: true
        }
      )
    ] })
  ] }) });
};
var NumberButtonRowContainer = styled(ButtonRow)`
  padding: 0px !important;
`;
var InputContainer = styled.div`
  display: flex;
  flex-direction: row;
  margin-top: 24px;
  gap: 10px;
  align-items: center;
`;
var Divider = styled.div`
  height: 4px;
  width: 12px;
  flex-shrink: 0;
  border-radius: 999px;
  background-color: ${({ theme }) => theme.c1Neutral};
`;

export {
  isCurrencyFilterState,
  getDefaultCurrencyFilterState,
  CurrencyFilter
};
