import React__default, { useCallback } from 'react';
import { InformationCircleIcon, ExclamationTriangleIcon, XCircleIcon, CheckCircleIcon } from '@heroicons/react/24/solid';
import { useToastContext } from './ToastProvider.js';

const createSemanticIcon = (IconComponent, colorClass) => {
    return React__default.createElement(IconComponent, {
        className: `w-5 h-5 ${colorClass}`,
    });
};
const useToast = () => {
    const { addToast, removeToast, removeAllToasts } = useToastContext();
    const toast = useCallback((title, options) => {
        return addToast({
            title,
            variant: options === null || options === void 0 ? void 0 : options.variant,
            state: (options === null || options === void 0 ? void 0 : options.state) || 'default',
            subtitle: options === null || options === void 0 ? void 0 : options.subtitle,
            duration: options === null || options === void 0 ? void 0 : options.duration,
            dismissible: options === null || options === void 0 ? void 0 : options.dismissible,
            action: options === null || options === void 0 ? void 0 : options.action,
            icon: options === null || options === void 0 ? void 0 : options.icon,
        });
    }, [addToast]);
    const success = useCallback((title, options) => {
        return addToast({
            title,
            variant: options === null || options === void 0 ? void 0 : options.variant,
            state: (options === null || options === void 0 ? void 0 : options.state) || 'default',
            subtitle: options === null || options === void 0 ? void 0 : options.subtitle,
            duration: options === null || options === void 0 ? void 0 : options.duration,
            dismissible: options === null || options === void 0 ? void 0 : options.dismissible,
            action: options === null || options === void 0 ? void 0 : options.action,
            icon: (options === null || options === void 0 ? void 0 : options.icon) || createSemanticIcon(CheckCircleIcon, 'text-[var(--color-success)]'),
        });
    }, [addToast]);
    const error = useCallback((title, options) => {
        return addToast({
            title,
            variant: options === null || options === void 0 ? void 0 : options.variant,
            state: (options === null || options === void 0 ? void 0 : options.state) || 'default',
            subtitle: options === null || options === void 0 ? void 0 : options.subtitle,
            duration: options === null || options === void 0 ? void 0 : options.duration,
            dismissible: options === null || options === void 0 ? void 0 : options.dismissible,
            action: options === null || options === void 0 ? void 0 : options.action,
            icon: (options === null || options === void 0 ? void 0 : options.icon) || createSemanticIcon(XCircleIcon, 'text-[var(--color-danger)]'),
        });
    }, [addToast]);
    const warning = useCallback((title, options) => {
        return addToast({
            title,
            variant: options === null || options === void 0 ? void 0 : options.variant,
            state: (options === null || options === void 0 ? void 0 : options.state) || 'default',
            subtitle: options === null || options === void 0 ? void 0 : options.subtitle,
            duration: options === null || options === void 0 ? void 0 : options.duration,
            dismissible: options === null || options === void 0 ? void 0 : options.dismissible,
            action: options === null || options === void 0 ? void 0 : options.action,
            icon: (options === null || options === void 0 ? void 0 : options.icon) || createSemanticIcon(ExclamationTriangleIcon, 'text-[var(--color-warning)]'),
        });
    }, [addToast]);
    const info = useCallback((title, options) => {
        return addToast({
            title,
            variant: options === null || options === void 0 ? void 0 : options.variant,
            state: (options === null || options === void 0 ? void 0 : options.state) || 'default',
            subtitle: options === null || options === void 0 ? void 0 : options.subtitle,
            duration: options === null || options === void 0 ? void 0 : options.duration,
            dismissible: options === null || options === void 0 ? void 0 : options.dismissible,
            action: options === null || options === void 0 ? void 0 : options.action,
            icon: (options === null || options === void 0 ? void 0 : options.icon) || createSemanticIcon(InformationCircleIcon, 'text-[var(--color-primary)]'),
        });
    }, [addToast]);
    const loading = useCallback((title, options) => {
        var _a, _b;
        return addToast({
            title,
            variant: options === null || options === void 0 ? void 0 : options.variant,
            state: 'loading',
            subtitle: options === null || options === void 0 ? void 0 : options.subtitle,
            duration: (_a = options === null || options === void 0 ? void 0 : options.duration) !== null && _a !== void 0 ? _a : 0, // Loading toasts don't auto-dismiss by default
            dismissible: (_b = options === null || options === void 0 ? void 0 : options.dismissible) !== null && _b !== void 0 ? _b : false, // Loading toasts are not dismissible by default
            action: options === null || options === void 0 ? void 0 : options.action,
            icon: options === null || options === void 0 ? void 0 : options.icon,
        });
    }, [addToast]);
    const dismiss = useCallback((id) => {
        removeToast(id);
    }, [removeToast]);
    const dismissAll = useCallback(() => {
        removeAllToasts();
    }, [removeAllToasts]);
    return {
        toast,
        success,
        error,
        warning,
        info,
        loading,
        dismiss,
        dismissAll,
    };
};

export { useToast };
