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 Select_exports = {};
__export(Select_exports, {
  Select: () => Select
});
module.exports = __toCommonJS(Select_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_Menu = require("./Menu"), import_Popover = require("./Popover"), import_Sheet = require("./Sheet"), import_TextField = require("./TextField"), import_typography = require("./typography");
function Select(param) {
  var { options = [], label, onValueChange = function() {
  }, disabled, value, supportingText, loading, ...props } = param, [open, setOpen] = (0, import_react.useState)(!1), [width, setWidth] = (0, import_react.useState)(0), render = (0, import_react.useMemo)(function() {
    var _options_find;
    return options == null || (_options_find = options.find(function(o) {
      return o.value == value;
    })) === null || _options_find === void 0 ? void 0 : _options_find.label;
  }, [
    value,
    options
  ]);
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_Popover.Popover, {
    allowFlip: !0,
    open,
    onOpenChange: setOpen,
    children: [
      /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Popover.Popover.Trigger, {
        disabled,
        f: 1,
        cursor: "pointer",
        asChild: !0,
        children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.Pressable, {
          disabled,
          style: {
            flexGrow: 1
          },
          children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_TextField.TextField, {
            disabled,
            label,
            loading,
            supportingText,
            trailingIcon: import_icons_ui.ChevronDown,
            onLayout: function(e) {
              return setWidth(e.nativeEvent.layout.width);
            },
            ...props,
            pointerEvents: "none",
            cursor: "pointer",
            value: render || ""
          })
        })
      }),
      /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_tamagui.Adapt, {
        when: "sm",
        children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_Sheet.Sheet, {
          modal: !0,
          snapPoints: [
            80
          ],
          animation: "quick",
          disableDrag: !0,
          children: [
            /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Sheet.Sheet.Overlay, {}),
            /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_Sheet.Sheet.Frame, {
              pb: 16,
              backgroundColor: "$surfaceContainerLowest",
              children: [
                /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_tamagui.View, {
                  margin: "$spacing.margin_compact",
                  children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_typography.Headline, {
                    children: label
                  })
                }),
                /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Divider.Divider, {}),
                /* @ts-ignore */
                /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_tamagui.Adapt.Contents, {
                  background: "$transparent"
                })
              ]
            })
          ]
        })
      }),
      /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Popover.Popover.Content, {
        minWidth: 0,
        maxWidth: void 0,
        open,
        onOpenChange: setOpen,
        p: 0,
        backgroundColor: "$surfaceContainerLowest",
        width,
        maxHeight: 300,
        overflow: "hidden",
        borderRadius: "$shape.corner_l",
        borderWidth: "$border.outline",
        borderColor: "$outline",
        children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_tamagui.ScrollView, {
          width: "100%",
          showsVerticalScrollIndicator: !1,
          children: [
            !(options != null && options.length) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_typography.Body, {
              m: 12,
              children: "No options"
            }),
            options == null ? void 0 : options.map(function(o) {
              return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.Pressable, {
                onPress: function() {
                  setOpen(!1), onValueChange(o.value);
                },
                style: {
                  width: "100%",
                  justifyContent: "flex-start",
                  flexDirection: "row",
                  display: "flex"
                },
                children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_Menu.MenuItem, {
                  selected: value == o.value,
                  children: [
                    /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Menu.MenuItem.Label, {
                      children: o.label
                    }),
                    /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Menu.MenuItem.Selected, {})
                  ]
                })
              }, `menu-item-${o.value}`);
            })
          ]
        })
      })
    ]
  });
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  Select
});
//# sourceMappingURL=Select.js.map
