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