"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.createAlertDialog = createAlertDialog;
var _react = _interopRequireWildcard(require("react"));
var _reactNative = require("react-native");
var _index = require("../button/index.js");
var _useTheme = require("../theme/use-theme.js");
var _index2 = require("../typography/index.js");
var _tokens = require("../styles/tokens.js");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
/**
 * 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.
 */
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 = (0, _useTheme.useTheme)();
    const handleCancel = (0, _react.useCallback)(() => {
      onCancel?.();
      onClose();
    }, [onCancel, onClose]);
    const handleConfirm = (0, _react.useCallback)(() => {
      onConfirm?.();
      onClose();
    }, [onConfirm, onClose]);
    return /*#__PURE__*/(0, _jsxRuntime.jsx)(CenteredDialog, {
      visible: visible,
      onClose: dismissible ? onClose : () => {},
      dismissible: dismissible,
      title: title,
      showClose: false,
      accessibilityLabel: title,
      cardStyle: cardStyle,
      testID: testID,
      footer: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
        style: styles.actions,
        children: [!hideCancel ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_index.Button, {
          variant: "secondary",
          size: "medium",
          onPress: handleCancel,
          style: styles.action,
          accessibilityLabel: cancelLabel,
          children: cancelLabel
        }) : null, /*#__PURE__*/(0, _jsxRuntime.jsx)(_index.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__*/(0, _jsxRuntime.jsx)(_index2.Text, {
        style: {
          fontSize: _tokens.fontSize.md,
          lineHeight: _tokens.fontSize.md * 1.4,
          color: theme.colors.textSecondary
        },
        children: description
      }) : null
    });
  };
  const AlertDialog = /*#__PURE__*/(0, _react.memo)(AlertDialogComponent);
  AlertDialog.displayName = 'AlertDialog';
  return AlertDialog;
}
const styles = _reactNative.StyleSheet.create({
  actions: {
    flexDirection: 'row',
    justifyContent: 'flex-end',
    gap: _tokens.space.sm
  },
  action: {
    minWidth: 96
  }
});
//# sourceMappingURL=AlertDialog.js.map