"use strict";exports.id=5421,exports.ids=[5421],exports.modules={77802:(e,a,t)=>{t.d(a,{A:()=>F});var l=t(8732),s=t(82015),i=t.n(s);function d({tableFields:e,setTableFields:a,setRefresh:t,setPageRefresh:l,refreshFieldsListRef:s}){let i=e.findIndex(e=>"date_created"===e.fieldName);e.splice(i,0,{newTempField:!0}),a(e),s?.current&&s.current(e=>e+1)}t(80255);var r=t(39897),n=t(32415),c=t(64030),o=t(27825),m=t.n(o);function u({tableFields:e,setTableFields:a,refreshFieldsListRef:t,order:l,field:s,e:i}){let d=m().cloneDeep(e),r=d.findIndex(e=>e.fieldName===s.fieldName);if(r<0)return;let n=d[r];if("up"===l&&r&&r<=1){console.log("Min Reached =>",r);return}if("down"===l&&r&&r>=d.length-7){console.log("Max Reached =>",r);return}try{let e;let a=i.target.closest(".table-field-wrapper"),t=a.previousElementSibling,s=a.nextElementSibling,d=window.DSQL.Flip,r=d.getState(a);"up"===l?(e=d.getState(t),a.parentNode?.insertBefore(a,t)):s?.nextElementSibling&&(e=d.getState(s),a.parentNode?.insertBefore(a,s.nextElementSibling)),d.from(r,{duration:.3,ease:"power1.inOut"}),d.from(e,{duration:.3,ease:"power1.inOut"})}catch(e){console.log("Error =>",e.message)}if(!r){console.log("No target Field Index =>",r);return}d.splice(r,1),"up"===l?d.splice(r-1,0,n):d.splice(r+1,0,n),setTimeout(()=>{a([...d]),t.current&&t.current(e=>e+1)},500)}var p=t(64417),x=t(12097),h=t(63715);function f({field:e,setTargetField:a,fieldIndex:t,tableFields:s,setTableFields:d,refreshFieldsListRef:r,database:n,currentTable:o,user:m,isDelegated:u,setLoading:p}){let[f,g]=i().useState(e),[w,y]=i().useState(!1);return(0,l.jsxs)("div",{className:"flex-col w-full table-field-wrapper"+(w?" shadow-2xl shadow-slate-700/40 relative z-50":""),children:[(0,l.jsxs)("div",{className:"card no-hover items-center w-full py-4"+(w?" rounded-t":" rounded")+(f.fieldName?.match(c.A)?" text-slate-400 pointer-events-none border-slate-200 border":" light-gray"),children:[(0,l.jsx)("span",{className:"font-bold"+(f.fieldName?.match(c.A)?" dark:text-slate-500":" dark:text-white"),children:f.fieldName}),(0,l.jsx)("span",{className:"text-xs py-1 px-2 bg-slate-100 dark:bg-slate-700 dark:text-slate-200 rounded ",children:f.dataType}),f?.foreignKey&&(0,l.jsxs)("div",{className:"text-xs bg-primary text-white px-2 py-0.5 rounded-full",children:[(0,l.jsx)("span",{children:"Foreign Key: "}),(0,l.jsxs)("span",{children:[f.foreignKey.destinationTableName," ("," ",(0,l.jsx)("b",{children:f.foreignKey.destinationTableColumnName})," ",")"]})]}),f.fieldName?.match(c.A)&&(0,l.jsx)("span",{className:"text-slate-300 text-sm font-semibold ml-0 md:ml-auto",children:"Default Field"}),!(!u&&!f.fieldName?.match(c.A)&&f.dataType?.match(/INT/))||f.foreignKey||n?.active_clone?.toString()?.match(/1/)?!u&&!f.fieldName?.match(c.A)&&f.dataType?.match(/INT/)&&!n?.active_clone?.toString()?.match(/1/)?(0,l.jsx)("div",{className:"ml-0 md:ml-auto flex-wrap",children:(0,l.jsx)("div",{className:"button py-1 text-xs light-gray",onClick:a=>{window.confirm("Delete this foreign Key?")&&(delete e.foreignKey,p(!0),(0,h.A)("/api/updateClonedTableForeignKeys",{method:"post",body:{tableData:o,database:n.db_full_name,dbSlug:n.db_slug,delegated:!!window.location?.search?.match(/delegated=true/i)}},!0).then(e=>{e.success?window.location.reload():window.alert("Update Failed, Please Try again.")}))},style:{color:"var(--slate-500)"},children:"Delete Foreign Key"})}):(0,l.jsx)(i().Fragment,{}):(0,l.jsx)("div",{className:"ml-0 md:ml-auto flex-wrap",children:(0,l.jsx)("div",{className:"button outlined py-1 text-xs gray",onClick:e=>{w?y(!1):y(!0)},style:{color:"var(--slate-500)"},children:"Add Foreign Key"})})]}),w&&!u&&(0,l.jsx)("div",{className:"card col w-full -mt-5 pt-0 no-hover",children:(0,l.jsx)(x.A,{targetField:e,setFieldData:g,tableFields:s,setTableFields:d,database:n,currentTable:o,user:m,setActiveEdit:y,activeClonedTable:!0})})]})}var g=t(65388),w=t(84896);function y({fieldIndex:e,setTableFields:a,database:s,user:d,isNewField:r,setLiteralValue:n,tempFieldData:c,setTempFieldData:o,dataTypeValue:m,setDataTypeValue:u,dataType:p,setDataType:x,dataTypeDesc:h,setDataTypeDesc:f}){let y=t(94327);i().useRef();let b=!!p.match(/uuid/i);return(0,l.jsxs)(i().Fragment,{children:[r&&(0,l.jsx)("span",{className:"absolute -top-4 text-sm bg-fuchsia-600 dark:bg-white text-white dark:text-fuchsia-800 px-3 py-1 rounded-full",children:"New Field"}),(0,l.jsxs)("div",{className:"gap-4 flex-wrap xl:flex-nowrap flex-col xl:flex-row items-stretch w-full xl:w-auto",children:[(0,l.jsxs)("div",{className:"flex flex-col items-start gap-0.5",children:[(0,l.jsx)("label",{htmlFor:"new_field_name",children:"Field Name"}),(0,l.jsx)("input",{type:"text",name:"new_field_name",id:"new_field_name",placeholder:"Eg. post_title",onInput:async e=>{let a=e.target,t=a.value.toLowerCase().replace(/ /g,"_");a.value=t},required:!0})]}),(0,l.jsxs)("div",{className:"flex flex-col items-start gap-4 xl:gap-0.5",children:[(0,l.jsxs)("div",{className:"items-start flex-wrap xl:flex-nowrap",children:[(0,l.jsx)("label",{htmlFor:"new_field_data_type",children:"Data Type"}),(0,l.jsxs)("div",{className:"dropdown-wrapper reversed text-sm w-full items-start gap-2",children:[(0,l.jsx)("span",{className:"px-2 bg-slate-200 dark:bg-slate-700 rounded-full hover:bg-slate-100 dark:hover:bg-slate-600 hidden xl:flex",children:"Info"}),(0,l.jsx)("div",{className:"dropdown mt-0 xl:-mt-2",children:(0,l.jsx)("span",{children:h})})]})]}),(0,l.jsxs)("div",{className:"w-full xl:w-auto",children:[(0,l.jsx)("select",{name:"new_field_data_type",id:"new_field_data_type",className:"w-full xl:w-auto",onChange:e=>{let a=e.target;x(a.value),a.childNodes.forEach(e=>{e.value===a.value&&f(e.dataset.desc),e.value===a.value&&e.dataset.literal&&n(e.dataset.literal)})},children:y.map((e,a)=>e.name.match(/VARCHAR/)?(0,l.jsx)("option",{value:e.name,"data-desc":e.description,children:e.title+"("+(m||200)+")"},a+1):(0,l.jsx)("option",{value:e.name,"data-desc":e.description,"data-literal":e.valueLiteral||void 0,children:e.title},a+1))}),p.match(/VARCHAR/)&&(0,l.jsx)("input",{type:"number",defaultValue:m,className:"px-2",style:{maxWidth:"60px"},max:255,min:5,onChange:e=>{u(e.target.value)}})]})]}),p?.match(/text/i)&&(0,l.jsx)(i().Fragment,{children:(0,l.jsx)(w.A,{targetField:c})}),!b&&(0,l.jsxs)("div",{className:"flex flex-col items-start gap-0.5",style:{minWidth:"70px"},children:[(0,l.jsx)("label",{htmlFor:"new_field_required",children:"Required?"}),(0,l.jsxs)("select",{name:"new_field_required",id:"new_field_required",className:"px-2",children:[(0,l.jsx)("option",{value:"No",children:"No"}),(0,l.jsx)("option",{value:"Yes",children:"Yes"})]})]}),!b&&(0,l.jsxs)("div",{className:"flex flex-col items-start gap-0.5",children:[(0,l.jsx)("label",{htmlFor:"new_field_default_value",children:"Default Value (optional)"}),(0,l.jsx)("input",{type:"text",name:"new_field_default_value",id:"new_field_default_value",placeholder:"Default Value"})]}),!b&&(0,l.jsx)(g.A,{database:s,setFieldData:o,targetField:c,user:d,fieldIndex:e})]}),(0,l.jsxs)("div",{className:"secondary mt-auto flex-wrap xl:flex-nowrap w-full xl:w-auto",children:[(0,l.jsx)("button",{type:"submit",className:"secondary mt-auto py-3 w-full sm:w-auto justify-center grow",children:"Add Field"}),(0,l.jsx)("div",{className:"button outlined-gray mt-auto py-2.5 w-full sm:w-auto justify-center grow",onClick:t=>{a(a=>a.filter((a,t)=>t!=e))},children:"Cancel"})]})]})}function b({fieldIndex:e,tableFields:a,setTableFields:s,refreshFieldsListRef:d,database:r,currentTable:n,user:c}){t(94327);let[o,m]=i().useState("VARCHAR"),[u,p]=i().useState("200"),[x,h]=i().useState("Varchar is simply letters and numbers within the range 0 - 255"),[f,g]=i().useState({}),w=i().useRef(),[b,v]=i().useState(""),j=!!o.match(/uuid/i);return(0,l.jsx)("div",{className:"w-full mt-1 flex-wrap relative z-0 hover:z-20",ref:w,children:(0,l.jsx)("form",{className:"flex flex-row items-start gap-4 w-full justify-between border border-solid p-4 pt-6 border-slate-400 rounded focus:shadow-lg shadow-slate-400/40 dark:shadow-black/30 relative flex-wrap xl:flex-nowrap shadow-xl",onSubmit:a=>{a.preventDefault();let t=f.foreignKey;t&&!t.destinationTableName&&delete f.foreignKey;let l=a.target,i=l.new_field_name.value,r=l.new_field_data_type.value,n=l.new_field_required?.value,c=l.new_field_default_value?.value,o=l.encryption_field?.value,m=l.rich_text_option?.value,p=l.foreign_key_field,x=l.foreign_key_destination_table_name,h=l.foreign_key_destination_table_column_name;p?.value;let g={...f,fieldName:i,dataType:f?.dataType&&f?.foreignKey?f.dataType:r?.match(/VARCHAR/)?`${r}(${u})`:r};n?.match(/yes/i)?g.notNullValue=!0:c?.match(/./)||(g.nullValue=!0),c?.match(/./)&&(g.defaultValue=c),o?.match(/yes/i)&&(g.encrypted=!0),h?.value?.match(/./i)&&!h?.value?.match(/^--$/i)&&(g.dataType=h.dataset.dataType,g.foreignKey={foreignKeyName:h.dataset.foreignKeyName,destinationTableName:x.dataset.destinationTableName,destinationTableColumnName:h.dataset.destinationTableColumnName,cascadeDelete:!0}),m?.match(/yes/i)&&(g.richText=!0),j?(g.defaultValueLiteral=b,g.nullValue=!1):delete g.defaultValueLiteral,console.log("newFieldObject",g),function({fieldIndex:e,setTableFields:a,refreshFieldsListRef:t,payload:l}){a(a=>(a.splice(e,1,l),a)),t?.current&&t.current(e=>e+1)}({fieldIndex:e,setTableFields:s,refreshFieldsListRef:d,payload:g})},children:(0,l.jsx)(y,{database:r,fieldIndex:e,isNewField:!0,literalValue:b,refreshFieldsListRef:d,setLiteralValue:v,setTableFields:s,user:c,currentTable:n,tableFields:a,tempFieldData:f,setTempFieldData:g,dataTypeValue:u,setDataTypeValue:p,dataType:o,setDataType:m,dataTypeDesc:x,setDataTypeDesc:h})})})}var v=t(62506),j=t(58526);function N({field:e,setTargetField:a,fieldIndex:t,tableFields:s,setTableFields:d,refreshFieldsListRef:r,database:n,currentTable:o,confirmedDelegetedUser:m,user:x}){let h=m?.delegated,f=m?.priviledges?.match(/Edit Tables/i);m?.priviledges?.match(/Delete Tables/i),m?.priviledges?.match(/Create Tables/i);let{active_clone:g,active_clone_parent_db:w,remote_connected:y}=n,[b,N]=i().useState(e),[_,T]=i().useState(!1);return(0,l.jsxs)("div",{className:"flex-col w-full table-field-wrapper"+(_?" shadow-2xl shadow-slate-300/40 dark:shadow-black/30 relative z-50":""),children:[(0,l.jsxs)("div",{className:"card no-hover items-center w-full py-4"+(_?" rounded-t":" rounded")+(b.fieldName?.match(c.A)?" text-slate-400 pointer-events-none border-slate-200 border":" light-gray"),children:[(0,l.jsx)("span",{className:"font-bold"+(b.fieldName?.match(c.A)?" dark:text-slate-500":" dark:text-white"),children:b.fieldName}),(0,l.jsx)("span",{className:"text-xs py-1 px-2 bg-slate-100 dark:bg-slate-700 dark:text-slate-200 rounded ",children:b.dataType}),b?.foreignKey&&(0,l.jsxs)("div",{className:"text-xs bg-primary text-white px-2 py-0.5 rounded-full",children:[(0,l.jsx)("span",{children:"Foreign Key: "}),(0,l.jsxs)("span",{children:[b.foreignKey.destinationTableName," ("," ",(0,l.jsx)("b",{children:b.foreignKey.destinationTableColumnName})," ",")"]})]}),b.fieldName?.match(c.A)&&(0,l.jsx)("span",{className:"text-slate-300 text-sm font-semibold ml-0 md:ml-auto",children:"Default Field"}),!b.fieldName?.match(c.A)&&!w&&!y&&(0,l.jsx)("div",{className:"ml-0 md:ml-auto flex-wrap",children:(!h||h&&f)&&(0,l.jsxs)(i().Fragment,{children:[(0,l.jsxs)(v.A,{children:[(0,l.jsx)("div",{className:"button outlined py-1 text-xs gray",onClick:e=>{_?T(!1):T(!0)},style:{color:"var(--slate-500)"},children:"Edit"}),!w&&!y&&(0,l.jsx)("div",{className:"button outlined py-1 text-xs gray",onClick:a=>{window.confirm(`Delete "${e.fieldName}"?`)&&d(e=>e.filter((e,a)=>a!=t))},style:{color:"var(--slate-500)"},children:"Delete"})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("div",{className:"button outlined gray p-2 w-8 h-8 rounded-full rotate-180",onClick:a=>{u({tableFields:s,setTableFields:d,refreshFieldsListRef:r,order:"up",field:e,e:a})},children:(0,l.jsx)(j.A,{size:20})}),(0,l.jsx)("div",{className:"button outlined gray p-2 w-8 h-8 rounded-full",onClick:a=>{u({tableFields:s,setTableFields:d,refreshFieldsListRef:r,order:"down",field:e,e:a})},children:(0,l.jsx)(j.A,{size:20})})]})]})})]}),_&&(0,l.jsx)("div",{className:"w-full",children:(0,l.jsx)(p.A,{fieldIndex:t,tableFields:s,setTableFields:d,refreshFieldsListRef:r,targetField:e,setActiveEdit:T,database:n,currentTable:o,user:x})})]})}var _=t(63014);let T=1;function F({user:e,tableFields:a,setTableFields:t,setTargetField:s,refreshFieldsListRef:c,updateTable:o,updateTableAfterFieldsUpdateFunction:m,collapsed:u,database:p,table:x,confirmedDelegetedUser:h,query:g}){x?.childTable&&x.childTableDbFullName?.replace(new RegExp(/datasquirel_user_\d+_/),"");let w=h?.delegated,y=h?.priviledges?.match(/Edit Tables/i);h?.priviledges?.match(/Delete Tables/i),h?.priviledges?.match(/Create Tables/i);let{active_clone:v,active_clone_parent_db:j,remote_connected:F}=p,[A,C]=i().useState(0);c.current=C;let[S,k]=i().useState(!1),[D,$]=i().useState(u||!1);return w&&!y?(0,l.jsx)(l.Fragment,{}):(0,l.jsxs)("section",{className:"paper green",children:[S&&(0,l.jsx)(n.A,{}),x?.childTable?(0,l.jsxs)(i().Fragment,{children:[(0,l.jsxs)("div",{className:"w-full justify-between flex-wrap",children:[(0,l.jsx)("h2",{className:"text-xl m-0 text-left title",children:"Fields"}),(0,l.jsxs)("div",{children:[(0,l.jsx)("div",{className:"button outlined light-gray",onClick:a=>{let t=(0,_.A)({paradigm:"JavaScript",table:x,query:g,user:e});t&&navigator.clipboard.writeText(t).then(()=>{window.alert("JavaScript Type Definition Copied")})},children:(0,l.jsx)("span",{children:"Copy TypeDef (JS)"})}),(0,l.jsx)("div",{className:"button outlined light-gray",onClick:a=>{let t=(0,_.A)({paradigm:"TypeScript",table:x,query:g,user:e});t&&navigator.clipboard.writeText(t).then(()=>{window.alert("TypeScript Type Definition Copied")})},children:(0,l.jsx)("span",{children:"Copy TypeDef (TS)"})})]})]}),(0,l.jsx)("div",{className:"flex-col w-full",style:D?{maxHeight:"200px"}:{},children:a&&a[0]&&a.map((i,d)=>(T++,(0,l.jsx)(f,{field:i,fieldIndex:d,setTargetField:s,setTableFields:t,refreshFieldsListRef:c,tableFields:a,database:p,setLoading:k,currentTable:x,user:e,isDelegated:w},T)))}),u&&(0,l.jsx)(r.A,{collapse:D||!1,setCollapse:$})]}):(0,l.jsxs)(i().Fragment,{children:[(0,l.jsxs)("div",{className:"w-full justify-between flex-wrap",children:[(0,l.jsx)("h2",{className:"text-xl m-0 text-left title",children:"Fields"}),(0,l.jsxs)("div",{children:[(!w||w&&y)&&!j&&!F&&(0,l.jsxs)("div",{className:"button secondary outlined",onClick:e=>{D&&$(!1),d({setTableFields:t,tableFields:a,setRefresh:C,refreshFieldsListRef:c})},children:[(0,l.jsx)("span",{className:"symbol",children:"+"}),(0,l.jsx)("span",{children:"Add New Field"})]}),(0,l.jsx)("div",{className:"button outlined light-gray",onClick:a=>{if(!x)return;let t=(0,_.A)({paradigm:"JavaScript",table:x,query:g,user:e});t&&navigator.clipboard.writeText(t).then(()=>{window.alert("JavaScript Type Definition Copied")})},children:(0,l.jsx)("span",{children:"Copy TypeDef (JS)"})}),(0,l.jsx)("div",{className:"button outlined light-gray",onClick:a=>{if(!x)return;let t=(0,_.A)({paradigm:"TypeScript",table:x,query:g,user:e});t&&navigator.clipboard.writeText(t).then(()=>{window.alert("TypeScript Type Definition Copied")})},children:(0,l.jsx)("span",{children:"Copy TypeDef (TS)"})})]})]}),(0,l.jsxs)("div",{className:"flex-col w-full",style:D?{maxHeight:"200px"}:{},children:[a&&a[0]&&a.map((i,d)=>(T++,i.newTempField)?(0,l.jsx)(b,{fieldIndex:d,tableFields:a,setTableFields:t,refreshFieldsListRef:c,database:p,currentTable:x,user:e},T):(0,l.jsx)(N,{field:i,fieldIndex:d,setTargetField:s,setTableFields:t,refreshFieldsListRef:c,tableFields:a,database:p,currentTable:x,confirmedDelegetedUser:h,user:e},T)),(!w||w&&y)&&!j&&!F&&(0,l.jsxs)(i().Fragment,{children:[(0,l.jsxs)("div",{className:"button outlined gray w-full more-padding",style:{borderStyle:"dashed"},onClick:e=>{D&&$(!1),d({setTableFields:t,tableFields:a,setRefresh:C,refreshFieldsListRef:c})},children:[(0,l.jsx)("span",{className:"symbol",children:"+"}),(0,l.jsx)("span",{children:"Add New Field"})]}),o&&(0,l.jsx)("button",{className:"secondary w-full py-3",onClick:e=>{k(!0),m&&m(k)},children:"Update Table Fields"})]})]}),u&&(0,l.jsx)(r.A,{collapse:D,setCollapse:$})]})]})}},63014:(e,a,t)=>{t.d(a,{A:()=>s});var l=t(64030);function s({paradigm:e,table:a,query:t,user:s}){let i="";try{let s=`DSQL_${t.single}_${t.single_table}`.toUpperCase(),r=a.fields;function d(e){return e?.match(/int/i)?"number":(e?.match(/text|varchar|timestamp/i),"string")}let n=[],c=[];n.push(`type ${s} = {`),c.push(`/** * @typedef {object} ${s}`),r.forEach(e=>{let a=e.nullValue?"?":e.fieldName?.match(l.A)?"?":"";n.push(` ${e.fieldName}${a}: ${d(e.dataType||"")};`),c.push(` * @property {${d(e.dataType||"")}${a}} ${e.fieldName}`)}),n.push("}"),c.push(" */"),e?.match(/javascript/i)&&(i=c.join("\n")),e?.match(/typescript/i)&&(i=n.join("\n"))}catch(e){console.log(e.message),i=null}return i}},39897:(e,a,t)=>{t.d(a,{A:()=>s});var l=t(8732);function s({collapse:e,setCollapse:a}){return(0,l.jsxs)("div",{className:"collapse-block"+(e?" -mt-16 -mb-6 pt-10":" mt-0 mb-0 p-0"),onClick:t=>{e?a(!1):a(!0)},children:[(0,l.jsx)("span",{children:e?"Expand":"Collapse"}),(0,l.jsx)("img",{src:"/images/down-arrow-dark.svg",alt:"Down Arrow",width:16,className:"dark:hidden opacity-30 "+(e?"":"rotate-180")}),(0,l.jsx)("img",{src:"/images/down-arrow-white.svg",alt:"Down Arrow",width:16,className:"opacity-30 hidden dark:flex "+(e?"":"rotate-180")})]})}t(82015)},64030:(e,a,t)=>{t.d(a,{A:()=>l});let l=/^id$|^uuid$|^date_created$|^date_created_code$|^date_created_timestamp$|^date_updated$|^date_updated_code$|^date_updated_timestamp$/},93342:(e,a,t)=>{t.d(a,{A:()=>d});let l=t(22373),s=t(29021),i=t(33873);function d({userId:e}){try{let a=i.resolve(process.cwd(),`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${e}/main.json`);return JSON.parse(s.readFileSync(a,"utf-8"))}catch(e){return l({component:"grabUserSchemaData",message:e.message}),null}}}};