"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[6052],{4589:(e,a,t)=>{t.d(a,{A:()=>c});var l=t(4848),s=t(6540),i=t(620),d=t(7810);t(7711),t(5165);var n=t(7157),r=t(4924);function c(e){let{user:a,dbImage:t,setDbImage:c,query:o}=s.useContext(d.AddDatabaseContext);if(!a)return(0,l.jsx)(s.Fragment,{});let[u,m]=s.useState(null),[h,p]=s.useState(!1);return(0,l.jsx)("section",{className:"card",children:(0,l.jsxs)("div",{className:"w-full grid grid-cols-1 xl:grid-cols-2 gap-6 items-stretch",children:[h&&(0,l.jsx)(i.A,{}),(0,l.jsxs)("div",{className:"flex-col items-start",children:[(0,l.jsx)("h2",{className:"text-xl m-0 text-left w-full",children:"New Database Information"}),a&&t&&c&&(0,l.jsx)(n.A,{user:a,dbImage:t,setDbImage:c,setLoading:p,query:o})]}),a&&t&&c&&(0,l.jsx)(r.A,{user:a,dbImage:t,setDbImage:c})]})})}},7157:(e,a,t)=>{let l;t.d(a,{A:()=>h});var s=t(4848),i=t(6540),d=t(7711),n=t(1696);t(961);var r=t(3698),c=t(7531);async function o(e){var a,t,l,s,i,d,n;let{e:o,setLoading:u,dbImage:m,database:h,user:p}=e;u(!0);let g={db_description:(null===(t=o.target.database_description)||void 0===t?void 0:null===(a=t.value)||void 0===a?void 0:a.match(/./))?o.target.database_description.value:null,db_name:(null===(s=o.target.database_name)||void 0===s?void 0:null===(l=s.value)||void 0===l?void 0:l.match(/./))?o.target.database_name.value:null,db_slug:(null===(d=o.target.database_slug)||void 0===d?void 0:null===(i=d.value)||void 0===i?void 0:i.match(/./))?o.target.database_slug.value:null,db_full_name:h.db_full_name,id:h.id,active_clone:h.active_clone,active_clone_parent_db:h.active_clone_parent_db};if(m){if("string"==typeof m)g.db_image=m;else if("object"==typeof m){let e=await (0,r.A)("/api/addUserMedia",{method:"post",body:{media:[m],folder:g.db_slug.replace(/_/g,"-"),type:"image"}},!0);g.db_image=(null==e?void 0:null===(n=e.mediaData[0])||void 0===n?void 0:n.media_thumbnail_url)?e.mediaData[0].media_thumbnail_url:"/images/database-placeholder.png"}}else g.db_image="/images/database-placeholder.png";(0,r.A)("/api/updateUserDatabase",{method:"post",body:g},!0).then(e=>{e.success?(0,c.A)().then(()=>{window.location.pathname="/admin/".concat(null==p?void 0:p.id,"/databases"),setTimeout(()=>{u(!1)},1e3)}):(alert("Error! Please Try Again"),setTimeout(()=>{u(!1)},1e3))})}async function u(e){var a,t,l;let{e:s,setLoading:i,dbImage:d,keepUpdated:n,keepDataUpdated:o,query:u,user:m}=e;i(!0);let h={db_name:s.target.database_name.value,db_slug:s.target.database_slug.value,db_description:(null===(t=s.target.database_description)||void 0===t?void 0:null===(a=t.value)||void 0===a?void 0:a.match(/./))?s.target.database_description.value:null};if(d){if("string"==typeof d)h.db_image=d;else if("object"==typeof d){let e=await (0,r.A)("/api/addUserMedia",{method:"post",body:{media:[d],folder:h.db_slug.replace(/_/g,"-"),type:"image"}},!0);h.db_image=(null==e?void 0:null===(l=e.mediaData[0])||void 0===l?void 0:l.media_thumbnail_url)?e.mediaData[0].media_thumbnail_url:"/images/database-placeholder.png"}}(null==u?void 0:u.duplicate)&&(h.duplicate=u.duplicate,h.keepUpdated=!!n&&n,h.keepDataUpdated=!!o&&o),(0,r.A)("/api/createUserDatabase",{method:"post",body:h},!0).then(e=>{e.success?(0,c.A)().then(()=>{window.location.pathname="/admin/".concat(null==m?void 0:m.id,"/databases/").concat(h.db_slug)}):setTimeout(()=>{i(!1)},1e3)})}var m=t(1458);function h(e){let{user:a,dbImage:t,setDbImage:r,database:c,setLoading:h,query:p}=e;async function g(e){return(null==c?void 0:c.db_slug)===e?null:await (0,d.A)({tableName:"user_databases",columnName:"db_slug",value:e,userId:a.id})}let[b,v]=i.useState(null),[x,f]=i.useState(!1),[y,_]=i.useState(!1);return(0,s.jsxs)("form",{className:"w-full max-w-none xl:max-w-lg flex flex-col items-start gap-4 relative",onSubmit:e=>{e.preventDefault(),c?o({e,setLoading:h,dbImage:t,database:c,user:a}):u({e,setLoading:h,dbImage:t,keepUpdated:x,keepDataUpdated:y,query:p,user:a})},children:[b&&(0,s.jsx)(n.A,{message:b}),(0,s.jsxs)("div",{className:"flex flex-col items-start gap-0.5 w-full",children:[(0,s.jsx)("label",{htmlFor:"database_name",children:"Name"}),(0,s.jsx)("input",{type:"text",name:"database_name",id:"database_name",placeholder:"Database Name",onInput:async e=>{let a=e.target,t=a.closest("form");if(a.value.match(/./)?(a.classList.remove("warning"),v(null)):a.classList.add("warning"),t){t.database_slug.value=a.value.toLowerCase().replace(/ /g,"_").replace(/[^a-zA-Z0-9-_]/g,"");let e=t.database_slug.value;window.clearTimeout(l),l=setTimeout(()=>{g(e).then(e=>{(null==e?void 0:e.result)?(t.database_slug.classList.add("warning"),v("Duplicate Database Name")):(t.database_slug.classList.remove("warning"),v(null))})},300)}},defaultValue:c?c.db_name:"",required:!0})]}),(0,s.jsxs)("div",{className:"flex flex-col items-start gap-0.5 w-full",children:[(0,s.jsx)("label",{htmlFor:"database_slug",children:"Slug"}),(0,s.jsx)("input",{type:"text",name:"database_slug",id:"database_slug",placeholder:"Database Slug",onInput:e=>{let a=e.target;a.value.match(/./)?(a.classList.remove("warning"),v(null)):a.classList.add("warning");let t=a.value;window.clearTimeout(l),l=setTimeout(()=>{g(t).then(e=>{(null==e?void 0:e.result)?(a.classList.add("warning"),v("Duplicate Database Name")):(a.classList.remove("warning"),v(null))})},300)},defaultValue:c?c.db_slug:"",required:!0})]}),(0,s.jsxs)("div",{className:"flex flex-col items-start gap-0.5 w-full",children:[(0,s.jsx)("label",{htmlFor:"database_description",children:"Description (optional)"}),(0,s.jsx)("textarea",{name:"database_description",id:"database_description",placeholder:"Short Description of database",defaultValue:c?c.db_description:""})]}),(null==p?void 0:p.duplicate)&&(0,s.jsx)(i.Fragment,{children:(0,s.jsxs)("div",{className:"card col items-start",children:[(0,s.jsx)(m.A,{checkBoxValues:[{payload:"Keep New Database Updated?",title:"Keep New Database Updated?",name:"clone_database",onChangeHandler:e=>{e.target.checked?f(!0):f(!1)}}]}),(0,s.jsx)("span",{className:"text-sm italic text-slate-600 dark:text-slate-300",children:"By checking this box the new Database stays up to date with changes to the structure of the parent Database"})]})}),(0,s.jsxs)("button",{type:"submit",className:"w-full",children:[c?"Update":"Create"," Database"]})]})}},4924:(e,a,t)=>{t.d(a,{A:()=>r});var l=t(4848),s=t(6540),i=t(5113),d=t(5165),n=t(557);function r(e){let{user:a,dbImage:t,setDbImage:r,database:c}=e,o=s.useRef();return(0,l.jsxs)("div",{className:"card no-hover col items-center justify-center",children:[(0,l.jsx)("h4",{className:"m-0",children:"Database Image"}),(0,l.jsx)("div",{className:"bg-white rounded-full overflow-hidden w-24 h-24",children:(0,l.jsx)("img",{src:t?"string"==typeof t?t:t.imageBase64Full:"/images/database-placeholder.png",alt:"Database Image",width:100,className:"w-full h-full object-cover",ref:o,"data-imagepreview":"image"})}),(0,l.jsxs)("div",{className:"w-full flex-col",id:"edit-database-image-option-wrapper",children:[(0,l.jsxs)(n.A,{column:!0,className:"w-full",children:[(0,l.jsx)("button",{className:"outlined w-full whitespace-normal",onClick:e=>{(0,d.PB)("user-media-popup")},children:"Choose Image from uploads"}),(0,l.jsx)("button",{className:"outlined secondary w-full whitespace-normal",onClick:e=>{var a,t;let l=e.target;null==l||null===(t=l.closest("#edit-database-image-option-wrapper"))||void 0===t||null===(a=t.querySelector("input"))||void 0===a||a.click()},children:"Choose Image from Computer"})]}),(0,l.jsx)("input",{type:"file",accept:".png,.jpg,.jpeg,.webp",placeholder:"Choose Database Image",className:"hidden",onChange:async e=>{let a=e.target.files[0];r(await (0,i.A)({imageInputFile:a,maxWidth:400}))}})]})]})}},3834:(e,a,t)=>{t.d(a,{A:()=>r});var l=t(4848),s=t(6540),i=t(3698),d=t(5165),n=t(620);function r(e){let{setDbImage:a}=e,[t,r]=s.useState(!0),[c,o]=s.useState(null);return s.useEffect(()=>{(0,i.A)("/api/getUserMedia").then(e=>{r(!1),o(e.media)})},[]),(0,l.jsxs)(d.Ay,{title:"user-media-popup",children:[t&&(0,l.jsx)(n.A,{width:"20px"}),(0,l.jsx)("h4",{className:"m-0 text-lg",children:"Your Uploaded Images"}),(0,l.jsx)("div",{className:"grid grid-cols-2",children:c&&c[0]&&c.filter(e=>"image"==e.media_type).map((e,t)=>(0,l.jsx)("div",{className:"w-full h-44 cursor-pointer hover:opacity-70",onClick:t=>{a(e.media_thumbnail_url||null),(0,d.fs)()},children:(0,l.jsx)("img",{src:e.media_thumbnail_url,alt:"User Media",className:"w-full h-full object-contain"})},t+1))})]})}t(5160)},1696:(e,a,t)=>{t.d(a,{A:()=>s});var l=t(4848);function s(e){let{message:a}=e;return(0,l.jsxs)("div",{className:"p-2 bg-orange-50 w-full justify-center rounded text-sm text-orange-700 border border-orange-400 border-solid",children:[(0,l.jsx)("img",{src:"/images/warning.png",alt:"Warning Image Icon",width:22,className:"-my-2"}),(0,l.jsx)("span",{children:a})]})}t(6540)},7711:(e,a,t)=>{t.d(a,{A:()=>s}),t(961);var l=t(3698);async function s(e){let{tableName:a,columnName:t,value:s,dbFullName:i,dispatch:d,userId:n,dbId:r}=e;return await (0,l.A)("/api/checkDuplicateData?tableName=".concat(a,"&type=").concat(t,"&value=").concat(s).concat(i?"&dbFullName="+i:"").concat(n?"&userId="+n:"").concat(r?"&dbId="+r:""))}},5113:(e,a,t)=>{t.d(a,{A:()=>l});async function l(e){let a,t,{imageInputFile:l,maxWidth:s}=e,i=document.querySelector("[data-imagepreview='image']"),d=l.name.replace(/\..*/,""),n=document.createElement("canvas"),r=l.type,c=s||null,o=URL.createObjectURL(l),u=new Image;return u.src=o,a=await new Promise((e,a)=>{u.onerror=function(){URL.revokeObjectURL(this.src),console.log("Cannot load image")},u.onload=function(){if(URL.revokeObjectURL(this.src),c){let e=c/u.naturalWidth;n.width=u.naturalWidth{e.src=t}),e(t)}}),t=await new Promise((e,a)=>{n.toBlob(a=>{e(null==a?void 0:a.size)},r,.95)}),{imageBase64:a.replace(/.*?base64,/,""),imageBase64Full:a,imageName:d,imageSize:t}}},7216:(e,a,t)=>{t.d(a,{A:()=>l});let l=(0,t(5737).A)("ArrowLeft",[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]])},5014:(e,a,t)=>{t.d(a,{A:()=>l});let l=(0,t(5737).A)("BookText",[["path",{d:"M4 19.5v-15A2.5 2.5 0 0 1 6.5 2H20v20H6.5a2.5 2.5 0 0 1 0-5H20",key:"t4utmx"}],["path",{d:"M8 7h6",key:"1f0q6e"}],["path",{d:"M8 11h8",key:"vwpz6n"}]])},9140:(e,a,t)=>{t.d(a,{A:()=>l});let l=(0,t(5737).A)("Database",[["ellipse",{cx:"12",cy:"5",rx:"9",ry:"3",key:"msslwz"}],["path",{d:"M3 5V19A9 3 0 0 0 21 19V5",key:"1wlel7"}],["path",{d:"M3 12A9 3 0 0 0 21 12",key:"mv7ke4"}]])},2894:(e,a,t)=>{t.d(a,{A:()=>l});let l=(0,t(5737).A)("FileKey2",[["path",{d:"M4 22h14a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v6",key:"rc0qvx"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["circle",{cx:"4",cy:"16",r:"2",key:"1ehqvc"}],["path",{d:"m10 10-4.5 4.5",key:"7fwrp6"}],["path",{d:"m9 11 1 1",key:"wa6s5q"}]])},9508:(e,a,t)=>{t.d(a,{A:()=>l});let l=(0,t(5737).A)("Globe",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20",key:"13o1zl"}],["path",{d:"M2 12h20",key:"9i4pu4"}]])},9753:(e,a,t)=>{t.d(a,{A:()=>l});let l=(0,t(5737).A)("HardDrive",[["line",{x1:"22",x2:"2",y1:"12",y2:"12",key:"1y58io"}],["path",{d:"M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z",key:"oot6mr"}],["line",{x1:"6",x2:"6.01",y1:"16",y2:"16",key:"sgf278"}],["line",{x1:"10",x2:"10.01",y1:"16",y2:"16",key:"1l4acy"}]])},1915:(e,a,t)=>{t.d(a,{A:()=>l});let l=(0,t(5737).A)("Images",[["path",{d:"M18 22H4a2 2 0 0 1-2-2V6",key:"pblm9e"}],["path",{d:"m22 13-1.296-1.296a2.41 2.41 0 0 0-3.408 0L11 18",key:"nf6bnh"}],["circle",{cx:"12",cy:"8",r:"2",key:"1822b1"}],["rect",{width:"16",height:"16",x:"6",y:"2",rx:"2",key:"12espp"}]])},7273:(e,a,t)=>{t.d(a,{A:()=>l});let l=(0,t(5737).A)("RotateCw",[["path",{d:"M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8",key:"1p45f6"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}]])},5922:(e,a,t)=>{t.d(a,{A:()=>l});let l=(0,t(5737).A)("ShieldEllipsis",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"M8 12h.01",key:"czm47f"}],["path",{d:"M12 12h.01",key:"1mp3jc"}],["path",{d:"M16 12h.01",key:"1l6xoz"}]])},6897:(e,a,t)=>{t.d(a,{A:()=>l});let l=(0,t(5737).A)("X",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]])},7810:(e,a,t)=>{t.r(a),t.d(a,{AddDatabaseContext:()=>m,__N_SSP:()=>u,default:()=>h});var l=t(4848),s=t(6540),i=t(1187),d=t(9862),n=t(4709),r=t(4589);function c(e){let{query:a,duplicateDb:t,user:i}=s.useContext(m),c=(null==a?void 0:a.duplicate)?(0,l.jsxs)("span",{children:["Duplicate"," ",(0,l.jsx)("a",{href:"/admin/".concat(null==i?void 0:i.id,"/databases/").concat(null==t?void 0:t.db_slug),target:"_blank",children:null==t?void 0:t.db_name})," ","Database"]}):"Add A New Database";return(0,l.jsxs)(s.Fragment,{children:[(0,l.jsxs)("div",{className:"flex-col items-start gap-0 w-full",children:[(0,l.jsxs)("div",{className:"flex-wrap",children:[(0,l.jsx)(d.A,{}),(0,l.jsx)("h1",{className:"text-3xl m-0",children:c})]}),(0,l.jsx)(n.A,{user:i})]}),(0,l.jsx)(r.A,{})]})}var o=t(3834),u=!0;let m=s.createContext({});function h(e){let{user:a,databases:t,query:d,duplicateDb:n}=e,r=(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)("title",{children:"Add Database | Datasquirel"}),(0,l.jsx)("meta",{name:"description",content:"Add a database"})]}),[u,h]=s.useState("/images/database-placeholder.png");return(0,l.jsx)(i.A,{head:r,user:a,children:(0,l.jsxs)(m.Provider,{value:{user:a,databases:t,dbImage:u,setDbImage:h,query:d,duplicateDb:n},children:[(0,l.jsx)(c,{}),(0,l.jsx)(o.A,{setDbImage:h})]})})}}}]);