/* Copyright (C) Click & Push Accessibility, Inc - All Rights Reserved
 * Unauthorized copying of this file, via any medium is strictly prohibited
 * Proprietary and confidential
 * Written and maintained by the Click & Push Development team 
 * <dev@clicknpush.ca>, January 2022
 */

import * as WebBrowser from 'expo-web-browser'
import React from "react"
import { Text, TouchableOpacity, ViewStyle } from "react-native"
import { API_URL } from "../../../utils/RequestUtils"
import { ProfileSection } from "./ProfileSection"

interface ProfileLegalProps {
    openLegal: () => void
    legalCollapsed: boolean
}

export const BrowserLink: React.FC<{text:string, route:string, style?: ViewStyle}> = ({style, text, route}) => {
    return (
        <TouchableOpacity style={[{alignItems: 'center'}, style]} onPress={async () => await WebBrowser.openBrowserAsync(API_URL + "/" + route)}>
            <Text style={{fontWeight: 'bold', }}>{text}</Text>
        </TouchableOpacity>
    )
}

export const ProfileLegal: React.FC<ProfileLegalProps> = ({openLegal, legalCollapsed}) => {    
    return (
        <ProfileSection isCollapsed={legalCollapsed} collapseToggleMethod={openLegal} title="Terms">
            <BrowserLink style={{marginBottom: 10}} text="Mobile app third-party licenses" route="mobile-tpl"/>
            <BrowserLink text="API third-party licenses" route="api-tpl"/>
        </ProfileSection>
    )
}