"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[6836],{6836:(e,l,a)=>{a.d(l,{A:()=>r,p:()=>d});var s=a(4848),t=a(6540),n=a(8963),i=a(2378);function r(e){var l,a,r;let{database:o,tables:c,setTargetTable:u,confirmedDelegetedUser:m,query:h,user:p}=e;return null==m||m.delegated,null==m||null===(l=m.priviledges)||void 0===l||l.match(/Edit Tables/i),null==m||null===(a=m.priviledges)||void 0===a||a.match(/Delete Tables/i),null==m||null===(r=m.priviledges)||void 0===r||r.match(/Create Tables/i),(0,s.jsxs)(t.Fragment,{children:[o.active_clone&&p?(0,s.jsx)(i.A,{database:o,user:p}):(0,s.jsx)(s.Fragment,{}),o.remote_connected?(0,s.jsx)(d,{database:o}):(0,s.jsx)(s.Fragment,{}),(0,s.jsxs)("section",{className:"paper gray",children:[c&&c[0]?(0,s.jsxs)("div",{className:"flex-wrap gap-4 justify-between w-full",children:[(0,s.jsx)("h2",{className:"text-xl m-0",children:"Tables"}),(0,s.jsx)("a",{href:"/admin/".concat(null==p?void 0:p.id,"/databases/").concat(o.db_slug,"/tables"),className:"button outlined gray small-text",children:"See All Tables"})]}):(0,s.jsx)("h2",{className:"text-xl m-0",children:"This Database is empty"}),(0,s.jsx)("hr",{}),p?(0,s.jsx)(n.A,{database:o,tables:c,setTargetTable:u,confirmedDelegetedUser:m,query:h,user:p}):null]})]})}function d(e){var l;let{database:a}=e;return(0,s.jsx)("div",{className:"info green",children:(0,s.jsxs)("span",{className:"text font-normal",children:["This database is an active clone of"," ",(0,s.jsx)("b",{children:null===(l=a.remote_db_full_name)||void 0===l?void 0:l.replace(/datasquirel_user_\d+_/,"")})," ","on"," ",(0,s.jsx)("a",{className:"font-bold text-inherit",href:a.remote_connection_host,target:"_blank",children:a.remote_connection_host})," ","Host"]})})}},8963:(e,l,a)=>{a.d(l,{A:()=>w});var s=a(4848),t=a(6540),n=a(7121),i=a(5165),r=a(557),d=a(8190),o=a(8453);function c(e){var l,a,c,u;let{table:m,setTargetTable:h,database:p,confirmedDelegetedUser:f,query:x,icons:b,user:v}=e,g=null==f?void 0:f.delegated,j=null==f?void 0:null===(l=f.priviledges)||void 0===l?void 0:l.match(/Edit Tables/i),N=null==f?void 0:null===(a=f.priviledges)||void 0===a?void 0:a.match(/Delete Tables/i);null==f||null===(c=f.priviledges)||void 0===c||c.match(/Create Table/i);let{active_clone:y,active_clone_parent_db:w,remote_connected:_}=p;return(0,s.jsxs)("a",{href:"/admin/".concat(null==v?void 0:v.id,"/databases/").concat(p.db_slug,"/tables/").concat(m.table_slug),className:"card w-full items-center justify-between py-4"+((null==m?void 0:m.child_table)?" green":""),onClick:e=>{e.target.closest(".db-list-item-actions-block")&&e.preventDefault()},children:[(0,s.jsxs)("div",{className:"flex-wrap items-center flex",children:[(0,s.jsx)(d.A,{size:20,opacity:.3}),(0,s.jsx)("span",{className:"title",style:{fontSize:"16px"},children:m.table_name}),(0,s.jsxs)("span",{className:"text-sm text-slate-400",children:["Created: ",null===(u=m.date_created)||void 0===u?void 0:u.substring(0,21)]})]}),(0,s.jsxs)("div",{className:"flex-wrap",children:[(0,s.jsx)("div",{className:"db-list-item-actions-block flex-wrap",children:(0,s.jsxs)(r.A,{children:[(0,s.jsx)(n.A,{slugText:m.table_slug||"",outlined:!0}),(!g||g&&j)&&!w&&!_&&(0,s.jsx)(t.Fragment,{children:(0,s.jsx)("div",{className:"button outlined light-gray small-text",onClick:e=>{window.location.pathname="/admin/".concat(null==v?void 0:v.id,"/databases/").concat(p.db_slug,"/tables/").concat(m.table_slug,"/edit-table")},children:(0,s.jsx)("span",{children:"Edit"})})}),!w&&!m.child_table&&(0,s.jsx)("div",{className:"button outlined light-gray small-text",onClick:e=>{window.location.href="/admin/".concat(null==v?void 0:v.id,"/databases/").concat(p.db_slug,"/tables/add-table?clone=true&clone_db=").concat(p.db_slug,"&clone_table=").concat(m.table_slug)},children:(0,s.jsx)("span",{children:"Clone"})}),(!g||g&&N)&&!w&&!_&&(0,s.jsx)("div",{className:"button outlined light-gray small-text",onClick:e=>{h(m),(0,i.PB)("delete-table-confirmation")},children:(0,s.jsx)("span",{children:"Delete"})})]})}),(0,s.jsx)(o.A,{className:"text-slate-600",size:20})]})]})}var u=a(3698),m=a(5896),h=a(620),p=a(2750);function f(e){let{database:l}=e,a=t.useRef(),[n,i]=t.useState(!1);return(0,s.jsxs)(t.Fragment,{children:[(0,s.jsx)("input",{type:"file",name:"sql-file-input",id:"sql-file-input",accept:".sql",className:"hidden",ref:a}),(0,s.jsxs)("button",{className:"flex-col normal-weight outlined gray dashed w-full p-8 relative",onClick:e=>{var s,t;null===(s=a.current)||void 0===s||s.addEventListener("change",e=>{var a;let s=e.target;if(!(null===(a=s.files)||void 0===a?void 0:a[0])){window.alert("No FIles selected");return}(0,m.A)({inputFile:s.files[0]}).then(e=>{window.confirm("Use this file '".concat(e.fileName,"' as your import file?"))&&(i(!0),(0,u.A)("/api/importDatabase",{method:"post",body:{database:l,fileBase64:e.fileBase64}},!0).then(e=>{e.success?window.location.reload():window.alert("Import Failed!"),setTimeout(()=>{i(!1)},1e3)}))})}),null===(t=a.current)||void 0===t||t.click()},children:[n&&(0,s.jsx)(h.A,{}),(0,s.jsx)("span",{className:"text-slate-400",children:"Do you have an SQL file already?"}),(0,s.jsx)(p.A,{}),(0,s.jsx)("span",{className:"",children:"Import Database"})]})]})}var x=a(4769);function b(e){let{database:l}=e,a=t.useRef(),[n,i]=t.useState(!1);return(0,s.jsxs)(t.Fragment,{children:[(0,s.jsx)("input",{type:"file",name:"json_file_input",id:"json_file_input",accept:".json",className:"hidden",ref:a}),(0,s.jsxs)("button",{className:"flex-col normal-weight outlined gray dashed w-full p-8 relative",onClick:e=>{var s,t;null===(s=a.current)||void 0===s||s.addEventListener("change",e=>{var a;let s=e.target;if(!(null===(a=s.files)||void 0===a?void 0:a[0])){window.alert("No FIles selected");return}(0,m.A)({inputFile:s.files[0]}).then(e=>{window.confirm("Use this file '".concat(e.fileName,"' as your import file?"))&&(i(!0),(0,u.A)("/api/importDatabaseSchema",{method:"post",body:{database:l,fileBase64:e.fileBase64}},!0).then(e=>{e.success?window.location.reload():window.alert("Import Failed!"),setTimeout(()=>{i(!1)},1e3)}))})}),null===(t=a.current)||void 0===t||t.click()},children:[n&&(0,s.jsx)(h.A,{}),(0,s.jsx)("span",{className:"text-slate-400",children:"Do you have a JSON schema?"}),(0,s.jsx)(x.A,{}),(0,s.jsx)("span",{className:"",children:"Import JSON schema"})]})]})}var v=a(2836),g=a(7845),j=a(1333),N=a(7220),y=a(2276);function w(e){var l,a,n;let{database:i,tables:r,setTargetTable:d,confirmedDelegetedUser:o,query:u,user:m}=e,h=null==o?void 0:o.delegated;null==o||null===(l=o.priviledges)||void 0===l||l.match(/Edit Tables/i),null==o||null===(a=o.priviledges)||void 0===a||a.match(/Delete Tables/i);let p=null==o?void 0:null===(n=o.priviledges)||void 0===n?void 0:n.match(/Create Table/i),x=(!r||!r[0])&&!h||(!r||!r[0])&&!!h&&!!p,{active_clone:w,active_clone_parent_db:_,remote_connected:A}=i;return(0,s.jsx)(t.Fragment,{children:(0,s.jsxs)("div",{className:"w-full flex-col",children:[r&&r[0]&&r.map(e=>(0,s.jsx)(c,{table:e,setTargetTable:d,database:i,confirmedDelegetedUser:o,query:u,icons:{edit:(0,s.jsx)(v.A,{}),duplicate:(0,s.jsx)(g.A,{}),delete:(0,s.jsx)(j.A,{}),copy:(0,s.jsx)(N.A,{})},user:m},e.id)),x&&!_&&!A&&(0,s.jsx)(t.Fragment,{children:(0,s.jsxs)("div",{className:"w-full grid grid-cols-1 xl:grid-cols-2 items-stretch gap-6",children:[(0,s.jsxs)("a",{href:"/admin/".concat(null==m?void 0:m.id,"/databases/").concat(i.db_slug,"/tables/add-table"),className:"button flex-col normal-weight outlined gray dashed border-dotted w-full p-8",children:[(0,s.jsx)("span",{className:"text-slate-400",children:"No Tables Created."}),(0,s.jsx)(y.A,{}),(0,s.jsx)("span",{className:"",children:"Add Table"})]}),(0,s.jsx)(f,{database:i}),(0,s.jsx)(b,{database:i})]})}),(!r||!r[0])&&h&&(0,s.jsx)("span",{className:"text-sm bg-slate-100 px-3 py-2 rounded w-full flex items-center justify-center text-slate-400",children:"Tables will show here once the owner of the database adds one"})]})})}},2378:(e,l,a)=>{a.d(l,{A:()=>t});var s=a(4848);function t(e){var l;let{database:a,user:t}=e,n=null===(l=a.active_clone_parent_db)||void 0===l?void 0:l.replace(/datasquirel_user_\d+_/,""),i="/admin/".concat(null==t?void 0:t.id,"/databases/").concat(n);return(0,s.jsx)("div",{className:"info green",children:(0,s.jsxs)("span",{className:"text font-normal",children:["This database is an active clone of"," ",(0,s.jsx)("b",{children:(0,s.jsx)("a",{href:i,target:"_blank",className:"query-url",children:n})})]})})}a(6540)},5165:(e,l,a)=>{a.d(l,{Ay:()=>i,PB:()=>r,fs:()=>d});var s=a(4848),t=a(6897),n=a(6540);function i(e){let{children:l,title:a,data:i,fullPage:r,wrapperClasses:o,closePopupDispatch:c,wrapperStyle:u,noContainer:m}=e;return r?(0,s.jsxs)("div",{className:"popup-bg overflow-hidden "+(o||""),"data-popupid":a||null,style:u,children:[m?(0,s.jsx)(n.Fragment,{children:l}):(0,s.jsx)("div",{className:"relative w-full h-full z-50","data-data":i?JSON.stringify(i):"",children:l}),(0,s.jsx)("button",{className:"popup-cancel-button fixed outlined gray",onClick:e=>{d(),c&&c()},children:(0,s.jsx)(t.A,{color:"white",size:20})}),(0,s.jsx)("div",{className:"popup-canceller",onClick:e=>{d(),c&&c()}})]}):(0,s.jsxs)("div",{className:"popup-bg","data-popupid":a||null,children:[m?(0,s.jsx)(n.Fragment,{children:l}):(0,s.jsxs)("div",{className:"popup-content-container minimal-scrollbars","data-data":i?JSON.stringify(i):"",children:[l,(0,s.jsx)("button",{className:"outlined gray popup-cancel-button",onClick:e=>{d(),c&&c()},children:(0,s.jsx)("span",{className:"font-normal",children:"✖"})})]}),m&&(0,s.jsx)("button",{className:"gray popup-cancel-button",onClick:e=>{d(),c&&c()},children:(0,s.jsx)("span",{className:"font-normal",children:"✖"})}),(0,s.jsx)("div",{className:"popup-canceller",onClick:e=>{d(),c&&c()}})]})}function r(e,l){let a=document.querySelector("[data-popupid='".concat(e,"']"));a&&(a.style.display="flex",l&&l(a))}function d(e){document.querySelectorAll("[data-popupid]").forEach(e=>{e.style.display="none"}),e&&e()}},557:(e,l,a)=>{a.d(l,{A:()=>n});var s=a(4848),t=a(6540);function n(e){let{children:l,column:a,className:n}=e,i=t.useRef();return t.useEffect(()=>{try{let e=i.current.childNodes,l=Array.from(e);if((null==l?void 0:l.length)===1)return;l.forEach((e,s)=>{let t=e;if(t.classList.contains("dropdown-wrapper")){let l=Array.from(e.childNodes).filter(e=>{var l;return(null==e?void 0:null===(l=e.nodeName)||void 0===l?void 0:l.match(/button/i))||e.classList.contains("button")});l&&l[0]&&(t=l[0])}s0&&(t.style[a?"borderTop":"borderLeft"]="none",t.style[a?"borderTopRightRadius":"borderTopLeftRadius"]=0,t.style[a?"borderTopLeftRadius":"borderBottomLeftRadius"]=0)})}catch(e){console.log(e.message)}},[]),(0,s.jsx)("div",{className:"items-stretch gap-0"+(a?" flex-col":" flex-wrap xl:flex-nowrap")+(n?" "+n:""),ref:i,children:l})}},5896:(e,l,a)=>{a.d(l,{A:()=>s});async function s(e){let{inputFile:l}=e;try{let e=l.name.replace(/\..*/,""),a=await new Promise((e,a)=>{var s=new FileReader;s.readAsDataURL(l),s.onload=function(){e(s.result)},s.onerror=function(e){console.log("Error: ",e.message)}});return{fileBase64:a.replace(/.*?base64,/,""),fileBase64Full:a,fileName:e,fileSize:l.size,fileType:l.type}}catch(e){return console.log("Image Processing Error! =>",e.message),{fileBase64:null,fileBase64Full:null,fileName:l.name,fileSize:null,fileType:null}}}}}]);