"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[194],{61781:function(e,a,t){t.d(a,{Z:function(){return s}});var n=t(85893),l=(t(67294),t(42065));function s(){return(0,n.jsx)("button",{className:"outlined gray p-2 w-9 h-9 flex items-center justify-center rounded-full",onClick:function(e){window.history.back()},children:(0,n.jsx)(l.Z,{color:"inherit",className:"opacity-50 text-black",fontSize:"small"})})}},79230:function(e,a,t){t.d(a,{Z:function(){return s}});var n=t(85893),l=(t(67294),t(76915));function s(e){var a=e.slugText,t=e.justIcon,s=e.title,i=e.outlined;return(0,n.jsxs)("div",{className:"button small-text"+(i?" outlined gray bg-white":" ghost light-gray"),onClick:function(e){navigator.clipboard.writeText(a).then((function(){alert('Copied: "'.concat(a,'"'))}))},style:i?void 0:{padding:0},children:[(0,n.jsx)(l.Z,{size:i?15:20}),!t&&(0,n.jsx)("span",{className:"text-slate-500 dark:text-slate-300",children:s||"Copy Slug"})]})}},4423:function(e,a,t){t.d(a,{Z:function(){return x}});var n=t(828),l=t(85893),s=t(67294),i=t(79230),o=t(96355),d=t(87851),c=t(5467),r=t(57632),u=t(85541),m=t(86729),h=t(95264),f=t(8971),b=t(58261);function x(e){var a,t,d=e.database,c=(e.query,e.confirmedDelegetedUser),r=e.user,u=d.active_clone,m=(d.active_clone_parent_db,null===c||void 0===c?void 0:c.delegated),h=(null===c||void 0===c||null===(a=c.priviledges)||void 0===a||a.match(/Edit Tables/i),null===c||void 0===c||null===(t=c.priviledges)||void 0===t||t.match(/Delete Tables/i),(0,n.Z)(s.useState(null),2));h[0],h[1];return(0,l.jsxs)("div",{className:"flex-wrap justify-center gap-4",children:[(0,l.jsxs)("div",{className:"dropdown-wrapper gap-4",children:[(0,l.jsxs)("div",{className:"relative",children:[(0,l.jsxs)("div",{className:"w-8 h-8 relative",children:[(0,l.jsx)("img",{src:d.db_image,alt:"Database Image",width:20,className:"w-full h-full rounded-full object-cover"}),(null===c||void 0===c?void 0:c.delegated)&&(0,l.jsxs)("div",{className:" absolute -bottom-2 left-5 gap-1",children:[(0,l.jsx)("img",{src:c.rootUserImage,alt:"Root User Image",className:"w-5 h-5 rounded-full object-cover border-2 border-white dark:border-slate-800 border-solid"}),(0,l.jsx)("span",{className:"text-xs",children:c.rootUserEmail})]})]}),(0,l.jsx)("span",{className:"font-semibold text-base"+((null===c||void 0===c?void 0:c.delegated)?" -mt-3":""),children:d.db_name})]}),(0,l.jsx)(f.Z,{size:20}),(0,l.jsxs)("div",{className:"dropdown p-0",children:[(0,l.jsx)("hr",{className:"m-0"}),(0,l.jsx)("a",{href:"/admin/".concat(null===r||void 0===r?void 0:r.id,"/databases/").concat(d.db_slug,"/edit-database"),className:"button plain-text more-padding normal-weight",children:"Edit Database"}),(0,l.jsx)("hr",{className:"m-0"}),!u&&(0,l.jsxs)(s.Fragment,{children:[(0,l.jsx)("a",{href:"/admin/".concat(null===r||void 0===r?void 0:r.id,"/databases/add-database?duplicate=").concat(d.db_full_name),className:"button plain-text more-padding normal-weight",children:"Duplicate Database"}),(0,l.jsx)("hr",{className:"m-0"})]}),(0,l.jsx)("a",{href:"/admin/".concat(null===r||void 0===r?void 0:r.id,"/databases/").concat(d.db_slug,"/schema"),className:"button plain-text more-padding normal-weight",children:"Schema"}),(0,l.jsx)("hr",{className:"m-0"}),(0,l.jsx)("a",{href:"/admin/".concat(null===r||void 0===r?void 0:r.id,"/databases/").concat(d.db_slug,"/users"),className:"button plain-text more-padding normal-weight",children:"Database Users"}),!m&&(0,l.jsx)(v,{database:d,user:r})]})]}),(0,l.jsx)("hr",{className:"vertical"}),(0,l.jsx)(i.Z,{slugText:d.db_slug,title:"Copy Database Slug"}),!m&&(0,l.jsxs)(s.Fragment,{children:[(0,l.jsx)("hr",{className:"vertical"}),(0,l.jsxs)("a",{href:"/admin/".concat(null===r||void 0===r?void 0:r.id,"/databases/").concat(d.db_slug,"/shell"),className:"button ghost small-text",style:{height:"30px",padding:0},children:[(0,l.jsx)(b.Z,{size:20}),(0,l.jsx)("span",{className:"text-sm font-semibold",children:"Shell"})]})]}),(0,l.jsx)("hr",{className:"vertical"}),(0,l.jsx)(o.Z,{})]})}function v(e){var a=e.database,t=e.user,i=(0,n.Z)(s.useState(!1),2),o=i[0],f=i[1],b=s.useRef();return(0,l.jsxs)(s.Fragment,{children:[o&&(0,l.jsx)(h.Z,{width:"20px"}),(0,l.jsx)("hr",{className:"m-0"}),(0,l.jsx)("a",{href:"/admin/".concat(null===t||void 0===t?void 0:t.id,"/databases/").concat(a.db_slug,"/shell"),className:"button plain-text more-padding normal-weight",children:"Shell"}),(0,l.jsx)("hr",{className:"m-0"}),1==(null===a||void 0===a?void 0:a.remote_connected)?(0,l.jsx)(g,{database:a}):(0,l.jsx)("a",{href:"/admin/".concat(null===t||void 0===t?void 0:t.id,"/databases/").concat(a.db_slug,"/connect"),className:"button plain-text more-padding normal-weight",children:"Connect"}),(0,l.jsx)("hr",{className:"m-0"}),(0,l.jsxs)("button",{className:"button plain-text more-padding normal-weight w-full",onClick:function(e){(0,d.Z)({url:"/api/exportDatabase?dbName=".concat(a.db_full_name),fileName:"".concat(a.db_full_name,".sql")})},children:[(0,l.jsx)(c.Z,{fontSize:"small",color:"action",className:"opacity-50"}),(0,l.jsx)("span",{children:"Export Database"})]}),(0,l.jsx)("input",{type:"file",name:"upload-update-schema",id:"",ref:b,className:"hidden"}),(0,l.jsxs)("button",{className:"button green outlined more-padding normal-weight w-full rounded-none -mb-[1px]",onClick:function(e){var t;b.current&&(b.current.addEventListener("change",(function(e){var t,n=null===(t=e.target.files)||void 0===t?void 0:t[0];if(n){var l=new FileReader;l.onload=function(e){var t,n=null===(t=e.target)||void 0===t?void 0:t.result;n||alert("Invalid File!");try{var l=null===n||void 0===n?void 0:n.toString();if(!l)throw new Error("Invalid File!");var s=JSON.parse(l);window.confirm("Are you sure you want to use this schema file for the current database?")&&window.confirm("Remember if any existing table doesn't exist in the new schema file that table and all its content will be erased forever. Continue?")&&(f(!0),(0,m.Z)("/api/user-schema/replace-database-schema",{method:"POST",body:{schema:s,dbId:a.id}},!0).then((function(e){e.success&&window.location.reload()})).finally((function(){f(!1)})))}catch(i){alert("Invalid File. Please enter a valid JSON file")}},l.readAsText(n)}else alert("No File Selected")})),null===(t=b.current)||void 0===t||t.click())},children:[(0,l.jsx)(u.Z,{fontSize:"small",color:"action",className:"opacity-50 text-inherit"}),(0,l.jsx)("span",{children:"Update From Schema"})]}),(0,l.jsxs)("button",{className:"button secondary outlined more-padding normal-weight w-full rounded-none",onClick:function(e){(0,d.Z)({url:"/api/downloadDatabaseSchema?dbName=".concat(a.db_full_name),fileName:"".concat(a.db_full_name,".json")})},children:[(0,l.jsx)(r.Z,{fontSize:"small",color:"action",className:"opacity-50 text-inherit"}),(0,l.jsx)("span",{children:"Download Schema"})]})]})}function g(e){var a=e.database;return(0,l.jsx)("button",{className:"button plain-text more-padding normal-weight w-full",onClick:function(e){window.confirm("Disconnect this Database from the remote host?")&&(0,m.Z)("/api/connect/disconnect",{method:"POST",body:{dbId:a.id}},!0).then((function(e){e.success?window.location.reload():(console.log(e),alert(e.msg||"Remote disconnection failed. Please try again."))}))},children:"Disconnect"})}},87851:function(e,a,t){function n(e){var a=e.url,t=e.fileName,n=e.setLoading;n&&n(!0),fetch(a,{method:"GET",headers:{"x-csrf-auth":localStorage.getItem("csrf")}}).then((function(e){return e.body})).then((function(e){var a=null===e||void 0===e?void 0:e.getReader();if(a)return new ReadableStream({start:function(e){return function t(){return null===a||void 0===a?void 0:a.read().then((function(a){var n=a.done,l=a.value;if(!n)return e.enqueue(l),t();e.close()}))}()}})})).then((function(e){return new Response(e)})).then((function(e){return e.blob()})).then((function(e){return URL.createObjectURL(e)})).then((function(e){var a=document.createElement("a");a.href=e,a.download=t,a.style.display="none",document.body.appendChild(a),a.click(),URL.revokeObjectURL(e),document.body.removeChild(a),setTimeout((function(){n&&n(!1)}),1e3)})).catch((function(e){console.log(e),setTimeout((function(){n&&n(!1)}),1e3)}))}t.d(a,{Z:function(){return n}})}}]);