(()=>{"use strict";function e(e){var t;return!e||!e.type||("application/vnd.google-apps.folder"===e.type||"application/vnd.google-apps.folder"===(null===(t=e.shortcutDetails)||void 0===t?void 0:t.targetMimeType))}function t(e,t){var o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},l=e.id,r=e.iconLink,a=e.thumbnailLink;e.accountId;e.shortcutDetails&&(l=e.shortcutDetails.targetId);var c=o.w,d=o.h;c||(c=64),d||(d=64);var s=null==r?void 0:r.replace("/16/","/".concat(c,"/"));return a&&(s=i(e)?"custom"===t?"https://drive.google.com/thumbnail?id=".concat(l,"&sz=w").concat(c,"-h").concat(d):"https://drive.google.com/thumbnail?id=".concat(l,"small"===t?"&sz=w300-h300":"medium"===t?"&sz=w600-h400":"large"===t?"&sz=w1024-h768":"full"===t?"&sz=w2048":"&sz=w300-h300"):a.includes("google.com")?"custom"===t?a.replace("=s220","=w".concat(c,"-h").concat(d)):"small"===t?a.replace("=s220","=w300-h300"):"medium"===t?a.replace("=s220","=h600-nu"):"large"===t?a.replace("=s220","=w1024-h768-p-k-nu"):"full"===t?a.replace("=s220",""):a.replace("=s220","=w200-h190-p-k-nu"):function(e,t){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:300,o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:300,l={id:e.id,accountId:e.accountId,size:t};"custom"===t&&(l.w=i,l.h=o);var r=n(JSON.stringify(l));return"".concat(igd.homeUrl,"/?igd_preview_image=").concat(r)}(e,t,c,d)),s}function i(e){var t,i;return"reader"===(null===(t=e.permissions)||void 0===t||null===(t=t.users)||void 0===t||null===(t=t.anyoneWithLink)||void 0===t?void 0:t.role)||"writer"===(null===(i=e.permissions)||void 0===i||null===(i=i.users)||void 0===i||null===(i=i.anyoneWithLink)||void 0===i?void 0:i.role)}function n(e){return btoa(encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,(function(e,t){return String.fromCharCode("0x"+t)})))}function o(e){return function(e){if(Array.isArray(e))return l(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,t){if(!e)return;if("string"==typeof e)return l(e,t);var i=Object.prototype.toString.call(e).slice(8,-1);"Object"===i&&e.constructor&&(i=e.constructor.name);if("Map"===i||"Set"===i)return Array.from(e);if("Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i))return l(e,t)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function l(e,t){(null==t||t>e.length)&&(t=e.length);for(var i=0,n=new Array(t);i<t;i++)n[i]=e[i];return n}var r,a,c;r=jQuery,a=window.ModuleBuilderModal,c={init:function(){r(document).on("click",".igd-acf-button",(function(e){var t=r(this);Swal.fire({html:'<div id="igd-select-files" class="igd-module-builder-modal-wrap"></div>',showConfirmButton:!1,customClass:{container:"igd-swal igd-module-builder-modal-container"},didOpen:function(e){ReactDOM.render(React.createElement(a,{initData:{},onUpdate:function(e){c.addFiles(t,e),Swal.close()},onClose:function(){return Swal.close()},isSelectFiles:!0}),document.getElementById("igd-select-files"))},willClose:function(e){ReactDOM.unmountComponentAtNode(document.getElementById("igd-select-files"))}})})),r(document).on("click",".igd-acf-field .file-remove",(function(e){e.preventDefault();var t=r(this).data("id"),i=r(this).closest(".igd-acf-field"),n=JSON.parse(r("input",i).val()).filter((function(e){return e.id!==t}));r("input",i).val(JSON.stringify(n)),r(this).closest("tr").remove()}))},addFiles:function(i,l){var a=l.folders,c=void 0===a?[]:a,d=[],s=i.parents(".igd-acf-field");r(".empty-row",s).remove();var u=r('<tr><td><img class="file-icon" src=""/></td><td class="file-name" style="width: 300px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;display: block;"></td><td class="file-id"></td><td class="file-actions"><a href="" target="_blank" class="button file-view">View</a> <a href="" class="button file-download">Download</a> <a href="#" class="button button-link-delete file-remove" data-id="">Remove</a></td></tr>');c.forEach((function(i){var o=i.id,l=i.accountId,a=(i.name,e(i)?"file_ids=".concat(n(JSON.stringify([o])),"&ignore_limit=1"):"id=".concat(o,"&accountId=").concat(l)),c="".concat(igd.homeUrl,"?igd_download=1&").concat(a,"&ignore_limit=1"),f="https://drive.google.com/file/d/".concat(i.id,"/preview?rm=minimal"),m=t(i,"full");d.push({id:i.id,account_id:i.accountId,name:i.name,type:i.type,size:i.size,embed_link:f,download_link:c,view_link:i.webViewLink,icon_link:i.iconLink,thumbnail_link:m});var p=u.clone();p.find(".file-icon").attr("src",i.iconLink),p.find(".file-name").text(i.name),p.find(".file-id").text(i.id),p.find(".file-view").attr("href",i.webViewLink),p.find(".file-download").attr("href",c),p.find(".file-remove").data("id",i.id),r("table",s).append(p)}));var f=r("input",s),m=f.val()?JSON.parse(f.val()):[];f.val(JSON.stringify([].concat(o(m),d)))}},r(document).ready(c.init)})();