"use strict";

import React, { createContext, useContext, useMemo } from 'react';
import { View, Text as RNText, Pressable, StyleSheet } from 'react-native';
import { useTheme } from "../theme/use-theme.js";
import { useInteractionState } from "../hooks/useInteractionState.js";
import { dismiss } from './sonner';
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
const ToastConfigContext = /*#__PURE__*/createContext({
  id: '',
  type: 'default'
});
ToastConfigContext.displayName = 'ToastConfigContext';
export function ToastConfigProvider({
  children,
  id,
  type
}) {
  return /*#__PURE__*/_jsx(ToastConfigContext.Provider, {
    value: useMemo(() => ({
      id,
      type
    }), [id, type]),
    children: children
  });
}
export function Outer({
  children
}) {
  const {
    colors
  } = useTheme();
  const {
    type
  } = useContext(ToastConfigContext);
  const toastColors = useToastColors({
    type,
    colors
  });
  return /*#__PURE__*/_jsx(View, {
    style: [styles.outer, {
      backgroundColor: toastColors.backgroundColor,
      borderColor: toastColors.borderColor
    }],
    children: children
  });
}
export function Icon({
  icon
}) {
  const {
    colors
  } = useTheme();
  const {
    type
  } = useContext(ToastConfigContext);
  const toastColors = useToastColors({
    type,
    colors
  });
  if (!icon) {
    return null;
  }
  if (/*#__PURE__*/React.isValidElement(icon)) {
    return /*#__PURE__*/React.cloneElement(icon, {
      color: toastColors.iconColor
    });
  }
  return /*#__PURE__*/_jsx(_Fragment, {
    children: icon
  });
}
export function Text({
  children
}) {
  const {
    colors
  } = useTheme();
  const {
    type
  } = useContext(ToastConfigContext);
  const toastColors = useToastColors({
    type,
    colors
  });
  return /*#__PURE__*/_jsx(View, {
    style: styles.textContainer,
    children: /*#__PURE__*/_jsx(RNText, {
      selectable: false,
      style: [styles.text, {
        color: toastColors.textColor
      }],
      children: children
    })
  });
}
export function Action({
  children,
  onPress,
  ...rest
}) {
  const {
    colors
  } = useTheme();
  const {
    type,
    id
  } = 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
  } = useInteractionState();
  const handlePress = e => {
    dismiss(id);
    onPress?.(e);
  };
  return /*#__PURE__*/_jsx(Pressable, {
    ...rest,
    onPress: handlePress,
    onPressIn: onPressIn,
    onPressOut: onPressOut,
    style: [styles.actionButton, {
      backgroundColor: pressed ? actionColors.interacted.backgroundColor : actionColors.base.backgroundColor
    }],
    children: /*#__PURE__*/_jsx(RNText, {
      style: [styles.actionText, {
        color: pressed ? actionColors.interacted.textColor : actionColors.base.textColor
      }],
      children: children
    })
  });
}
function useToastColors({
  type,
  colors
}) {
  return 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 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 = 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