import e from"@babel/runtime/helpers/typeof";import{createContext as n}from"react";var t=n(null),r=/^(.+) Copy(?:\s(\d+))?$/,i=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],t=e.trim(),i=t.match(r),o=n.reduce((function(e,n){var o,a=(null===(o=n.name)||void 0===o?void 0:o.trim())||"",l=0;if(i){var c=a.match(r);(null==c?void 0:c[1])===i[1]&&null!=c&&c[2]&&(l=Number(c[2]))}return{isDuplicate:e.isDuplicate||a===t,maxCopyIndex:Math.max(e.maxCopyIndex,l)}}),{isDuplicate:!1,maxCopyIndex:0}),a=o.maxCopyIndex,l=o.isDuplicate;if(l)return"".concat((null==i?void 0:i[1])||t," Copy").concat(a?" ".concat(a+1):"")},o=function(e){return"items"in e},a=function(e){return!o(e)},l=function(e,n){return"folder|".concat(e,"|").concat(n)},c=function(e){var n,t;return(null==e||null===(n=e.metadata)||void 0===n?void 0:n.isPresetOverride)&&void 0!==(null==e||null===(t=e.metadata)||void 0===t?void 0:t.parentTemplateId)},u=function(e){return!(null!=e&&e.isPreset||null!=e&&e.published||null!=e&&e.shared||c(e))},d=function(e){var n;return null==e||null===(n=e.metadata)||void 0===n?void 0:n.folderPath},s=function(e){return!!d(e)},m=function(e){var n,t;return{icon:null===(n=e.metadata)||void 0===n?void 0:n.icon,iconColor:null===(t=e.metadata)||void 0===t?void 0:t.iconColor}},f=function(e){return{version:1,name:e.name,settings:e.settings,metadata:m(e)}},v=function(n){var t;try{t=JSON.parse(n)}catch(e){throw new Error("Could not parse file")}var r="string"==typeof t.name&&t.name&&t.settings&&"object"===e(t.settings);if(!t.version&&r)return{name:t.name,settings:t.settings,metadata:{}};if(1===t.version&&r&&t.metadata&&"object"===e(t.metadata))return{name:t.name,settings:t.settings,metadata:t.metadata};throw new Error("Unexpected file format")},p=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=e.extensions,t=e.maxSizeKb;return new Promise((function(e,r){var i=document.createElement("input");i.type="file",n&&n.length>0&&(i.accept=n.join(",")),i.oncancel=function(){return r(new Error("File selection cancelled"))},i.onchange=function(n){var i,o=n.target;if(null!=o&&null!==(i=o.files)&&void 0!==i&&i[0]){var a=o.files[0];if(t&&a.size>1024*t)r(new Error("Selected file exceeds the size limit of ".concat(t," kb.")));else{var l=new FileReader;l.onload=function(n){var t,i=null===(t=n.target)||void 0===t?void 0:t.result;"string"!=typeof i?r(new Error("Unexpected file format.")):e(i)},l.onerror=function(){var e;r(new Error("Error reading file: ".concat(null===(e=l.error)||void 0===e?void 0:e.message)))},l.readAsText(a)}}else r(new Error("No file selected."))},i.click()}))};export{t as StoreContext,l as getFolderId,m as getMetadataForCopyOrExport,f as getTemplateExportData,d as getTemplateFolder,o as isFolder,u as isOwnTemplate,c as isPresetOverride,a as isTemplate,s as isTemplateInFolder,p as loadTextFile,v as parseTemplateImportData,i as suggestName};
//# sourceMappingURL=utils.js.map
