"use strict";

import { useCallback, useMemo } from "react";
import { StyleSheet, View } from "react-native";
import { IconButton } from "../buttons";
import { ContentWrapper, VStack } from "../layout";
import { NumberButton, numberButtonStyles } from "./NumberButton";
import { jsx as _jsx } from "react/jsx-runtime";
const mapIconSpecByBiometric = {
  FACE_ID: {
    icon: "biomFaceID",
    size: 32
  },
  TOUCH_ID: {
    icon: "fingerprint",
    size: 24
  },
  BIOMETRICS: {
    icon: "fingerprint",
    size: 24
  }
};

/**
 * This component displays a custom numeric keyboard.
 *
 * It accepts an optional `biometricType` prop which enables an extra keyboard button that accepts a `onBiometricPress` prop used to handle the action to be executed when it's pressed.
 * @returns {JSX.Element} The rendered numeric keyboard component.
 */
export const NumberPad = ({
  variant = "primary",
  biometricType,
  biometricAccessibilityLabel,
  deleteAccessibilityLabel,
  onNumberPress,
  onBiometricPress,
  onDeletePress
}) => {
  /**
   * Renders the buttons row from a given array.
   */
  // eslint-disable-next-line arrow-body-style
  const renderButtonsRow = useCallback(row => row.map(item => {
    if (typeof item === "number") {
      return /*#__PURE__*/_jsx(NumberButton, {
        number: item,
        onPress: onNumberPress,
        variant: variant
      }, item);
    }
    if (item === "delete") {
      return /*#__PURE__*/_jsx(ButtonWrapper, {
        children: /*#__PURE__*/_jsx(IconButton, {
          icon: "cancel",
          color: variant === "primary" ? "contrast" : "primary",
          onPress: onDeletePress,
          accessibilityLabel: deleteAccessibilityLabel
        })
      }, item);
    }
    if (biometricType && mapIconSpecByBiometric[biometricType]) {
      return /*#__PURE__*/_jsx(ButtonWrapper, {
        children: /*#__PURE__*/_jsx(IconButton, {
          icon: mapIconSpecByBiometric[biometricType].icon,
          iconSize: mapIconSpecByBiometric[biometricType].size,
          color: variant === "primary" ? "contrast" : "primary",
          onPress: onBiometricPress,
          accessibilityLabel: biometricAccessibilityLabel
        })
      }, item);
    }
    return /*#__PURE__*/_jsx(View, {
      style: numberButtonStyles.buttonSize
    }, "emptyElem");
  }), [biometricAccessibilityLabel, biometricType, deleteAccessibilityLabel, onBiometricPress, onDeletePress, onNumberPress, variant]);

  // eslint-disable-next-line arrow-body-style
  const numberPad = useMemo(() => /*#__PURE__*/_jsx(VStack, {
    space: 16,
    children: [[1, 2, 3], [4, 5, 6], [7, 8, 9], [biometricType, 0, "delete"]].map((row, i) => /*#__PURE__*/_jsx(View, {
      style: styles.numberPad,
      children: renderButtonsRow(row)
    }, i))
  }), [biometricType, renderButtonsRow]);
  return /*#__PURE__*/_jsx(ContentWrapper, {
    children: numberPad
  });
};
const ButtonWrapper = ({
  children
}) => /*#__PURE__*/_jsx(View, {
  style: [numberButtonStyles.buttonSize, {
    alignItems: "center",
    justifyContent: "center"
  }],
  children: children
});
const styles = StyleSheet.create({
  numberPad: {
    flexDirection: "row",
    justifyContent: "space-between",
    alignItems: "center",
    flexGrow: 1
  }
});
//# sourceMappingURL=NumberPad.js.map