import React from 'react';
import {
NativeModules
} from 'react-native';
var PokktExtension = function () {};

/**
 * Pokkt Standard APIs
 **/
 
PokktExtension.prototype.setPokktConfig = function (appId, securityKey) {
    notifyNative('setPokktConfig', undefined, JSON.stringify({"appId":appId,"securityKey":securityKey}));
};

PokktExtension.prototype.setDataAccessConsent = function (GDPRApplicable, GDPRConsentAvailable) {
    notifyNative('setDataAccessConsent', undefined, JSON.stringify({"GDPRApplicable":GDPRApplicable,"GDPRConsentAvailable":GDPRConsentAvailable}));
};

PokktExtension.prototype.setThirdPartyUserId = function (thirdPartyUserId) {
    notifyNative('setThirdPartyUserId', undefined, thirdPartyUserId);
};

PokktExtension.prototype.getSDKVersion = function (callback) {
    notifyNative('getSDKVersion', callback);
};

PokktExtension.prototype.setAdPlayerViewConfig = function(adPlayerViewConfig) {
    notifyNative('setAdVPlayeriewConfig', undefined, adPlayerViewConfig);
};

PokktExtension.prototype.setUserDetails = function(userDetails) {
    notifyNative('setUserDetails', undefined, userDetails);
};
/**
 * Values that developers need in the POKKT server callback
 */
PokktExtension.prototype.setCallbackExtraParams = function(extraParams) {
    notifyNative('setCallbackExtraParams', undefined, extraParams);
};

/**
 * Debugging related APIs
 **/
 
PokktExtension.prototype.setDebug = function (debug) {
    notifyNative('Debugging_shouldDebug', undefined, debug);
};

PokktExtension.prototype.exportLog = function () {
    notifyNative('Debugging_exportLog');
};

PokktExtension.prototype.exportLogToCloud = function () {
    notifyNative('Debugging_exportLogToCloud');
};

PokktExtension.prototype.showLog = function (message) {
    notifyNative('Debugging_showLog', undefined, message);
};

PokktExtension.prototype.showToast = function (message) {
    notifyNative('Debugging_showToast', undefined, message);
};


/**
 * FullScreen Ad related APIs
 **/

PokktExtension.prototype.cacheAd = function(screenId) {
    notifyNative('cacheAd', undefined, screenId);
};

PokktExtension.prototype.showAd = function(screenId) {
    notifyNative('showAd', undefined, screenId);
};

PokktExtension.prototype.isAdCached = function(screenId, callback) {
    notifyNative('isAdCached', callback, JSON.stringify({"screenId":screenId}));
};
/**
 * Banner
 */
PokktExtension.prototype.showAd = function(screenId, position) {
    notifyNative('showAd', undefined, JSON.stringify({"screenId":screenId,"bannerPosition":position}));
};

PokktExtension.prototype.destroyBanner = function(screenId) {
    var param = {
    "screenId" : screenId,
    "bannerPosition" : '8'
    }
    notifyNative('destroyBanner', undefined, JSON.stringify(param));
};

/**
 * createAdPlayerViewConfig Method
 **/

PokktExtension.prototype.createAdPlayerViewConfig = function () {
    return {
        backButtonDisabled:true,
        shouldAllowSkip: true,
        defaultSkipTime: 5,
        skipConfirmMessage: 'Do you want to skip the video?',
        shouldAllowMute: true,
        shouldSkipConfirm: true,
        skipConfirmYesLabel: 'Okay',
        skipConfirmNoLabel: 'Nope',
        skipTimerMessage: 'Must watch for ## seconds',
        incentiveMessage: '## more seconds to go!',
        shouldCollectFeedback: true,
        isAudioEnabled:true
    };
};

/**
 * createUserDetails Method
 **/

PokktExtension.prototype.createUserDetails = function () {
    return {
     	name: '',
        age: '',
        sex: '',
        mobileNo: '',
        emailAddress: '',
        location: '',
        birthday: '',
        maritalStatus: '',
        facebookId: '',
        twitterHandle: '',
        education: '',
        nationality: '',
        employment: '',
        maturityRating: ''
    };
};

// ------- NATIVE NOTIFIERS -------

function notifyNative(operation, successCallback, param) {
    if (successCallback == null || successCallback == undefined) {
        successCallback = function (result) {
            console.log(operation + ' was successful! result: ' + result);
        };
    }

    var errorCallback = function(error) {
        console.log(operation + ' failed! error: ' + error);
    };

    console.log('executing operation: ' + operation + ' with param: ' + param);
    NativeModules.PokktPlugin.execute(operation,param,successCallback);
}


// ------------------------------

if (!window.plugins) {
    window.plugins = {};
}

if (!window.plugins.pokktExtension) {
    window.plugins.pokktExtension = new PokktExtension();
}

if (typeof module != 'undefined' && module.exports) {
    module.exports = PokktExtension;
}
// ------------------------------
