import React, { memo } from 'react';
import { View, Text } from 'react-native';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import TouchableOpacity from '../TouchableOpacity';
import Popup from '../Popup';
import Loading from '../Loading';
import { useThemeFactory } from '../Theme';
import { createStyle } from './style';
import type { ActionSheetProps, ActionSheetAction } from './type';
const ActionSheet = (props: ActionSheetProps): JSX.Element => {
const {
actions = [],
cancelText,
description,
children,
onSelect,
onCancel,
onClose,
...rest
} = props;
const { styles, theme } = useThemeFactory(createStyle);
const insets = useSafeAreaInsets();
const activeBackground = theme.active_color;
const handleCancel = () => {
onClose?.();
onCancel?.();
};
const handleSelect: ActionSheetProps['onSelect'] = (action, index) => {
action?.callback?.(action);
onSelect?.(action, index);
onClose?.();
};
const renderItem = (it: ActionSheetAction, index: number) => (
handleSelect(it, index)}
activeBackgroundColor={activeBackground}
disabled={it.disabled || it.loading}
>
{it.loading ? (
) : (
<>
{it.name}
{!!it.subname && {it.subname}}
>
)}
);
return (
{children || (
{!!description && (
<>
{description}
>
)}
{actions.map(renderItem)}
{!!cancelText && (
<>
{cancelText}
>
)}
)}
);
};
export default memo(ActionSheet);