import { jsxs, Fragment, jsx } from "react/jsx-runtime";
import { forwardRef } from "react";
import { Checkbox } from "../Checkbox/index.js";
const SearchFilter = forwardRef(
  ({
    isClearable,
    onSearch,
    isMulti,
    onSelectAll,
    onClearAll,
    isSelectAll,
    selectedOptions,
    toggleSelectAll,
    isWithSearch,
    onKeyDown,
    searchPlaceholder,
    isLoading,
    searchTerm,
    externalOnSearch: _externalOnSearch,
    setSearchTerm: _setSearchTerm
  }, ref) => {
    const selectedArr = Array.isArray(selectedOptions) ? selectedOptions : [];
    return /* @__PURE__ */ jsxs(Fragment, { children: [
      isWithSearch && /* @__PURE__ */ jsx(
        "input",
        {
          ref,
          className: "ia-select-search-box",
          placeholder: searchPlaceholder,
          value: searchTerm,
          onChange: onSearch,
          onKeyDown
        }
      ),
      isMulti && toggleSelectAll && !isLoading && /* @__PURE__ */ jsx("div", { className: "ia-select-search-container", children: /* @__PURE__ */ jsxs("div", { className: "ia-select-selectAll-container", children: [
        /* @__PURE__ */ jsx(
          Checkbox,
          {
            checked: isSelectAll,
            className: "select-selectAll-checkbox",
            id: "select-all",
            label: isSelectAll ? "Deselect All" : "Select All",
            name: "select-all",
            onChange: onSelectAll
          }
        ),
        isClearable && selectedArr.length > 0 && /* @__PURE__ */ jsx(
          "button",
          {
            className: "ia-select-clear-all-button",
            type: "button",
            onClick: () => {
              onClearAll();
            },
            children: "Clear"
          }
        )
      ] }) })
    ] });
  }
);
SearchFilter.displayName = "SearchFilter";
export {
  SearchFilter as default
};
