"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _native = _interopRequireDefault(require("styled-components/native"));
var _reactNative = require("react-native");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
const SelectWrapper = _native.default.View`
  position: relative;
  width: 100%;
`;
const SelectBox = _native.default.TouchableOpacity`
  border: ${({
  borderColor
}) => borderColor ? `1px solid ${borderColor}` : '1px solid #ccc'};
  padding: 10px;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  background-color: #fff;
  border-radius: 5px;
  box-shadow: ${({
  isOpen
}) => isOpen ? '0px 4px 8px rgba(0, 0, 0, 0.1)' : 'none'};
`;
const Placeholder = _native.default.Text`
  color: #aaa;
`;
const Icon = (0, _native.default)(_reactNative.Animated.Text)`
  margin-left: 10px;
`;
const Dropdown = _native.default.View`
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background-color: #fff;
  max-height: 200px;
  border: 1px solid #ccc;
  border-radius: 5px;
  z-index: 100;
`;
const SearchBox = _native.default.TextInput`
  width: 100%;
  padding: 10px;
  border-bottom-width: 1px;
  border-color: #ccc;
  box-sizing: border-box;
`;
const DropdownItem = _native.default.TouchableOpacity`
  padding: 10px;
`;
const DropdownItemText = _native.default.Text`
  color: #000;
`;
const Select = ({
  options,
  placeholder,
  onSelect,
  accentColor,
  selectedValue = null
}) => {
  const [isOpen, setIsOpen] = (0, _react.useState)(false);
  const [selected, setSelected] = (0, _react.useState)(selectedValue);
  const [searchTerm, setSearchTerm] = (0, _react.useState)('');
  const rotationAnim = (0, _react.useRef)(new _reactNative.Animated.Value(0)).current;
  const toggleDropdown = () => {
    setIsOpen(prev => !prev);
    _reactNative.Animated.timing(rotationAnim, {
      toValue: isOpen ? 0 : 1,
      duration: 300,
      useNativeDriver: true
    }).start();
  };
  const handleSelect = option => {
    setSelected(option);
    onSelect(option);
    setIsOpen(false);
    setSearchTerm('');
    _reactNative.Keyboard.dismiss();
  };
  const filteredOptions = options.filter(option => option.name.toLowerCase().includes(searchTerm.toLowerCase()));
  const rotateInterpolation = rotationAnim.interpolate({
    inputRange: [0, 1],
    outputRange: ['0deg', '180deg']
  });
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(SelectWrapper, {
    children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(SelectBox, {
      isOpen: isOpen,
      onPress: toggleDropdown,
      borderColor: accentColor,
      children: [selected ? /*#__PURE__*/(0, _jsxRuntime.jsx)(Placeholder, {
        children: selected.name
      }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(Placeholder, {
        children: placeholder
      }), /*#__PURE__*/(0, _jsxRuntime.jsx)(Icon, {
        style: {
          transform: [{
            rotate: rotateInterpolation
          }],
          color: accentColor
        },
        children: "\u25BC"
      })]
    }), isOpen && /*#__PURE__*/(0, _jsxRuntime.jsxs)(Dropdown, {
      children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(SearchBox, {
        placeholder: "Search...",
        value: searchTerm,
        onChangeText: setSearchTerm
      }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.FlatList, {
        data: filteredOptions,
        keyExtractor: item => item.id,
        renderItem: ({
          item
        }) => /*#__PURE__*/(0, _jsxRuntime.jsx)(DropdownItem, {
          onPress: () => handleSelect(item),
          children: /*#__PURE__*/(0, _jsxRuntime.jsx)(DropdownItemText, {
            children: item.name
          })
        }),
        ListEmptyComponent: /*#__PURE__*/(0, _jsxRuntime.jsx)(DropdownItem, {
          children: /*#__PURE__*/(0, _jsxRuntime.jsx)(DropdownItemText, {
            children: "No options found"
          })
        })
      })]
    })]
  });
};
var _default = exports.default = Select;
//# sourceMappingURL=Select.js.map