/*
 * Copyright 2026 Palantir Technologies, Inc. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import { Popover } from "@base-ui/react/popover";
import classnames from "classnames";
import React, { memo, useCallback, useState } from "react";
import { RemoveIcon } from "./FilterIcons.js";
import styles from "./FilterPopover.module.css";
/** Labeled, popover-backed filter trigger. Pair with `FilterInput` for the popup body. */
function FilterPopoverInner({
  label,
  summary,
  isActive,
  onRemove,
  children,
  className,
  placeholder = "Any",
  labelPlacement = "inline"
}) {
  const [open, setOpen] = useState(false);
  const summaryHasValue = summary !== "";
  const handleRemoveClick = useCallback(e => {
    e.stopPropagation();
    onRemove?.();
  }, [onRemove]);
  return /*#__PURE__*/React.createElement(Popover.Root, {
    open: open,
    onOpenChange: setOpen
  }, /*#__PURE__*/React.createElement("span", {
    className: classnames(styles.fieldGroup, labelPlacement === "top" && styles.fieldGroupTop, className)
  }, /*#__PURE__*/React.createElement("span", {
    className: styles.label
  }, label), /*#__PURE__*/React.createElement(Popover.Trigger, {
    className: styles.trigger,
    "data-active": isActive ? "true" : undefined
  }, /*#__PURE__*/React.createElement("span", {
    className: classnames(styles.summary, !summaryHasValue && styles.placeholder)
  }, summaryHasValue ? summary : placeholder)), onRemove && /*#__PURE__*/React.createElement("button", {
    type: "button",
    onClick: handleRemoveClick,
    className: styles.removeButton,
    "aria-label": `Remove ${label} filter`
  }, /*#__PURE__*/React.createElement(RemoveIcon, null))), /*#__PURE__*/React.createElement(Popover.Portal, null, /*#__PURE__*/React.createElement(Popover.Positioner, {
    sideOffset: 4,
    align: "start"
  }, /*#__PURE__*/React.createElement(Popover.Popup, {
    className: styles.popup
  }, children))));
}
export const FilterPopover = /*#__PURE__*/memo(FilterPopoverInner);
//# sourceMappingURL=FilterPopover.js.map