"use strict";

import { Animated, View } from 'react-native';
import styles from "./styles.js";
import { useContext, useEffect, useRef } from 'react';
import { ApplicationContext } from "../Context/index.js";
import { getTypoStyle } from "../Text/index.js";
import { Icon } from "../Icon/index.js";
import { Text } from "../Text/index.js";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
export const getBorderColor = (theme, focused, error, disabled) => {
  let borderColor = theme.colors.border.default;
  if (focused) {
    borderColor = theme.colors.primary.default;
  }
  if (error) {
    borderColor = theme.colors.error.default;
  }
  if (disabled) {
    borderColor = theme.colors.border.disable;
  }
  return {
    borderColor,
    borderWidth: 1
  };
};
export const getSizeStyle = size => {
  switch (size) {
    case 'medium':
      return styles.mediumContainer;
    case 'large':
      return styles.largeContainer;
    default:
      return styles.smallContainer;
  }
};
export const getIconSize = size => {
  switch (size) {
    case 'medium':
      return 20;
    case 'large':
      return 24;
    default:
      return 18;
  }
};
export const getFontStyle = (theme, size) => {
  switch (size) {
    case 'medium':
      return getTypoStyle(theme, 'subhead', 'semibold');
    case 'large':
      return getTypoStyle(theme, 'title3', 'bold');
    default:
      return getTypoStyle(theme, 'subhead');
  }
};
export const ErrorView = ({
  error,
  style
}) => {
  const {
    theme
  } = useContext(ApplicationContext);
  const errorHeight = useRef(new Animated.Value(0));
  useEffect(() => {
    if (error) {
      Animated.timing(errorHeight.current, {
        toValue: 20,
        duration: 300,
        useNativeDriver: false
      }).start();
    } else {
      Animated.timing(errorHeight.current, {
        toValue: 0,
        duration: 300,
        useNativeDriver: false
      }).start();
    }
  }, [error]);
  return /*#__PURE__*/_jsxs(Animated.View, {
    style: [styles.errorView, {
      height: errorHeight.current
    }, style],
    children: [/*#__PURE__*/_jsx(View, {
      style: styles.errorIcon,
      children: /*#__PURE__*/_jsx(Icon, {
        color: theme.colors.error.default,
        name: "alert-circle-outline",
        size: 16
      })
    }), /*#__PURE__*/_jsx(Text, {
      color: theme.colors.error.default,
      numberOfLines: 2,
      typography: 'caption1',
      children: error
    })]
  });
};
export const FloatingView = ({
  floatingValue,
  floatingIconColor,
  disabled,
  floatingIcon,
  required
}) => {
  const {
    theme
  } = useContext(ApplicationContext);
  if (floatingValue) {
    let floatingTextColor = theme.colors.text.hint;
    let floatingIconTintColor = floatingIconColor;
    if (disabled) {
      floatingTextColor = theme.colors.text.disable;
      floatingIconTintColor = theme.colors.text.disable;
    }
    return /*#__PURE__*/_jsxs(View, {
      style: [styles.floatingView, {
        backgroundColor: theme.colors.background.surface
      }],
      children: [/*#__PURE__*/_jsxs(Text, {
        color: floatingTextColor,
        typography: 'caption1',
        fontWeight: 'medium',
        numberOfLines: 1,
        children: [floatingValue, required && /*#__PURE__*/_jsx(Text, {
          typography: 'caption1',
          fontWeight: 'medium',
          color: theme.colors.error.default,
          children: "*"
        })]
      }), !!floatingIcon && /*#__PURE__*/_jsx(Icon, {
        color: floatingIconTintColor,
        name: floatingIcon,
        size: 16,
        style: styles.floatingIcon
      })]
    });
  }
  return null;
};
//# sourceMappingURL=common.js.map