import React, { Component } from 'react';
import {LaunchApp, ua, isIos, inWeixin, detector, supportLink} from 'web-launch-app';
import CallApp from 'callapp-lib'

const options = {
    scheme: {
        protocol: 'julyedu',
        host: '',
        port: ''
    },
    intent: {
        package: "com.julyapp.julyonline",
        scheme: "julyedu",
        action: 'julyapp.julyedu',
        category: 'category_julyedu'
    },
    universal: {
        host: "api.julyedu.com/action",
        pathKey: 'page'
    },
    appstore: "https://itunes.apple.com/cn/app/id1102275343?mt=8",
    yingyongbao: "http://android.myapp.com/myapp/detail.htm?apkName=com.julyapp.julyonline",
    fallback: "http://www.julyedu.com/weekend/redir1"
}

const inApp = /appname(.*)/.test(ua);
const appVersion = inApp ? /appname\/(\d+(\.\d+)*)/.exec(ua)[1] : '';
// 微信iOS7.0.5支持ulink（20190716）
const wxSupportLink = isIos && inWeixin && detector.browser.fullVersion > '7.0.4';
const config = {
    inApp: inApp,
    appVersion: appVersion,
    pkgName: 'julyedu',
    deeplink: {
        scheme: {
            android: {
                protocol: 'julyedu',
                index: {
                    path: '/',
                },
                frs: {
                    protocol: 'app',
                    path: 'forum/detail',
                    param: {from:'h5'},
                    paramMap: {
                        forumName: 'kw'
                    }
                }
            },
            ios: {
                protocol: 'julyedu',
                index: {
                    path: '/',
                },
                frs: {
                    path: 'forum/detail'
                }
            }
        },
        link: {
            index: {url: 'https://link.app.com'},
            frs: {url: 'https://link.app.com/p/{forumName}'}
        },
    },
    pkgs: {
        android: 'https://cdn.app.com/package/app-defult.apk',
        ios: 'https://itunes.apple.com/cn/app/id1102275343?mt=8',
        yyb: 'hhttp://android.myapp.com/myapp/detail.htm?apkName=com.julyapp.julyonline',
    },
    useUniversalLink: supportLink,
    useAppLink: supportLink,
    autodemotion: true,
    useYingyongbao: inWeixin,
    useGuideMethod: inWeixin && !wxSupportLink, // 受限情况下使用引导方案
    landPage: 'http://www.julyedu.com/weekend/redir1'
};

class OpenApp extends Component {

    // callApp = new CallApp(options)
    lanchApp = null

    static defaultProps = {
        text: '在APP打开'
    }

   
    componentWillMount() {
        // this.callApp = new CallApp(options);
        this.lanchApp = new LaunchApp(config);
    }

    handleClick = () => {
        // this.callApp.open({})
        this.lanchApp.open();
    }

    render() {
        return (
            <div className={this.props.className} onClick={this.handleClick}>{this.props.text}</div>
        );
    }
}

export default OpenApp;
