(()=>{"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){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"default",n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},o=arguments.length>3&&void 0!==arguments[3]&&arguments[3],l=e.id,a=e.iconLink,r=e.thumbnailLink,d=e.shortcutDetails,c=(null==n?void 0:n.w)||64,u=(null==n?void 0:n.h)||64;null!=d&&d.targetId&&(l=d.targetId);var s=i(e),f={custom:"w".concat(c,"-h").concat(u),small:"w300-h300",medium:"w600-h400",large:"w1024-h768",full:"w2048",default:"w300-h300"},m={custom:"=w".concat(c,"-h").concat(u),small:"=w300-h300",medium:"=h600-nu",large:"=w1024-h768-p-k-nu",full:"=w2048",default:"=w200-h190-p-k-nu"};if(r){if(s&&!o){var v=f[t]||f.default;return"https://drive.google.com/thumbnail?id=".concat(l,"&sz=").concat(v)}if(!o&&!r.includes("google.com")){var g=m[t]||m.default;return r.replace(/=s\d+/,g)}return 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,l=e.accountId,a=new URLSearchParams({igd_preview_image:1,id:o,account_id:l,size:t,width:i,height:n});return"".concat(igd.homeUrl,"/?").concat(a.toString())}(e,t,c,u)}return(null==a?void 0:a.replace("/16/","/".concat(c,"/")))||""}function i(e){var t,i=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;return"reader"===i||"writer"===i}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){if("string"==typeof e)return l(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)?l(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 l(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 a,r,d;a=jQuery,r=window.ModuleBuilderModal,d={init:function(){a(document).on("click",".igd-acf-button",(function(e){var t=a(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){d.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"))}})})),a(document).on("click",".igd-acf-field .file-remove",(function(e){e.preventDefault();var t=a(this).data("id"),i=a(this).closest(".igd-acf-field"),n=JSON.parse(a("input",i).val()).filter((function(e){return e.id!==t}));a("input",i).val(JSON.stringify(n)),a(this).closest("tr").remove()}))},addFiles:function(i,l){var r=l.folders,d=void 0===r?[]:r,c=[],u=i.parents(".igd-acf-field");a(".empty-row",u).remove();var s=a('<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>');d.forEach((function(i){var o=i.id,l=i.accountId,r=(i.name,e(i)?"file_ids=".concat(n(JSON.stringify([o])),"&ignore_limit=1"):"id=".concat(o,"&accountId=").concat(l)),d="".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");c.push({id:i.id,account_id:i.accountId,name:i.name,type:i.type,size:i.size,embed_link:f,download_link:d,view_link:i.webViewLink,icon_link:i.iconLink,thumbnail_link:m});var v=s.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",d),v.find(".file-remove").data("id",i.id),a("table",u).append(v)}));var f=a("input",u),m=f.val()?JSON.parse(f.val()):[];f.val(JSON.stringify([].concat(o(m),c)))}},a(document).ready(d.init)})();