class DatabaseWebJS{constructor(){this.id=null,this.shareId=null,this.password=null,this.dialogExport=null,this.dialogShare=null,this.dialogAdded=null,this.messages=null,this.myCodeMirror=null,this.currentQuery=null,this.type=null,this.pageName=null}getServerType(){return this.type}formatResponse(e,t){const E=this,s={rows:[],columns:[],affectedRows:null,error:null};if(200!==e)try{const e=JSON.parse(t);e&&e.sqlMessage?s.error=e.sqlMessage:s.error=t}catch(e){s.error=t}else{services.storage.setItem(E.type+"-online.lastupdatetime",(new Date).getTime());let e=JSON.parse(t);Array.isArray(e)&&e.length&&(void 0!==e[0].fieldCount&&void 0!==e[0].affectedRows||Array.isArray(e[0]))&&(e=e[e.length-1]),Array.isArray(e)?e.length?(s.columns=Object.keys(e[0]),s.rows=e):(s.columns=[],s.rows=[]):e&&e.affectedRows?s.affectedRows=e.affectedRows:e&&e.changedRows&&(s.changedRows=e.changedRows)}return s}execute(e,t){const E=this;if(!this.id)return this.setMessage("SQLite-WebJS-editor-error","Following an error, please reload the page");services.storage.setItem(this.getServerType()+"-online.query",this.myCodeMirror.getValue("\n"));const s=new XMLHttpRequest;s.open("POST",myDomainAPI+"/"+this.type+"/query",!0),s.setRequestHeader(this.type+"-id",this.id),s.setRequestHeader(this.type+"-passwd",this.password),s.onreadystatechange=function(){if(4===this.readyState)return t(E.formatResponse(this.status,this.responseText))},s.send(e)}setMessage(e,t){for(;this.message.classList.length>0;)this.message.classList.remove(this.message.classList.item(0));this.message.classList.add(e),this.message.innerText=t,this.message.style.display=""}resetMessage(){for(;this.message.classList.length>0;)this.message.classList.remove(this.message.classList.item(0));this.message.innerText="",this.message.style.display="none"}exportFile(e){var t=e.blob?e.blob:new Blob([e.data],{type:e.mime});if(navigator.msSaveBlob)navigator.msSaveBlob(t,e.filename);else{var E=document.createElement("a");if(void 0!==E.download){var s=URL.createObjectURL(t);E.setAttribute("href",s),E.setAttribute("download",e.filename),E.style.visibility="hidden",document.body.appendChild(E),E.click(),document.body.removeChild(E)}}}exportResult(e){switch(e){case"csv":default:if(!this.currentQuery)return void alert("You must execute a query before you can export!");this.exportFile({data:this.getExportData(this.currentQuery),filename:"file.csv",mime:"text/csv"})}}format(e){return sqlFormatter.format(e,{language:"sql",indent:"\t"})}executeQuery(e,t){var E={message:null},s=document.getElementById("exportToCSVContainer");this.execute(e.query+(e&&e.orderBy?e.orderBy:""),function(a){e.result=a;let n=document.getElementById("results");for(var T=n.getElementsByTagName("tbody")[0],r=n.getElementsByTagName("thead")[0],o=n.rows.length-1;o>=0;o--)n.deleteRow(o);if(s&&(s.style.display="none"),e.result.error)return t({error:e.result.error});if(!e.result.rows.length){let E="Query has no result";return e.result.affectedRows?E=e.result.affectedRows+" row(s) affected":e.result.changedRows&&(E=e.result.changedRows+" row(s) changed"),t({message:E})}s&&(s.style.display=""),1==e.result.rows.length?E.message="1 row":E.message=e.result.rows.length+" rows";var I=0,R=0,l=r.insertRow(r.rows.length);e.result.columns.forEach(function(e,t){var E=l.insertCell(R);0,E.appendChild(document.createTextNode(e)),R++}),e.result.rows.forEach(function(t){I++;var E=T.insertRow(T.rows.length);I%2==1&&(E.className="SQLite-WebJS-results-odd"),R=0,0,e.result.columns.forEach(function(e,s){var a=E.insertCell(R),n=document.createElement("span");n.appendChild(document.createTextNode(null===t[e]?"":t[e])),a.appendChild(n),0,R++})}),t&&t(E)})}getExportData(e){var t="",E=document.getElementById("headerQuery").value,s=document.getElementById("nullString").value,a=document.getElementById("separator").value;return e.result&&("no"!==E&&(t+=e.result.columns.reduce(function(e,t,E){return(null==e?"":e+a)+t},null),t+="\n"),e.result.rows.forEach(function(e){var E=0;Object.keys(e).forEach(function(n,T){t+=(E>0?a:"")+(null===e[n]?s:e[n]),E++}),t+="\n"})),t}readSingleFile(e,t,E){var s;e.target&&e.target.files?s=e.target.files:e.dataTransfer&&e.dataTransfer.files&&(s=e.dataTransfer.files),s&&0!=s.length?Array.prototype.forEach.call(s,function(e){var s=new FileReader;s.onload=function(){E(s.result,{file:e})},t===ReadModeEnum.ARRAY_BUFFER?s.readAsArrayBuffer(e):t===ReadModeEnum.DATA_URL?s.readAsDataURL(e):s.readAsText(e)}):E(null)}dump(){const e=this,t=new XMLHttpRequest;t.open("GET",myDomainAPI+"/"+this.type+"/dump",!0),t.setRequestHeader(this.type+"-id",this.id),t.setRequestHeader(this.type+"-passwd",this.password),t.onreadystatechange=function(){4===this.readyState&&(200!==this.status?e.setMessage("SQLite-WebJS-editor-error",this.responseText):e.exportFile({data:this.responseText,filename:"database.sql",mime:"text/plain"}))},t.send()}init(e=null){var t=this;this.message=document.getElementById("editor-message"),this.myCodeMirror=CodeMirror.fromTextArea(document.getElementById("editor-container"),{mode:"text/x-sql",lineNumbers:!0,viewportMargin:1/0,extraKeys:{"Ctrl-Space":"autocomplete"}});const E=["A","ABORT","ABS","ABSOLUTE","ACCESS","ACTION","ADA","ADD","ADMIN","AFTER","AGGREGATE","ALIAS","ALL","ALLOCATE","ALSO","ALTER","ALWAYS","ANALYSE","ANALYZE","AND","ANY","ARE","ARRAY","AS","ASC","ASENSITIVE","ASSERTION","ASSIGNMENT","ASYMMETRIC","AT","ATOMIC","ATTRIBUTE","ATTRIBUTES","AUDIT","AUTHORIZATION","AUTO_INCREMENT","AVG","AVG_ROW_LENGTH","BACKUP","BACKWARD","BEFORE","BEGIN","BERNOULLI","BETWEEN","BIGINT","BINARY","BIT","BIT_LENGTH","BITVAR","BLOB","BOOL","BOOLEAN","BOTH","BREADTH","BREAK","BROWSE","BULK","BY","C","CACHE","CALL","CALLED","CARDINALITY","CASCADE","CASCADED","CASE","CAST","CATALOG","CATALOG_NAME","CEIL","CEILING","CHAIN","CHANGE","CHAR","CHAR_LENGTH","CHARACTER","CHARACTER_LENGTH","CHARACTER_SET_CATALOG","CHARACTER_SET_NAME","CHARACTER_SET_SCHEMA","CHARACTERISTICS","CHARACTERS","CHECK","CHECKED","CHECKPOINT","CHECKSUM","CLASS","CLASS_ORIGIN","CLOB","CLOSE","CLUSTER","CLUSTERED","COALESCE","COBOL","COLLATE","COLLATION","COLLATION_CATALOG","COLLATION_NAME","COLLATION_SCHEMA","COLLECT","COLUMN","COLUMN_NAME","COLUMNS","COMMAND_FUNCTION","COMMAND_FUNCTION_CODE","COMMENT","COMMIT","COMMITTED","COMPLETION","COMPRESS","COMPUTE","CONDITION","CONDITION_NUMBER","CONNECT","CONNECTION","CONNECTION_NAME","CONSTRAINT","CONSTRAINT_CATALOG","CONSTRAINT_NAME","CONSTRAINT_SCHEMA","CONSTRAINTS","CONSTRUCTOR","CONTAINS","CONTAINSTABLE","CONTINUE","CONVERSION","CONVERT","COPY","CORR","CORRESPONDING","COUNT","COVAR_POP","COVAR_SAMP","CREATE","CREATEDB","CREATEROLE","CREATEUSER","CROSS","CSV","CUBE","CUME_DIST","CURRENT","CURRENT_DATE","CURRENT_DEFAULT_TRANSFORM_GROUP","CURRENT_PATH","CURRENT_ROLE","CURRENT_TIME","CURRENT_TIMESTAMP","CURRENT_TRANSFORM_GROUP_FOR_TYPE","CURRENT_USER","CURSOR","CURSOR_NAME","CYCLE","DATA","DATABASE","DATABASES","DATE","DATETIME","DATETIME_INTERVAL_CODE","DATETIME_INTERVAL_PRECISION","DAY","DAY_HOUR","DAY_MICROSECOND","DAY_MINUTE","DAY_SECOND","DAYOFMONTH","DAYOFWEEK","DAYOFYEAR","DBCC","DEALLOCATE","DEC","DECIMAL","DECLARE","DEFAULT","DEFAULTS","DEFERRABLE","DEFERRED","DEFINED","DEFINER","DEGREE","DELAY_KEY_WRITE","DELAYED","DELETE","DELIMITER","DELIMITERS","DENSE_RANK","DENY","DEPTH","DEREF","DERIVED","DESC","DESCRIBE","DESCRIPTOR","DESTROY","DESTRUCTOR","DETERMINISTIC","DIAGNOSTICS","DICTIONARY","DISABLE","DISCONNECT","DISK","DISPATCH","DISTINCT","DISTINCTROW","DISTRIBUTED","DIV","DO","DOMAIN","DOUBLE","DROP","DUAL","DUMMY","DUMP","DYNAMIC","DYNAMIC_FUNCTION","DYNAMIC_FUNCTION_CODE","EACH","ELEMENT","ELSE","ELSEIF","ENABLE","ENCLOSED","ENCODING","ENCRYPTED","END","END-EXEC","ENUM","EQUALS","ERRLVL","ESCAPE","ESCAPED","EVERY","EXCEPT","EXCEPTION","EXCLUDE","EXCLUDING","EXCLUSIVE","EXEC","EXECUTE","EXISTING","EXISTS","EXIT","EXP","EXPLAIN","EXTERNAL","EXTRACT","FALSE","FETCH","FIELDS","FILE","FILLFACTOR","FILTER","FINAL","FIRST","FLOAT","FLOAT4","FLOAT8","FLOOR","FLUSH","FOLLOWING","FOR","FORCE","FOREIGN","FORTRAN","FORWARD","FOUND","FREE","FREETEXT","FREETEXTTABLE","FREEZE","FROM","FULL","FULLTEXT","FUNCTION","FUSION","G","GENERAL","GENERATED","GET","GLOBAL","GO","GOTO","GRANT","GRANTED","GRANTS","GREATEST","GROUP","GROUPING","HANDLER","HAVING","HEADER","HEAP","HIERARCHY","HIGH_PRIORITY","HOLD","HOLDLOCK","HOST","HOSTS","HOUR","HOUR_MICROSECOND","HOUR_MINUTE","HOUR_SECOND","IDENTIFIED","IDENTITY","IDENTITY_INSERT","IDENTITYCOL","IF","IGNORE","ILIKE","IMMEDIATE","IMMUTABLE","IMPLEMENTATION","IMPLICIT","IN","INCLUDE","INCLUDING","INCREMENT","INDEX","INDICATOR","INFILE","INFIX","INHERIT","INHERITS","INITIAL","INITIALIZE","INITIALLY","INNER","INOUT","INPUT","INSENSITIVE","INSERT","INSERT_ID","INSTANCE","INSTANTIABLE","INSTEAD","INT","INT1","INT2","INT3","INT4","INT8","INTEGER","INTERSECT","INTERSECTION","INTERVAL","INTO","INVOKER","IS","ISAM","ISNULL","ISOLATION","ITERATE","JOIN","K","KEY","KEY_MEMBER","KEY_TYPE","KEYS","KILL","LANCOMPILER","LANGUAGE","LARGE","LAST","LAST_INSERT_ID","LATERAL","LEADING","LEAST","LEAVE","LEFT","LENGTH","LESS","LEVEL","LIKE","LIMIT","LINENO","LINES","LISTEN","LN","LOAD","LOCAL","LOCALTIME","LOCALTIMESTAMP","LOCATION","LOCATOR","LOCK","LOGIN","LOGS","LONG","LONGBLOB","LONGTEXT","LOOP","LOW_PRIORITY","LOWER","M","MAP","MATCH","MATCHED","MAX","MAX_ROWS","MAXEXTENTS","MAXVALUE","MEDIUMBLOB","MEDIUMINT","MEDIUMTEXT","MEMBER","MERGE","MESSAGE_LENGTH","MESSAGE_OCTET_LENGTH","MESSAGE_TEXT","METHOD","MIDDLEINT","MIN","MIN_ROWS","MINUS","MINUTE","MINUTE_MICROSECOND","MINUTE_SECOND","MINVALUE","MLSLABEL","MOD","MODE","MODIFIES","MODIFY","MODULE","MONTH","MONTHNAME","MORE","MOVE","MULTISET","MUMPS","MYISAM","NAME","NAMES","NATIONAL","NATURAL","NCHAR","NCLOB","NESTING","NEW","NEXT","NO","NO_WRITE_TO_BINLOG","NOAUDIT","NOCHECK","NOCOMPRESS","NOCREATEDB","NOCREATEROLE","NOCREATEUSER","NOINHERIT","NOLOGIN","NONCLUSTERED","NONE","NORMALIZE","NORMALIZED","NOSUPERUSER","NOT","NOTHING","NOTIFY","NOTNULL","NOWAIT","NULL","NULLABLE","NULLIF","NULLS","NUMBER","NUMERIC","OBJECT","OCTET_LENGTH","OCTETS","OF","OFF","OFFLINE","OFFSET","OFFSETS","OIDS","OLD","ON","ONLINE","ONLY","OPEN","OPENDATASOURCE","OPENQUERY","OPENROWSET","OPENXML","OPERATION","OPERATOR","OPTIMIZE","OPTION","OPTIONALLY","OPTIONS","OR","ORDER","ORDERING","ORDINALITY","OTHERS","OUT","OUTER","OUTFILE","OUTPUT","OVER","OVERLAPS","OVERLAY","OVERRIDING","OWNER","PACK_KEYS","PAD","PARAMETER","PARAMETER_MODE","PARAMETER_NAME","PARAMETER_ORDINAL_POSITION","PARAMETER_SPECIFIC_CATALOG","PARAMETER_SPECIFIC_NAME","PARAMETER_SPECIFIC_SCHEMA","PARAMETERS","PARTIAL","PARTITION","PASCAL","PASSWORD","PATH","PCTFREE","PERCENT","PERCENT_RANK","PERCENTILE_CONT","PERCENTILE_DISC","PLACING","PLAN","PLI","POSITION","POSTFIX","POWER","PRECEDING","PRECISION","PREFIX","PREORDER","PREPARE","PREPARED","PRESERVE","PRIMARY","PRINT","PRIOR","PRIVILEGES","PROC","PROCEDURAL","PROCEDURE","PROCESS","PROCESSLIST","PUBLIC","PURGE","QUOTE","RAID0","RAISERROR","RANGE","RANK","RAW","READ","READS","READTEXT","REAL","RECHECK","RECONFIGURE","RECURSIVE","REF","REFERENCES","REFERENCING","REGEXP","REGR_AVGX","REGR_AVGY","REGR_COUNT","REGR_INTERCEPT","REGR_R2","REGR_SLOPE","REGR_SXX","REGR_SXY","REGR_SYY","REINDEX","RELATIVE","RELEASE","RELOAD","RENAME","REPEAT","REPEATABLE","REPLACE","REPLICATION","REQUIRE","RESET","RESIGNAL","RESOURCE","RESTART","RESTORE","RESTRICT","RESULT","RETURN","RETURNED_CARDINALITY","RETURNED_LENGTH","RETURNED_OCTET_LENGTH","RETURNED_SQLSTATE","RETURNS","REVOKE","RIGHT","RLIKE","ROLE","ROLLBACK","ROLLUP","ROUTINE","ROUTINE_CATALOG","ROUTINE_NAME","ROUTINE_SCHEMA","ROW","ROW_COUNT","ROW_NUMBER","ROWCOUNT","ROWGUIDCOL","ROWID","ROWNUM","ROWS","RULE","SAVE","SAVEPOINT","SCALE","SCHEMA","SCHEMA_NAME","SCHEMAS","SCOPE","SCOPE_CATALOG","SCOPE_NAME","SCOPE_SCHEMA","SCROLL","SEARCH","SECOND","SECOND_MICROSECOND","SECTION","SECURITY","SELECT","SELF","SENSITIVE","SEPARATOR","SEQUENCE","SERIALIZABLE","SERVER_NAME","SESSION","SESSION_USER","SET","SETOF","SETS","SETUSER","SHARE","SHOW","SHUTDOWN","SIGNAL","SIMILAR","SIMPLE","SIZE","SMALLINT","SOME","SONAME","SOURCE","SPACE","SPATIAL","SPECIFIC","SPECIFIC_NAME","SPECIFICTYPE","SQL","SQL_BIG_RESULT","SQL_BIG_SELECTS","SQL_BIG_TABLES","SQL_CALC_FOUND_ROWS","SQL_LOG_OFF","SQL_LOG_UPDATE","SQL_LOW_PRIORITY_UPDATES","SQL_SELECT_LIMIT","SQL_SMALL_RESULT","SQL_WARNINGS","SQLCA","SQLCODE","SQLERROR","SQLEXCEPTION","SQLSTATE","SQLWARNING","SQRT","SSL","STABLE","START","STARTING","STATE","STATEMENT","STATIC","STATISTICS","STATUS","STDDEV_POP","STDDEV_SAMP","STDIN","STDOUT","STORAGE","STRAIGHT_JOIN","STRICT","STRING","STRUCTURE","STYLE","SUBCLASS_ORIGIN","SUBLIST","SUBMULTISET","SUBSTRING","SUCCESSFUL","SUM","SUPERUSER","SYMMETRIC","SYNONYM","SYSDATE","SYSID","SYSTEM","SYSTEM_USER","TABLE","TABLE_NAME","TABLES","TABLESAMPLE","TABLESPACE","TEMP","TEMPLATE","TEMPORARY","TERMINATE","TERMINATED","TEXT","TEXTSIZE","THAN","THEN","TIES","TIME","TIMESTAMP","TIMEZONE_HOUR","TIMEZONE_MINUTE","TINYBLOB","TINYINT","TINYTEXT","TO","TOAST","TOP","TOP_LEVEL_COUNT","TRAILING","TRAN","TRANSACTION","TRANSACTION_ACTIVE","TRANSACTIONS_COMMITTED","TRANSACTIONS_ROLLED_BACK","TRANSFORM","TRANSFORMS","TRANSLATE","TRANSLATION","TREAT","TRIGGER","TRIGGER_CATALOG","TRIGGER_NAME","TRIGGER_SCHEMA","TRIM","TRUE","TRUNCATE","TRUSTED","TSEQUAL","TYPE","UESCAPE","UID","UNBOUNDED","UNCOMMITTED","UNDER","UNDO","UNENCRYPTED","UNION","UNIQUE","UNKNOWN","UNLISTEN","UNLOCK","UNNAMED","UNNEST","UNSIGNED","UNTIL","UPDATE","UPDATETEXT","UPPER","USAGE","USE","USER","USER_DEFINED_TYPE_CATALOG","USER_DEFINED_TYPE_CODE","USER_DEFINED_TYPE_NAME","USER_DEFINED_TYPE_SCHEMA","USING","UTC_DATE","UTC_TIME","UTC_TIMESTAMP","VACUUM","VALID","VALIDATE","VALIDATOR","VALUE","VALUES","VAR_POP","VAR_SAMP","VARBINARY","VARCHAR","VARCHAR2","VARCHARACTER","VARIABLE","VARIABLES","VARYING","VERBOSE","VIEW","VOLATILE","WAITFOR","WHEN","WHENEVER","WHERE","WHILE","WIDTH_BUCKET","WINDOW","WITH","WITHIN","WITHOUT","WORK","WRITE","WRITETEXT","X509","XOR","YEAR","YEAR_MONTH","ZEROFILL","ZONE"];CodeMirror.registerHelper("hintWords","sql",E.concat(E.map(function(e){return e.toLowerCase()}))),this.myCodeMirror.setSize(null,250),services.storage.getItem(this.getServerType()+".query")&&this.myCodeMirror.setValue(services.storage.getItem(this.getServerType()+".query")),document.getElementById("ExecuteQuery").addEventListener("click",function(e){var E=t.myCodeMirror.getSelection();t.currentQuery={query:""!=E&&null!=E?E:t.myCodeMirror.getValue("\n"),result:null};try{t.executeQuery(t.currentQuery,function(e){e&&e.error?t.setMessage("SQLite-WebJS-editor-error",e.error):e&&e.message&&t.setMessage("SQLite-WebJS-editor-valid",e.message)})}catch(e){t.setMessage("SQLite-WebJS-editor-error",e.message)}},!1),this.dialogExport=new A11yDialog(document.getElementById("dialog-export")),this.initMenu(),null==this.type&&services.storage.getItem(this.getServerType()+"-online.type")&&(this.type=services.storage.getItem(this.getServerType()+"-online.type"));const s=window.location.pathname.split("/").pop();this.pageName!==s&&(this.shareId=s),this.loadShare(function(){t.loadSessionIfValid(),t.initServer(e)}),this.dialogAdded=new A11yDialog(document.getElementById("dialog-added")),this.dialogPwd=new A11yDialog(document.getElementById("dialog-pwd")),this.dialogShare=new A11yDialog(document.getElementById("dialog-share"))}loadSessionIfValid(){if(services.storage.getItem(this.type+"-online.lastupdatetime")){const e=(new Date).getTime()-15e5;services.storage.getItem(this.type+"-online.lastupdatetime")>e&&(this.id=services.storage.getItem(this.type+"-online.id"),this.password=services.storage.getItem(this.type+"-online.password"),this.password=services.storage.getItem(this.type+"-online.password"))}}loadShare(e){const t=this;if(null!==this.shareId){document.getElementById("database-save").style.display="none",document.getElementById("message-save").style.display="none";var E=new XMLHttpRequest;E.open("GET",myDomain+"/share/"+this.getServerType()+"/"+this.shareId,!0),E.setRequestHeader("Content-type","application/json"),E.onreadystatechange=function(){if(4===this.readyState){var E=null,s=JSON.parse(this.responseText);200!==this.status&&(E=s.message?s.message:"An error has occured. Please, try later."),function(e,E){E?(alert(E),document.getElementById("database-save").style.display="",document.getElementById("message-save").style.display="",document.getElementById("message-update").style.display="none",document.getElementById("message-delete").style.display="none",document.getElementById("database-update").style.display="none",document.getElementById("database-delete").style.display="none",document.getElementById("database-fork").style.display="none"):(t.resetMessage(),t.loadDatabase(e))}(s,E),e()}},E.send()}else document.getElementById("message-update").style.display="none",document.getElementById("message-delete").style.display="none",document.getElementById("database-update").style.display="none",document.getElementById("database-delete").style.display="none",document.getElementById("database-fork").style.display="none",e()}initServer(e){if(this.id)e&&e();else{const t=this,E=new XMLHttpRequest;E.open("GET",myDomainAPI+"/"+this.type+"/init",!0),E.onreadystatechange=function(){if(4===this.readyState){var E=JSON.parse(this.responseText);200!==this.status?t.setMessage("SQLite-WebJS-editor-error",E.message?E.message:this.responseText):(t.id=E.id,t.password=E.password,services.storage.setItem(t.type+"-online.id",t.id),services.storage.setItem(t.type+"-online.password",t.password),services.storage.setItem(t.getServerType()+"-online.type",t.type),services.storage.setItem(t.type+"-online.lastupdatetime",(new Date).getTime())),e&&e()}},E.send()}}deletePwd(){document.getElementById("message-save").style.display="none",document.getElementById("message-update").style.display="none",document.getElementById("message-fork").style.display="none",document.getElementById("message-delete").style.display="",this.currentAction=this.deleteDatabase,this.dialogPwd.show()}savePwd(){document.getElementById("message-save").style.display="",document.getElementById("message-update").style.display="none",document.getElementById("message-fork").style.display="none",document.getElementById("message-delete").style.display="none",this.currentAction=this.saveDatabase,this.dialogPwd.show()}updatePwd(){document.getElementById("message-save").style.display="none",document.getElementById("message-update").style.display="",document.getElementById("message-fork").style.display="none",document.getElementById("message-delete").style.display="none",this.currentAction=this.updateDatabase,this.dialogPwd.show()}forkPwd(){document.getElementById("message-save").style.display="none",document.getElementById("message-update").style.display="none",document.getElementById("message-fork").style.display="",document.getElementById("message-delete").style.display="none",this.currentAction=this.forkDatabase,this.dialogPwd.show()}doIt(){""!=document.getElementById("pwd").value?(this.dialogPwd.hide(),this.currentAction()):alert("You must fill password input")}loadDatabase(e){this.myCodeMirror.setValue(pako.inflate(e.queries,{to:"string"}))}getData(e){const t={pwd:document.getElementById("pwd").value,queries:pako.deflate(this.myCodeMirror.getValue("\n"),{to:"string"})};return"update"==e&&(t.id=this.shareId),t}forkDatabase(){var e=this;const t=this.getData("fork");var E=new XMLHttpRequest;E.open("POST",myDomain+"/share/"+this.getServerType(),!0),E.setRequestHeader("Content-type","application/json"),E.setRequestHeader("Security-key",pwd),E.onreadystatechange=function(){if(4===this.readyState){var t=JSON.parse(this.responseText);201!==this.status?t&&t.message?alert(t.message):alert("An error has occured. Please, try later."):(history.pushState({},"","/"+e.getServerType()+"/"+t.id),document.getElementById("link-id").value=myDomain+"/"+e.getServerType()+"/"+t.id,document.getElementById("link-id").select(),document.getElementById("database-save").style.display="none",document.getElementById("message-save").style.display="none",document.getElementById("message-update").style.display="",document.getElementById("message-delete").style.display="",document.getElementById("database-update").style.display="",document.getElementById("database-delete").style.display="",document.getElementById("database-fork").style.display="",e.dialogAdded.show())}},E.send(JSON.stringify(t))}saveDatabase(){var e=this;try{const E=this.getData("save");var t=new XMLHttpRequest;t.open("POST",myDomain+"/share/"+this.getServerType(),!0),t.setRequestHeader("Content-type","application/json"),t.setRequestHeader("Security-key",pwd),t.onreadystatechange=function(){if(4===this.readyState){var t=JSON.parse(this.responseText);201!==this.status?t&&t.message?alert(t.message):alert("An error has occured. Please, try later."):(history.pushState({},"","/"+e.getServerType()+"/"+t.id),document.getElementById("link-id").value=myDomain+"/"+e.getServerType()+"/"+t.id,document.getElementById("link-id").select(),document.getElementById("database-save").style.display="none",document.getElementById("message-save").style.display="none",document.getElementById("message-update").style.display="",document.getElementById("message-delete").style.display="",document.getElementById("database-update").style.display="",document.getElementById("database-delete").style.display="",document.getElementById("database-fork").style.display="",e.dialogAdded.show())}},t.send(JSON.stringify(E))}catch(e){console.log(e)}}updateDatabase(){const e=this.getData("update");var t=new XMLHttpRequest;t.open("PUT",myDomain+"/share/"+this.getServerType()+"/"+e.id,!0),t.setRequestHeader("Content-type","application/json"),t.setRequestHeader("Security-key",pwd),t.onreadystatechange=function(){if(4===this.readyState)if(200!==this.status){var e=JSON.parse(this.responseText);e.message?alert(e.message):alert("An error has occured. Please, try later.")}else alert("Your snippet has been updated.")},t.send(JSON.stringify(e))}deleteDatabase(){const e=this;var t=new XMLHttpRequest;t.open("DELETE",myDomain+"/share/"+this.getServerType()+"/"+this.shareId,!0),t.setRequestHeader("Content-type","application/json"),t.setRequestHeader("Security-key",pwd),t.onreadystatechange=function(){if(4===this.readyState)if(200!==this.status){var t=JSON.parse(this.responseText);t.message?alert(t.message):alert("An error has occured. Please, try later.")}else alert("Your snippet has been deleted."),document.location.href=myDomain+"/"+e.pageName},t.send()}closeMenu(e=null){document.querySelectorAll(".sub-menu ul").forEach(function(t){e&&e===t.parentNode||(t.style.display="none",t.parentNode.querySelectorAll("i.arrow").forEach(function(e){e.classList.remove("up"),e.classList.add("down")}))})}initMenu(){const e=this;this.closeMenu(),document.querySelectorAll(".sub-menu a").forEach(function(t){t.onclick=function(){let E=t.parentNode;for(;E&&!E.classList.contains("sub-menu");)E=E.parentNode;E&&(e.closeMenu(E),E.querySelectorAll("ul").forEach(function(e){""==e.style.display?e.style.display="none":e.style.display=""}),E.querySelectorAll("i.arrow").forEach(function(e){e.classList.toggle("up"),e.classList.toggle("down")}))}}),document.getElementById("menu-database-sql-file")&&document.getElementById("menu-database-sql-file").addEventListener("click",function(t){e.dump()}),document.getElementById("menu-sqlite-exportCSVResults").addEventListener("click",function(t){e.closeMenu(),e.dialogExport.show()}),document.getElementById("menu-sqlite-openSQL").addEventListener("click",function(t){e.closeMenu(),document.getElementById("sql-input").click()}),document.getElementById("menu-share").addEventListener("click",function(t){e.closeMenu(),e.dialogShare.show()}),document.getElementById("sql-input").addEventListener("change",function(t){""!=document.getElementById("sql-input").value&&e.readSingleFile(t,ReadModeEnum.TEXT,function(t){document.getElementById("sql-input").value="",e.myCodeMirror.setValue(t)})}),document.getElementById("menu-sqlite-saveSQL").addEventListener("click",function(t){e.closeMenu(),e.exportFile({data:e.myCodeMirror.getValue("\n"),filename:"file.sql",mime:"text/plain"})})}}