var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: !0 });
}, __copyProps = (to, from, except, desc) => {
  if (from && typeof from == "object" || typeof from == "function")
    for (let key of __getOwnPropNames(from))
      !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
var SearchList_exports = {};
__export(SearchList_exports, {
  SearchList: () => SearchList
});
module.exports = __toCommonJS(SearchList_exports);
var import_jsx_runtime = require("react/jsx-runtime"), import_icons_ui = require("@truststack/icons-ui"), import_react = require("react"), import_react_native = require("react-native"), import_tamagui = require("tamagui"), import_Divider = require("./Divider"), import_List = require("./List"), import_ListFooter = require("./ListFooter"), import_Search = require("./Search"), import_utils = require("./utils");
function SearchList(param) {
  var { value, onChange, searchFunc, placeholder = "Search..." } = param, [searching, setSearching] = (0, import_react.useState)(void 0), [search, setSearch] = (0, import_react.useState)(""), [results, setResults] = (0, import_react.useState)([]), debounce = (0, import_utils.useDebounce)(search, 1e3);
  return (0, import_react.useEffect)(function() {
    debounce != null && debounce.length && (setSearching(!0), searchFunc(debounce).then(setResults).finally(function() {
      return setSearching(!1);
    }));
  }, [
    debounce
  ]), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_tamagui.YStack, {
    gap: 12,
    children: [
      /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_tamagui.View, {
        margin: "$spacing.margin_compact",
        children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Search.SearchBar, {
          placeholder,
          value: search,
          onChangeText: setSearch
        })
      }),
      /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.FlatList, {
        data: results,
        ItemSeparatorComponent: import_Divider.Divider,
        ListFooterComponent: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ListFooter.ListFooter, {
          loading: searching,
          noResults: !!search && searching === !1 && !(results != null && results.length)
        }),
        renderItem: function(param2) {
          var { item } = param2;
          return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_List.ListItem, {
            pressable: !0,
            line: "one",
            onPress: function() {
              return onChange(item.value);
            },
            children: [
              /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_List.ListItem.Container, {
                children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_List.ListItem.Headline, {
                  adjustsFontSizeToFit: !0,
                  numberOfLines: 1,
                  children: item.label
                })
              }),
              item.value == value && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_List.ListItem.TrailingIcon, {
                Icon: import_icons_ui.Check
              })
            ]
          });
        }
      })
    ]
  });
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  SearchList
});
//# sourceMappingURL=SearchList.js.map
