"use strict";var pickerOauthToken,pickerDeveloperKey="",pickerClientId="",pickerScope=["https://www.googleapis.com/auth/drive.readonly"],pickerApiLoaded=!1;function wpieLoadPicker(){gapi.load("auth",{callback:wpieOnAuthApiLoad}),gapi.load("picker",{callback:wpieOnPickerApiLoad})}function wpieOnAuthApiLoad(){window.gapi.auth.authorize({client_id:pickerClientId,scope:pickerScope,immediate:!1},wpieHandleAuthResult)}function wpieOnPickerApiLoad(){pickerApiLoaded=!0,wpieCreatePicker()}function wpieHandleAuthResult(e){e&&!e.error&&(pickerOauthToken=e.access_token,wpieCreatePicker())}function wpieCreatePicker(){pickerApiLoaded&&pickerOauthToken&&(new google.picker.PickerBuilder).addViewGroup(new google.picker.ViewGroup(google.picker.ViewId.DOCS).addView(google.picker.ViewId.DOCUMENTS).addView(google.picker.ViewId.PRESENTATIONS)).setOAuthToken(pickerOauthToken).setDeveloperKey(pickerDeveloperKey).setCallback(wpiePickerCallback).build().setVisible(!0)}function wpiePickerCallback(e){if(e[google.picker.Response.ACTION]==google.picker.Action.PICKED){wpieSetProcessLoader({wpieDownloadFileText:wpiePluginSettings.wpieLocalizeText.wpieDownloadFileText});var i=e[google.picker.Response.DOCUMENTS][0];jQuery.ajax({url:wpiePluginSettings.wpieAjaxURL,type:"POST",data:"action=wpie_import_upload_file_from_googledrive&wpie_import_id="+wpiePluginSettings.wpieImportId+"&fileId="+i.id+"&oAuthToken="+pickerOauthToken+"&name="+i.name,dataType:"json",async:!0,success:function(e){if(wpieUpdateProcessLoader("wpieDownloadFileText"),"error"==e.status)return wpieSetErrorMsg(e.message),!1;wpieSetFileData(e)},error:function(e,i){wpieHandleAjaxError(e,i)}})}}jQuery(document).on("click",".wpie_google_drive_upload_btn",function(){pickerDeveloperKey=jQuery(".wpie_gd_developer_key").val(),""!=(pickerClientId=jQuery(".wpie_gd_client_id").val())&&wpieLoadPicker()});