/*
 * Copyright 2025 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 { Button } from "@base-ui/react/button";
import classnames from "classnames";
import React, { useCallback, useState } from "react";
import { ExpandIcon } from "./FilterIcons.js";
import { FilterListBoundaryProvider } from "./FilterListBoundaryContext.js";
import { FilterListContent } from "./FilterListContent.js";
import { FilterListHeader } from "./FilterListHeader.js";
import styles from "./FilterList.module.css.js";
export function BaseFilterList(props) {
  const {
    title,
    titleIcon,
    collapsed = false,
    onCollapsedChange,
    filterDefinitions,
    filterStates,
    onFilterStateChanged,
    renderInput,
    getFilterKey,
    getFilterLabel,
    getEmptyDisplayState,
    activeFilterCount,
    onReset,
    onFilterAdded,
    onFilterRemoved,
    onOrderChange,
    showResetButton = false,
    showActiveFilterCount = false,
    canReset,
    // eslint-disable-next-line @typescript-eslint/no-deprecated -- consumed as a backwards-compatible fallback when canReset is not provided
    hasVisibilityChanges,
    enableSorting,
    className,
    renderAddFilterButton
  } = props;
  const [boundaryElement, setBoundaryElement] = useState(null);
  const handleExpand = useCallback(() => {
    onCollapsedChange?.(false);
  }, [onCollapsedChange]);
  const isCollapsed = collapsed && onCollapsedChange != null;
  return /*#__PURE__*/React.createElement("div", {
    className: classnames(styles.filterList, className)
  }, isCollapsed && /*#__PURE__*/React.createElement("div", {
    className: styles.filterListCollapsed,
    "data-collapsed": "true"
  }, /*#__PURE__*/React.createElement(Button, {
    className: styles.expandButton,
    onClick: handleExpand,
    "aria-label": "Expand filters"
  }, /*#__PURE__*/React.createElement(ExpandIcon, null)), /*#__PURE__*/React.createElement("span", {
    className: styles.collapsedLabel
  }, title ?? "Filters")), /*#__PURE__*/React.createElement("div", {
    ref: setBoundaryElement,
    className: classnames(styles.expandedContent, isCollapsed && styles.hiddenContent),
    "data-active-count": activeFilterCount
  }, /*#__PURE__*/React.createElement(FilterListBoundaryProvider, {
    value: boundaryElement
  }, (title || titleIcon || showResetButton || showActiveFilterCount || onCollapsedChange) && /*#__PURE__*/React.createElement(FilterListHeader, {
    title: title,
    titleIcon: titleIcon,
    collapsed: collapsed,
    onCollapsedChange: onCollapsedChange,
    showResetButton: showResetButton,
    onReset: onReset,
    showActiveFilterCount: showActiveFilterCount,
    activeFilterCount: activeFilterCount,
    canReset: canReset,
    hasVisibilityChanges: hasVisibilityChanges
  }), /*#__PURE__*/React.createElement("div", {
    className: styles.scrollableContent
  }, /*#__PURE__*/React.createElement(FilterListContent, {
    filterDefinitions: filterDefinitions,
    filterStates: filterStates,
    onFilterStateChanged: onFilterStateChanged,
    onFilterRemoved: onFilterRemoved,
    onOrderChange: onOrderChange,
    renderInput: renderInput,
    getFilterKey: getFilterKey,
    getFilterLabel: getFilterLabel,
    getEmptyDisplayState: getEmptyDisplayState,
    enableSorting: enableSorting
  })), (renderAddFilterButton != null || onFilterAdded != null) && /*#__PURE__*/React.createElement("div", {
    className: styles.addButtonContainer
  }, renderAddFilterButton ? renderAddFilterButton() : /*#__PURE__*/React.createElement(Button, {
    type: "button",
    className: styles.addButton,
    onClick: onFilterAdded
  }, "+ Add filter")))));
}
//# sourceMappingURL=BaseFilterList.js.map