"use strict";

import React, { memo, useCallback } from 'react';
import { StyleSheet, View } from 'react-native';
import { Button } from "../button/index.js";
import { useTheme } from "../theme/use-theme.js";
import { Text } from "../typography/index.js";
import { fontSize, space } from "../styles/tokens.js";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
/**
 * Build the `AlertDialog` component bound to a platform `CenteredDialog`.
 *
 * `CenteredDialog` is platform-forked (native RN `Modal` vs pure-DOM web
 * overlay), and this repo never relies on implicit `.web` resolution — the
 * platform entry files (`index.ts` / `index.web.ts`) inject the correct
 * `CenteredDialog` here. The body below is single-source, no duplication.
 *
 * `AlertDialog` is a thin wrapper over `CenteredDialog` that lays out a title,
 * description and a confirm/cancel action row. Reach for the imperative
 * `confirm()` helper + `<AlertDialogHost />` to trigger a confirm from an
 * event handler without owning visible state.
 */
export function createAlertDialog(CenteredDialog) {
  const AlertDialogComponent = function AlertDialog({
    visible,
    onClose,
    title,
    description,
    confirmLabel = 'Confirm',
    cancelLabel = 'Cancel',
    onConfirm,
    onCancel,
    destructive = false,
    hideCancel = false,
    dismissible = false,
    cardStyle,
    testID
  }) {
    const theme = useTheme();
    const handleCancel = useCallback(() => {
      onCancel?.();
      onClose();
    }, [onCancel, onClose]);
    const handleConfirm = useCallback(() => {
      onConfirm?.();
      onClose();
    }, [onConfirm, onClose]);
    return /*#__PURE__*/_jsx(CenteredDialog, {
      visible: visible,
      onClose: dismissible ? onClose : () => {},
      dismissible: dismissible,
      title: title,
      showClose: false,
      accessibilityLabel: title,
      cardStyle: cardStyle,
      testID: testID,
      footer: /*#__PURE__*/_jsxs(View, {
        style: styles.actions,
        children: [!hideCancel ? /*#__PURE__*/_jsx(Button, {
          variant: "secondary",
          size: "medium",
          onPress: handleCancel,
          style: styles.action,
          accessibilityLabel: cancelLabel,
          children: cancelLabel
        }) : null, /*#__PURE__*/_jsx(Button, {
          variant: "primary",
          size: "medium",
          onPress: handleConfirm,
          style: [styles.action, destructive && {
            backgroundColor: theme.colors.negative
          }],
          textStyle: destructive ? {
            color: theme.colors.negativeForeground
          } : undefined,
          accessibilityLabel: confirmLabel,
          children: confirmLabel
        })]
      }),
      children: description ? /*#__PURE__*/_jsx(Text, {
        style: {
          fontSize: fontSize.md,
          lineHeight: fontSize.md * 1.4,
          color: theme.colors.textSecondary
        },
        children: description
      }) : null
    });
  };
  const AlertDialog = /*#__PURE__*/memo(AlertDialogComponent);
  AlertDialog.displayName = 'AlertDialog';
  return AlertDialog;
}
const styles = StyleSheet.create({
  actions: {
    flexDirection: 'row',
    justifyContent: 'flex-end',
    gap: space.sm
  },
  action: {
    minWidth: 96
  }
});
//# sourceMappingURL=AlertDialog.js.map