"use strict";

import { useContext, useState } from 'react';
import { TouchableOpacity, View } from 'react-native';
import { ApplicationContext } from "../Context/index.js";
import { Colors, Styles } from "../Consts/index.js";
import { Icon } from "../Icon/index.js";
import { Text } from "../Text/index.js";
import styles from "./styles.js";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
const Stepper = ({
  defaultValue = 0,
  max = 100,
  min = 0,
  onChange,
  style
}) => {
  const {
    theme
  } = useContext(ApplicationContext);
  const [value, setValue] = useState(defaultValue);

  /**
   * on increase value
   */
  const onIncrease = () => {
    if (value < max) {
      setValue(value + 1);
      onChange?.(value + 1);
    }
  };

  /**
   * on decrease value
   */
  const onDecrease = () => {
    if (value > min) {
      setValue(value - 1);
      onChange?.(value - 1);
    }
  };
  const decrease = value > min;
  const increase = value < max;
  return /*#__PURE__*/_jsxs(View, {
    style: [Styles.row, style],
    children: [/*#__PURE__*/_jsx(TouchableOpacity, {
      onPress: onDecrease,
      style: [styles.step, {
        backgroundColor: decrease ? theme.colors.primary.default : theme.colors.background.disable
      }],
      children: /*#__PURE__*/_jsx(Icon, {
        name: 'minus',
        color: decrease ? Colors.white : theme.colors.text.hint
      })
    }), /*#__PURE__*/_jsx(View, {
      style: [styles.value, {
        borderColor: theme.colors.border.default
      }],
      children: /*#__PURE__*/_jsx(Text, {
        typography: 'callout',
        children: value
      })
    }), /*#__PURE__*/_jsx(TouchableOpacity, {
      onPress: onIncrease,
      style: [styles.step, {
        backgroundColor: increase ? theme.colors.primary.default : theme.colors.background.disable
      }],
      children: /*#__PURE__*/_jsx(Icon, {
        name: 'plus',
        color: increase ? Colors.white : theme.colors.text.hint
      })
    })]
  });
};
export { Stepper };
//# sourceMappingURL=index.js.map