import React, {ReactNode} from 'react';
import {TouchableOpacity, Linking} from 'react-native';

type HyperlinkProps = {
    url: string;
    children: ReactNode;
};

const Hyperlink: React.FC<HyperlinkProps> = ({url, children}) => {
    const handlePress = () => {
        Linking.canOpenURL(url).then(supported => {
            if (supported) {
                Linking.openURL(url);
            } else {
                console.log("Don't know how to open URI: " + url);
            }
        });
    };

    return (
        <TouchableOpacity onPress={handlePress}>
            {children}
        </TouchableOpacity>
    );
};

export default Hyperlink;
