/**
 * Created by rburson on 4/25/16.
 */

import * as React from 'react'
import {
    CvState,
    CvProps,
    CvBaseMixin,
} from 'catreact'
import {NavRequest, Log} from 'catavolt-sdk'
import {CvPopupPrompt, promptOpenUrl} from "./CvPopupPrompt";

export interface CvWebNavigatorState extends CvState { }

export interface CvWebNavigatorProps extends CvProps {
    promptForOpen?:boolean,
    url:string;
}

export var CvWebNavigator = React.createClass<CvWebNavigatorProps, CvWebNavigatorState>({

    mixins: [CvBaseMixin],

    getDefaultProps: function () {
        return {promptForOpen:false, url: null}
    },


    render: function() {
        if(this.props.url) {
            if (this.props.promptForOpen) {
                promptOpenUrl(this.props.url);
            } else if (!this.state.userAborted) {
                window.open(this.props.url, "_blank");
            }
        }
        return null;
    }


});