(()=>{"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 n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},o=e.id,a=e.iconLink,l=e.thumbnailLink;e.shortcutDetails&&(o=e.shortcutDetails.targetId);var r=n.w,c=n.h;r||(r=64),c||(c=64);var d=null==a?void 0:a.replace("/16/","/".concat(r,"/"));return l&&(d=i(e)?"custom"===t?"https://drive.google.com/thumbnail?id=".concat(o,"&sz=w").concat(r,"-h").concat(c):"https://drive.google.com/thumbnail?id=".concat(o,"small"===t?"&sz=w300-h300":"medium"===t?"&sz=w600-h400":"large"===t?"&sz=w1024-h768":"full"===t?"&sz=w2048":"&sz=w300-h300"):l.includes("google.com")?function(e,t){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:300,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:300,o=e.id,a=e.accountId,l={id:o,accountId:a,size:t};"custom"===t&&(l.w=i,l.h=n);return"".concat(igd.homeUrl,"/?igd_preview_image=1&id=").concat(o,"&account_id=").concat(a,"&size=").concat(t,"&w=").concat(i,"&h=").concat(n)}(e,t,r,c):"custom"===t?l.replace("=s220","=w".concat(r,"-h").concat(c)):"small"===t?l.replace("=s220","=w300-h300"):"medium"===t?l.replace("=s220","=h600-nu"):"large"===t?l.replace("=s220","=w1024-h768-p-k-nu"):"full"===t?l.replace("=s220",""):l.replace("=s220","=w200-h190-p-k-nu")),d}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 a(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){if("string"==typeof e)return a(e,t);var i={}.toString.call(e).slice(8,-1);return"Object"===i&&e.constructor&&(i=e.constructor.name),"Map"===i||"Set"===i?Array.from(e):"Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?a(e,t):void 0}}(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 a(e,t){(null==t||t>e.length)&&(t=e.length);for(var i=0,n=Array(t);i<t;i++)n[i]=e[i];return n}var l,r,c;l=jQuery,r=window.ModuleBuilderModal,c={init:function(){l(document).on("click",".igd-acf-button",(function(e){var t=l(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(r,{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"))}})})),l(document).on("click",".igd-acf-field .file-remove",(function(e){e.preventDefault();var t=l(this).data("id"),i=l(this).closest(".igd-acf-field"),n=JSON.parse(l("input",i).val()).filter((function(e){return e.id!==t}));l("input",i).val(JSON.stringify(n)),l(this).closest("tr").remove()}))},addFiles:function(i,a){var r=a.folders,c=void 0===r?[]:r,d=[],s=i.parents(".igd-acf-field");l(".empty-row",s).remove();var u=l('<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,a=i.accountId,r=(i.name,e(i)?"file_ids=".concat(n(JSON.stringify([o])),"&ignore_limit=1"):"id=".concat(o,"&accountId=").concat(a)),c="".concat(igd.homeUrl,"?igd_download=1&").concat(r,"&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 v=u.clone();v.find(".file-icon").attr("src",i.iconLink),v.find(".file-name").text(i.name),v.find(".file-id").text(i.id),v.find(".file-view").attr("href",i.webViewLink),v.find(".file-download").attr("href",c),v.find(".file-remove").data("id",i.id),l("table",s).append(v)}));var f=l("input",s),m=f.val()?JSON.parse(f.val()):[];f.val(JSON.stringify([].concat(o(m),d)))}},l(document).ready(c.init)})();