"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Action = Action;
exports.Icon = Icon;
exports.Outer = Outer;
exports.Text = Text;
exports.ToastConfigProvider = ToastConfigProvider;
var _react = _interopRequireWildcard(require("react"));
var _reactNative = require("react-native");
var _useTheme = require("../theme/use-theme.js");
var _useInteractionState = require("../hooks/useInteractionState.js");
var _sonner = require("./sonner");
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); }
const ToastConfigContext = /*#__PURE__*/(0, _react.createContext)({
  id: '',
  type: 'default'
});
ToastConfigContext.displayName = 'ToastConfigContext';
function ToastConfigProvider({
  children,
  id,
  type
}) {
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(ToastConfigContext.Provider, {
    value: (0, _react.useMemo)(() => ({
      id,
      type
    }), [id, type]),
    children: children
  });
}
function Outer({
  children
}) {
  const {
    colors
  } = (0, _useTheme.useTheme)();
  const {
    type
  } = (0, _react.useContext)(ToastConfigContext);
  const toastColors = useToastColors({
    type,
    colors
  });
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
    style: [styles.outer, {
      backgroundColor: toastColors.backgroundColor,
      borderColor: toastColors.borderColor
    }],
    children: children
  });
}
function Icon({
  icon
}) {
  const {
    colors
  } = (0, _useTheme.useTheme)();
  const {
    type
  } = (0, _react.useContext)(ToastConfigContext);
  const toastColors = useToastColors({
    type,
    colors
  });
  if (!icon) {
    return null;
  }
  if (/*#__PURE__*/_react.default.isValidElement(icon)) {
    return /*#__PURE__*/_react.default.cloneElement(icon, {
      color: toastColors.iconColor
    });
  }
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
    children: icon
  });
}
function Text({
  children
}) {
  const {
    colors
  } = (0, _useTheme.useTheme)();
  const {
    type
  } = (0, _react.useContext)(ToastConfigContext);
  const toastColors = useToastColors({
    type,
    colors
  });
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
    style: styles.textContainer,
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
      selectable: false,
      style: [styles.text, {
        color: toastColors.textColor
      }],
      children: children
    })
  });
}
function Action({
  children,
  onPress,
  ...rest
}) {
  const {
    colors
  } = (0, _useTheme.useTheme)();
  const {
    type,
    id
  } = (0, _react.useContext)(ToastConfigContext);
  const actionColors = useActionColors({
    type,
    colors
  });
  // Drive the pressed visual via state, not Pressable's function-form `style`
  // / function-children, which NativeWind v4's css-interop swallows (dropping
  // the base button style: padding, radius, alignSelf).
  const {
    state: pressed,
    onIn: onPressIn,
    onOut: onPressOut
  } = (0, _useInteractionState.useInteractionState)();
  const handlePress = e => {
    (0, _sonner.dismiss)(id);
    onPress?.(e);
  };
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Pressable, {
    ...rest,
    onPress: handlePress,
    onPressIn: onPressIn,
    onPressOut: onPressOut,
    style: [styles.actionButton, {
      backgroundColor: pressed ? actionColors.interacted.backgroundColor : actionColors.base.backgroundColor
    }],
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
      style: [styles.actionText, {
        color: pressed ? actionColors.interacted.textColor : actionColors.base.textColor
      }],
      children: children
    })
  });
}
function useToastColors({
  type,
  colors
}) {
  return (0, _react.useMemo)(() => {
    const colorMap = {
      default: {
        backgroundColor: colors.backgroundSecondary,
        borderColor: colors.border,
        iconColor: colors.text,
        textColor: colors.text
      },
      success: {
        backgroundColor: colors.primarySubtle,
        borderColor: colors.primary,
        iconColor: colors.primarySubtleForeground,
        textColor: colors.primarySubtleForeground
      },
      error: {
        backgroundColor: colors.negativeSubtle,
        borderColor: colors.negative,
        iconColor: colors.negativeSubtleForeground,
        textColor: colors.negativeSubtleForeground
      },
      warning: {
        backgroundColor: colors.backgroundSecondary,
        borderColor: colors.border,
        iconColor: colors.warning,
        textColor: colors.text
      },
      info: {
        backgroundColor: colors.backgroundSecondary,
        borderColor: colors.border,
        iconColor: colors.info,
        textColor: colors.text
      }
    };
    return colorMap[type];
  }, [type, colors]);
}
function useActionColors({
  type,
  colors
}) {
  return (0, _react.useMemo)(() => {
    const base = {
      base: {
        textColor: colors.textSecondary,
        backgroundColor: colors.backgroundTertiary
      },
      interacted: {
        textColor: colors.text,
        backgroundColor: colors.contrast50
      }
    };
    const colorMap = {
      default: base,
      warning: base,
      info: base,
      success: {
        base: {
          textColor: colors.primarySubtleForeground,
          backgroundColor: colors.primarySubtle
        },
        interacted: {
          textColor: colors.primaryDark,
          backgroundColor: colors.primaryLight
        }
      },
      error: {
        base: {
          textColor: colors.negativeSubtleForeground,
          backgroundColor: colors.negativeSubtle
        },
        interacted: {
          textColor: colors.negativeForeground,
          backgroundColor: colors.negative
        }
      }
    };
    return colorMap[type];
  }, [type, colors]);
}
const styles = _reactNative.StyleSheet.create({
  outer: {
    flex: 1,
    padding: 16,
    borderRadius: 8,
    borderWidth: 1,
    flexDirection: 'row',
    gap: 8,
    paddingVertical: 14,
    shadowColor: '#000',
    shadowOffset: {
      width: 0,
      height: 1
    },
    shadowOpacity: 0.05,
    shadowRadius: 2,
    elevation: 2
  },
  textContainer: {
    flex: 1,
    paddingRight: 16
  },
  text: {
    fontSize: 15,
    fontWeight: '500',
    lineHeight: 20
  },
  actionButton: {
    paddingVertical: 5,
    paddingHorizontal: 9,
    borderRadius: 6,
    alignSelf: 'center'
  },
  actionText: {
    fontSize: 15,
    fontWeight: '500',
    lineHeight: 20
  }
});
//# sourceMappingURL=Toast.js.map