"use strict";

import { useContext } from 'react';
import { Pressable, TextInput, View } from 'react-native';
import { ErrorView, FloatingView, getBorderColor, getFontStyle, getIconSize, getSizeStyle } from "./common.js";
import { ApplicationContext } from "../Context/index.js";
import { Icon } from "../Icon/index.js";
import { SizedBox } from "../SizedBox/index.js";
import { Spacing } from "../Consts/index.js";
import styles from "./styles.js";
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
const InputDropDown = ({
  floatingValue,
  floatingIcon,
  leading,
  size = 'small',
  error,
  trailing,
  disabled,
  floatingIconColor,
  required,
  onPress,
  style,
  ...props
}) => {
  const {
    theme
  } = useContext(ApplicationContext);
  const renderInputView = () => {
    const disabledColor = theme.colors.text.disable;
    const iconSize = getIconSize(size);
    let textColor = theme.colors.text.default;
    let placeholderColor = theme.colors.text.hint;
    let iconColor;
    if (disabled) {
      textColor = disabledColor;
      placeholderColor = disabledColor;
      iconColor = disabledColor;
    }
    const renderLeadingIcon = () => {
      if (leading) {
        return /*#__PURE__*/_jsxs(_Fragment, {
          children: [/*#__PURE__*/_jsx(SizedBox, {
            width: Spacing.M
          }), typeof leading === 'string' ? /*#__PURE__*/_jsx(Icon, {
            color: iconColor,
            name: leading,
            size: iconSize
          }) : leading]
        });
      }
      return null;
    };
    const renderTrailingIcon = () => {
      if (trailing) {
        return /*#__PURE__*/_jsx(SizedBox, {
          width: iconSize,
          height: iconSize,
          children: typeof trailing === 'string' ? /*#__PURE__*/_jsx(Icon, {
            color: iconColor,
            name: trailing,
            size: iconSize
          }) : trailing
        });
      }
      return /*#__PURE__*/_jsx(Icon, {
        color: iconColor,
        name: 'chevron-down',
        size: iconSize
      });
    };
    return /*#__PURE__*/_jsxs(View, {
      style: [styles.inputWrapper, {
        backgroundColor: theme.colors.background.surface
      }, !!floatingValue && {
        marginTop: Spacing.S
      }, getSizeStyle(size), getBorderColor(theme, false, error, disabled)],
      children: [/*#__PURE__*/_jsx(FloatingView, {
        floatingValue: floatingValue,
        floatingIconColor: floatingIconColor,
        disabled: disabled,
        required: required,
        floatingIcon: floatingIcon
      }), renderLeadingIcon(), /*#__PURE__*/_jsx(Pressable, {
        style: styles.inputView,
        onPress: onPress,
        children: /*#__PURE__*/_jsx(TextInput, {
          ...props,
          onPress: onPress,
          editable: false,
          style: [styles.input, getFontStyle(theme, size), {
            color: textColor,
            lineHeight: undefined
          }, style],
          textBreakStrategy: "highQuality",
          selectionColor: theme.colors.primary.default,
          placeholderTextColor: placeholderColor
        })
      }), /*#__PURE__*/_jsx(View, {
        style: styles.iconView,
        children: renderTrailingIcon()
      })]
    });
  };
  return /*#__PURE__*/_jsxs(View, {
    style: styles.wrapper,
    children: [renderInputView(), /*#__PURE__*/_jsx(ErrorView, {
      error: error
    })]
  });
};
export default InputDropDown;
//# sourceMappingURL=InputDropDown.js.map