import React, { cloneElement, forwardRef, useImperativeHandle, useState, } from 'react'; import type {StyleProp, TextStyle, ViewStyle} from 'react-native'; import { Modal, Platform, StyleSheet, TouchableWithoutFeedback, } from 'react-native'; import {useTheme} from '@dooboo-ui/theme'; import styled, {css} from '@emotion/native'; import {Button} from '../../uis/Button'; import {Icon} from '../../uis/Icon'; import {Typography} from '../../uis/Typography'; const Container = styled.View` flex: 1; justify-content: center; align-items: center; flex-direction: row; `; const AlertDialogContainer = styled.View` flex: 0.87; background-color: ${({theme}) => theme.bg.basic}; padding: 20px 20px 28px 24px; border-radius: 8px; `; const TitleRow = styled.View` flex-direction: row; justify-content: space-between; align-items: center; `; const BodyRow = styled.View` margin-top: 12px; margin-bottom: 8px; `; const ActionRow = styled.View` margin-top: 20px; padding-right: 4px; flex-direction: row; `; export type AlertDialogProps = { style?: StyleProp; }; export type AlertDialogStyles = { container?: StyleProp; titleContainer?: StyleProp; title?: StyleProp; bodyContainer?: StyleProp; body?: StyleProp; actionContainer?: StyleProp; }; export type AlertDialogOptions = { styles?: AlertDialogStyles; title?: string | JSX.Element; body?: string | JSX.Element; backdropOpacity?: number; closeOnTouchOutside?: boolean; actions?: JSX.Element[]; }; export type AlertDialogContext = { open(alertDialogOptions?: AlertDialogOptions): void; close(): void; }; function AlertDialog( {style}: AlertDialogProps, ref: React.Ref, ): JSX.Element { const [options, setOptions] = useState(null); const [visible, setVisible] = useState(false); const {theme, themeType} = useTheme(); useImperativeHandle(ref, () => ({ open: (alertDialogOptions) => { setVisible(true); if (alertDialogOptions) { setOptions(alertDialogOptions); } }, close: () => { setVisible(false); setOptions(null); }, })); const { backdropOpacity = 0.2, title, body, styles, actions, closeOnTouchOutside = true, } = options ?? {}; const AlertDialogContent = ( {typeof title === 'string' ? ( {title} ) : ( title )}