import { jsxs as s, jsx as a, Fragment as W } from "react/jsx-runtime";
import { execute as oe } from "@/common/services/QueryBuilder";
import { showToast as R } from "@/common/toaster/toaster";
import { useDebounceFn as ia } from "@/hooks/useDebounceFn";
import sa from "@/views/custom-components/CustomConfirmationModal";
import da from "@/views/custom-components/CustomTextField";
import x from "@/common/fontAwesomeIcons/FontAwesomeIcons";
import { F as ie } from "./index-B4r0wjBD.js";
import { Paper as he, Typography as c, Tooltip as E, Button as P, FormControl as Y, RadioGroup as pe, FormControlLabel as L, Radio as B, Autocomplete as se, TextField as V, IconButton as O, InputAdornment as ye, Popover as ua, Checkbox as ca, TableContainer as ma, Table as ha, TableHead as pa, TableRow as J, TableCell as X, TableBody as _e, Modal as ya, Switch as fa } from "@mui/material";
import p from "@mui/material/Grid2";
import { Box as f } from "@mui/system";
import N from "prop-types";
import { useState as C, useEffect as fe } from "react";
import { useForm as ga, useWatch as ba, Controller as T } from "react-hook-form";
import { useSelector as xa } from "react-redux";
function va({
  tableInfo: d,
  table: w,
  isEditMode: m,
  updateEditMode: ge,
  tableCompleteInfo: S,
  reloadComponents: je,
  isCreateTableMode: i,
  isSyncTableMode: $,
  updateCreateTableMode: be,
  openDeleteModal: He,
  setOpenDeleteModal: xe
}) {
  var ve, Ce, we, Te, Ne, Se, ke, Ve, De;
  const Ie = ["Document Master", "Form Configurator", "Form Media Record", "LMS"], Pe = (e) => (e == null ? void 0 : e.toUpperCase().replace(/ /g, "_")) || "", Ke = (e) => Ie.find((r) => Pe(r) === e) || "", Ue = (e) => {
    var r;
    return e != null && e.downloadType ? Ke(e.downloadType) || e.downloadType : (r = e == null ? void 0 : e.data) != null && r.downloadType ? Ke(e.data.downloadType) || e.data.downloadType : "";
  }, Ge = (e) => {
    var r;
    const t = e == null ? void 0 : e.downloadUrl;
    if (typeof t == "object" && t !== null) return t.apiEndpoint || "";
    const l = (r = e == null ? void 0 : e.data) == null ? void 0 : r.downloadUrl;
    return typeof l == "object" && l !== null && l.apiEndpoint || "";
  }, de = (e) => {
    var r;
    const t = e == null ? void 0 : e.downloadUrl;
    if (typeof t == "object" && t !== null) return t.requestParameters || [];
    const l = (r = e == null ? void 0 : e.data) == null ? void 0 : r.downloadUrl;
    return typeof l == "object" && l !== null ? l.requestParameters || [] : [];
  }, [ze, Me] = C([]), [Re, Z] = C(!1), [Q, ee] = C(""), [Ye, Je] = C({}), [ae, F] = C(""), [v, D] = C([]), [_, q] = C([]), [g, re] = C(0), [j, ue] = C(0), [Ee, le] = C(null), [H, ne] = C(null), [te, Xe] = C({}), [K, z] = C(
    i ? [] : de(d == null ? void 0 : d.mediaConfiguration)
  ), Le = !!Ee, Ze = Le ? "simple-popover" : void 0, Oe = ["TEXT", "INTEGER"], qe = xa((e) => e.Authenticate.user.id), I = {
    selectedColumns: i ? [] : [...d.columnInfo],
    modifiedOnQuery: i ? "" : d.modifiedOnQuery,
    dataFetchQuery: i ? "" : d.selectQuery,
    tableName: "",
    createTableQuery: "",
    syncByDefault: i ? null : (ve = d == null ? void 0 : d.syncByDefault) == null ? void 0 : ve.toString(),
    primaryKey: i ? null : d.primaryKey ? d.primaryKey : null,
    userData: i ? null : ((Ce = d == null ? void 0 : d.userData) == null ? void 0 : Ce.toString()) || null,
    hasMedia: i ? null : ((we = d == null ? void 0 : d.hasMedia) == null ? void 0 : we.toString()) || null,
    downloadType: i ? "" : Ue(d.mediaConfiguration),
    apiEndpoint: i ? "" : Ge(d.mediaConfiguration),
    requestParameters: i ? [] : de(d.mediaConfiguration),
    directoryPath: i ? "" : ((Ne = (Te = d.mediaConfiguration) == null ? void 0 : Te.directoryPath) == null ? void 0 : Ne.split("/")[1]) || ((Ve = (ke = (Se = d.mediaConfiguration) == null ? void 0 : Se.data) == null ? void 0 : ke.directoryPath) == null ? void 0 : Ve.split("/")[1]) || ""
  }, n = ga({
    defaultValues: {
      ...I
    },
    mode: "onChange"
  }), ea = !n.formState.isValid, A = n.watch("hasMedia"), Ae = n.watch("newColumnName"), We = n.watch("newColumnType");
  n.register("requestParameters", {
    validate: (e) => A !== "true" ? !0 : !e || e.length === 0 ? "At least one request parameter is required." : e.some((r) => {
      var t, l;
      return !((t = r.key) != null && t.trim()) || !((l = r.value) != null && l.trim());
    }) ? "Each parameter must have both a key and a value filled." : !0
  });
  const aa = async (e) => {
    var r;
    const t = i ? n.getValues("createTableQuery") : await $e(
      [...d.columnInfo],
      e.selectedColumns,
      d.primaryKey,
      (r = e.primaryKey) == null ? void 0 : r.toString()
    );
    t ? (Je(() => e), ee(() => t), Qe(), Z(!0)) : Be(e, !1);
  }, Be = async (e, r) => {
    var t;
    const l = {};
    let o, u = e || Ye;
    if (r || ee(""), Object.keys(u).length > 0) {
      u.selectedColumns.forEach((y) => {
        l[y.name] = y.type;
      }), u.columns = JSON.stringify(l), u.primaryKey = (t = u.primaryKey) == null ? void 0 : t.toString();
      let h = {
        downloadType: Pe(u.downloadType),
        downloadUrl: {
          apiEndpoint: u.apiEndpoint || "",
          requestParameters: K || []
        },
        directoryPath: "#directoryPath#/" + u.directoryPath + "/"
      };
      h = JSON.stringify(h), o = (await oe({
        code: "update_mobile_entity",
        parameters: {
          tableName: i ? n.getValues("tableName") : w,
          syncByDefault: u.syncByDefault === "true",
          columnInfo: u.columns,
          primaryKey: u.primaryKey,
          modifiedOnQuery: u.modifiedOnQuery,
          selectQuery: u.dataFetchQuery,
          userData: u.userData === "true",
          hasMedia: u.hasMedia === "true",
          mediaConfiguration: u.hasMedia === "true" ? h : null,
          modifiedBy: qe,
          migrationScript: Q,
          isUpdate: !0,
          generateMigration: Q !== ""
        }
      }).catch((y) => {
        R({ message: `Submission failure ${y}`, type: "error" });
      })).data;
    } else
      o = (await oe({
        code: "update_mobile_entity",
        parameters: {
          tableName: i ? n.getValues("tableName") : w,
          syncByDefault: !1,
          columnInfo: "",
          primaryKey: "",
          modifiedOnQuery: "",
          selectQuery: "",
          userData: null,
          hasMedia: null,
          mediaConfiguration: "",
          modifiedBy: qe,
          migrationScript: Q,
          isUpdate: !1,
          generateMigration: !0
        }
      }).catch((h) => {
        R({ message: `Submission failure ${h}`, type: "error" });
      })).data;
    o != null && o.result && (ge(!1), be(!1), je((h) => !h), R({ message: "Table configuration saved successfully!", type: "success" })), Z(!1);
  }, ra = () => {
    Z(!1);
  }, $e = async (e, r, t, l) => {
    let o = "";
    if (e.length > 0) {
      let u = e.map((b) => b.name), h = r.map((b) => b.name), y = e.filter((b) => !h.includes(b.name)), M = r.filter((b) => !u.includes(b.name)), U = y.map((b) => `ALTER TABLE ${w} DROP COLUMN ${b.name};`).join(`
`), k = M.map((b) => `ALTER TABLE ${w} ADD COLUMN ${b.name} ${b.type};`).join(`
`);
      return o += y.length > 0 ? `${U}
` : "", o += M.length > 0 ? `${k}` : "", o;
    } else {
      const u = i ? n.getValues("tableName") : w;
      return o = `CREATE TABLE ${u} (
`, o += r.map((h) => `${h.name} ${h.type}`).join(`,
`), l && (o += `,
CONSTRAINT ${u}_pkey PRIMARY KEY (${l})`), o += ");", o;
    }
  }, Qe = async () => {
    var e;
    const r = (e = await oe({
      code: "MFA_MIGRATION_MASTER_GET_LATEST_VERSIONS"
    }).catch((t) => {
      R({ message: `Failed to fetch migration versions ${t}`, type: "error" });
    })) == null ? void 0 : e.data;
    Xe(r == null ? void 0 : r.result[0]);
  };
  fe(() => {
    if (F(""), ue(0), re(0), i && (Me([]), D([]), q([]), z([]), n.reset({
      ...I
    }), setTimeout(() => n.trigger(), 0)), w && d && !i) {
      Me(S !== void 0 ? () => S.columnInfo : () => d.columnInfo);
      let e = S !== void 0 ? S.columnInfo.map((l) => l.name) : d.columnInfo.map((l) => l.name), r = {};
      S !== void 0 ? S.columnInfo.forEach((l) => {
        r[l.name] = l.type;
      }) : d.columnInfo.forEach((l) => {
        r[l.name] = l.type;
      });
      let t = {};
      d.columnInfo.forEach((l) => {
        t[l.name] = l.type;
      }), d.columnInfo.map((l) => {
        e.includes(l.name) || (l.onlyMobileDb = !0), t[l.name] !== r[l.name] && (l.isTypeChanged = !0), l.name === d.primaryKey && (l.isPrimaryKey = !0);
      }), n.reset({
        ...I
      }), setTimeout(() => n.trigger(), 0), z(de(d == null ? void 0 : d.mediaConfiguration)), D(
        () => d.columnInfo.sort((l, o) => l.name === d.primaryKey ? (l.isPrimaryKey = !0, -1) : o.name === d.primaryKey ? (o.isPrimaryKey = !0, 1) : l.name.localeCompare(o.name))
      ), q(S !== void 0 ? () => {
        const l = new Set(d.columnInfo.map((o) => o.name));
        return S.columnInfo.map((o) => ({
          ...o,
          isSynced: l.has(o.name)
        })).sort((o, u) => o.name === d.primaryKey ? -1 : u.name === d.primaryKey ? 1 : o.name.localeCompare(u.name));
      } : []);
    }
  }, [d, S, w, i]), fe(() => {
    const e = ae.toLowerCase();
    if (g === 0) {
      const r = n.getValues("selectedColumns"), t = e ? r.filter((l) => l.name.toLowerCase().includes(e)) : r;
      D(t);
    } else {
      const r = new Set(n.getValues("selectedColumns").map((l) => l.name)), t = e ? ze.filter((l) => l.name.toLowerCase().includes(e)).map((l) => ({
        ...l,
        isSynced: r.has(l.name)
      })) : ze.map((l) => ({
        ...l,
        isSynced: r.has(l.name)
      }));
      q(t);
    }
  }, [ae, g]);
  const Fe = ba({
    control: n.control,
    name: "tableName"
  });
  fe(() => {
    i && n.getValues("selectedColumns").length > 0 && Fe && me(n.getValues("selectedColumns"));
  }, [Fe]);
  const la = (e) => {
    ee(e);
  }, na = () => {
    m && ge(!m), i && be(!i), n.reset({
      ...I,
      newColumnName: null,
      newColumnType: null
    }), z(I.requestParameters || []), D(I.selectedColumns || []);
    const e = new Set((I.selectedColumns || []).map((r) => r.name));
    q(
      (I.allColumns || []).map((r) => ({
        ...r,
        isSynced: e.has(r.name)
      }))
    );
  }, ta = async () => {
    var e, r, t;
    xe(() => !1);
    const l = await oe({
      code: "DELETE_MOBILE_ENTITY",
      parameters: {
        tableName: w
      }
    }).catch((u) => {
      R({ message: `Metadata deletion failure ${u}`, type: "error" });
    });
    (t = (r = (e = l == null ? void 0 : l.data) == null ? void 0 : e.result) == null ? void 0 : r[0]) != null && t.table_name && R({ message: `${w} deleted successfully!`, type: "success" });
    let o = `DROP TABLE if exists ${w};`;
    ee(() => o), Qe(), Z(!0);
  }, oa = ia(async (e) => {
    const r = /^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e);
    if (e.trim().length === 0) {
      n.setError("newColumnName", {
        type: "manual",
        message: "*Column name is required. "
      });
      return;
    }
    if (!r) {
      n.setError("newColumnName", {
        type: "manual",
        message: "Must start with a letter/underscore and contain only letters, numbers, and underscores."
      });
      return;
    }
    _.some((t) => t.name === e) || v.some((t) => t.name === e) ? n.setError("newColumnName", {
      type: "manual",
      message: "Column name already exists in the table."
    }) : n.clearErrors("newColumnName");
  }, 500), ce = v.some((e) => e.isPrimaryKey === !0), me = async (e) => {
    var r;
    if (j !== 2 && i && ue(2), e.length === 0) {
      n.setValue("createTableQuery", "", { shouldDirty: !0 });
      return;
    }
    const t = ((r = e.find((o) => o.isPrimaryKey)) == null ? void 0 : r.name) || "", l = await $e([], e, "", t);
    n.setValue("createTableQuery", l, { shouldDirty: !0 });
  };
  return /* @__PURE__ */ s(
    p,
    {
      size: 9,
      sx: {
        maxHeight: "88vh",
        overflowY: "auto",
        overflowX: "hidden"
      },
      children: [
        /* @__PURE__ */ a(
          he,
          {
            variant: "outlined",
            sx: {
              p: 2.5,
              borderRadius: 2.5,
              backgroundColor: "background.paper"
            },
            children: /* @__PURE__ */ s("form", { onSubmit: n.handleSubmit(aa), noValidate: !0, className: "w-full", children: [
              /* @__PURE__ */ s(
                f,
                {
                  sx: {
                    display: "flex",
                    justifyContent: "space-between",
                    alignItems: "center",
                    mb: 2.5,
                    pb: 2,
                    borderBottom: "1px solid",
                    borderColor: "divider"
                  },
                  children: [
                    /* @__PURE__ */ s(f, { sx: { flex: 1 }, children: [
                      i ? /* @__PURE__ */ s(f, { sx: { maxWidth: 350 }, children: [
                        /* @__PURE__ */ a(c, { variant: "subtitle2", sx: { fontWeight: 600, mb: 0.5 }, children: "New Table" }),
                        /* @__PURE__ */ a(
                          da,
                          {
                            control: n.control,
                            id: "tableName",
                            name: "tableName",
                            errors: n.formState.errors,
                            label: "Table Name",
                            size: "small",
                            rules: {
                              required: {
                                value: !0,
                                message: "Please Enter the name"
                              },
                              pattern: {
                                value: /^[a-z0-9_]+$/,
                                message: "Only lowercase letters, numbers, and underscores are allowed"
                              },
                              validate: {}
                            }
                          }
                        )
                      ] }) : /* @__PURE__ */ s(W, { children: [
                        /* @__PURE__ */ a(c, { variant: "h6", sx: { fontWeight: 700, color: "text.primary" }, children: w || "No Table Selected" }),
                        /* @__PURE__ */ a(c, { variant: "caption", color: "text.secondary", children: w ? "View and manage table configuration" : "Select a table from the list" })
                      ] }),
                      /* @__PURE__ */ a(
                        sa,
                        {
                          description: "Do you want to drop this table?",
                          title: "CONFIRMATION",
                          open: He,
                          handleClick: ta,
                          handleClose: () => xe((e) => !e)
                        }
                      )
                    ] }),
                    /* @__PURE__ */ s(f, { sx: { display: "flex", gap: 1 }, children: [
                      (m || i) && /* @__PURE__ */ a(E, { title: ce ? "" : "A primary key is required to proceed.", arrow: !0, placement: "bottom", children: /* @__PURE__ */ a("span", { children: /* @__PURE__ */ a(
                        P,
                        {
                          type: "submit",
                          variant: "contained",
                          size: "small",
                          sx: {
                            borderRadius: 2,
                            fontWeight: 600,
                            textTransform: "none",
                            boxShadow: "none",
                            px: 2.5
                          },
                          disabled: ea || !ce,
                          startIcon: /* @__PURE__ */ a(x, { iconName: "faCheck" }),
                          children: "Submit"
                        }
                      ) }) }),
                      (m || i) && /* @__PURE__ */ a(
                        P,
                        {
                          type: "button",
                          variant: "outlined",
                          onClick: () => na(),
                          size: "small",
                          sx: {
                            borderRadius: 2,
                            fontWeight: 600,
                            textTransform: "none",
                            borderColor: "divider",
                            color: "text.secondary",
                            px: 2.5,
                            "&:hover": { backgroundColor: "action.hover", borderColor: "text.disabled" }
                          },
                          children: "Cancel"
                        }
                      )
                    ] })
                  ]
                }
              ),
              /* @__PURE__ */ s(p, { container: !0, spacing: 2, children: [
                /* @__PURE__ */ s(p, { size: 7, children: [
                  /* @__PURE__ */ a(
                    f,
                    {
                      sx: {
                        display: "inline-flex",
                        gap: 0.75,
                        p: 0.75,
                        backgroundColor: "action.hover",
                        borderRadius: 2.5,
                        border: "1px solid",
                        borderColor: "divider",
                        mb: 2
                      },
                      children: [
                        { value: 0, label: "Modified On Query", icon: "faClock" },
                        { value: 1, label: "Data Fetch Query", icon: "faDatabase" },
                        ...i ? [{ value: 2, label: "Create Table Query", icon: "faCode" }] : []
                      ].map((e) => {
                        const r = j === e.value;
                        return /* @__PURE__ */ a(
                          P,
                          {
                            onClick: () => ue(e.value),
                            size: "small",
                            disableElevation: !0,
                            sx: {
                              px: 2,
                              py: 0.6,
                              borderRadius: 2,
                              textTransform: "none",
                              fontSize: "0.8rem",
                              fontWeight: r ? 700 : 500,
                              color: r ? "primary.dark" : "text.secondary",
                              backgroundColor: r ? "background.paper" : "transparent",
                              boxShadow: r ? "0px 2px 6px rgba(0,0,0,0.06)" : "none",
                              border: "1px solid",
                              borderColor: r ? "divider" : "transparent",
                              transition: "all 0.2s ease",
                              "&:hover": {
                                backgroundColor: r ? "background.paper" : "action.hover"
                              }
                            },
                            startIcon: /* @__PURE__ */ a(x, { iconName: e.icon }),
                            children: e.label
                          },
                          e.value
                        );
                      })
                    }
                  ),
                  j === 0 && /* @__PURE__ */ s(p, { children: [
                    /* @__PURE__ */ a(c, { variant: "subtitle1", children: "Modified On Query:" }),
                    /* @__PURE__ */ a(
                      T,
                      {
                        name: "modifiedOnQuery",
                        control: n.control,
                        render: ({ field: e, fieldState: { error: r } }) => /* @__PURE__ */ s(W, { children: [
                          /* @__PURE__ */ a(
                            ie,
                            {
                              height: "35vh",
                              defaultLanguage: "sql",
                              theme: "vs-dark",
                              options: {
                                fontSize: 12,
                                minimap: { enabled: !1 },
                                automaticLayout: !0,
                                scrollBeyondLastLine: !1,
                                wordWrap: "on",
                                occurrencesHighlight: !1,
                                selectionHighlight: !1,
                                readOnly: !m && !i
                              },
                              value: e.value || "",
                              defaultValue: e.value || "",
                              onChange: e.onChange,
                              editorProps: { $blockScrolling: !0 }
                            }
                          ),
                          (r == null ? void 0 : r.message) && /* @__PURE__ */ a(c, { variant: "subtitle1", color: "error", fontSize: "13px", className: "mt-1 ml-[13px]", children: r.message })
                        ] })
                      }
                    )
                  ] }),
                  j === 1 && /* @__PURE__ */ s(p, { children: [
                    /* @__PURE__ */ a(c, { variant: "subtitle1", children: "Data Fetch Query:" }),
                    /* @__PURE__ */ a(
                      T,
                      {
                        name: "dataFetchQuery",
                        control: n.control,
                        render: ({ field: e, fieldState: { error: r } }) => /* @__PURE__ */ s(W, { children: [
                          /* @__PURE__ */ a(
                            ie,
                            {
                              height: "35vh",
                              defaultLanguage: "sql",
                              theme: "vs-dark",
                              options: {
                                fontSize: 12,
                                minimap: { enabled: !1 },
                                automaticLayout: !0,
                                scrollBeyondLastLine: !1,
                                wordWrap: "on",
                                occurrencesHighlight: !1,
                                selectionHighlight: !1,
                                readOnly: !m && !i
                              },
                              value: e.value || "",
                              defaultValue: e.value || "",
                              onChange: e.onChange,
                              editorProps: { $blockScrolling: !0 }
                            }
                          ),
                          (r == null ? void 0 : r.message) && /* @__PURE__ */ a(c, { variant: "subtitle1", color: "error", fontSize: "13px", className: "mt-1 ml-[13px]", children: r.message })
                        ] })
                      }
                    )
                  ] }),
                  j === 2 && /* @__PURE__ */ s(p, { children: [
                    /* @__PURE__ */ a(c, { variant: "subtitle1", children: "Create Table Query:" }),
                    /* @__PURE__ */ a(
                      T,
                      {
                        name: "createTableQuery",
                        control: n.control,
                        render: ({ field: e, fieldState: { error: r } }) => /* @__PURE__ */ s(W, { children: [
                          /* @__PURE__ */ a(
                            ie,
                            {
                              height: "35vh",
                              defaultLanguage: "sql",
                              theme: "vs-dark",
                              options: {
                                fontSize: 12,
                                minimap: { enabled: !1 },
                                automaticLayout: !0,
                                scrollBeyondLastLine: !1,
                                wordWrap: "on",
                                occurrencesHighlight: !1,
                                selectionHighlight: !1,
                                readOnly: !0
                              },
                              value: e.value || "",
                              defaultValue: e.value || "",
                              onChange: e.onChange,
                              editorProps: { $blockScrolling: !0 }
                            }
                          ),
                          (r == null ? void 0 : r.message) && /* @__PURE__ */ a(c, { variant: "subtitle1", color: "error", fontSize: "13px", className: "mt-1 ml-[13px]", children: r.message })
                        ] })
                      }
                    )
                  ] }),
                  /* @__PURE__ */ s(he, { variant: "outlined", sx: { p: 2, mt: 2, borderRadius: 2, backgroundColor: "action.hover" }, children: [
                    /* @__PURE__ */ a(c, { variant: "subtitle2", sx: { fontWeight: 700, mb: 1.5, color: "text.primary" }, children: "Table Settings" }),
                    /* @__PURE__ */ s(p, { container: !0, spacing: 2, children: [
                      /* @__PURE__ */ s(p, { size: 6, xs: 12, children: [
                        /* @__PURE__ */ s(c, { variant: "body2", sx: { fontWeight: 600, mb: 0.5 }, children: [
                          "Data Scope ",
                          /* @__PURE__ */ a("span", { style: { color: "#ef4444" }, children: "*" })
                        ] }),
                        /* @__PURE__ */ a(Y, { children: /* @__PURE__ */ a(
                          T,
                          {
                            name: "userData",
                            control: n.control,
                            rules: { required: "Required field." },
                            disabled: !m && !i,
                            defaultValue: d.userData !== void 0 && d.userData !== null ? String(d.userData) : "",
                            render: ({ field: e }) => /* @__PURE__ */ s(pe, { row: !0, ...e, value: e.value, children: [
                              /* @__PURE__ */ a(
                                L,
                                {
                                  value: "true",
                                  control: /* @__PURE__ */ a(B, { disabled: !m && !i, size: "small" }),
                                  label: /* @__PURE__ */ a(c, { variant: "body2", children: "User" })
                                }
                              ),
                              /* @__PURE__ */ a(
                                L,
                                {
                                  value: "false",
                                  control: /* @__PURE__ */ a(B, { disabled: !m && !i, size: "small" }),
                                  label: /* @__PURE__ */ a(c, { variant: "body2", children: "System" })
                                }
                              )
                            ] })
                          }
                        ) })
                      ] }),
                      /* @__PURE__ */ s(p, { size: 6, xs: 12, children: [
                        /* @__PURE__ */ s(c, { variant: "body2", sx: { fontWeight: 600, mb: 0.5 }, children: [
                          "Sync by Default ",
                          /* @__PURE__ */ a("span", { style: { color: "#ef4444" }, children: "*" })
                        ] }),
                        /* @__PURE__ */ a(Y, { children: /* @__PURE__ */ a(
                          T,
                          {
                            name: "syncByDefault",
                            id: "syncByDefault",
                            control: n.control,
                            rules: { required: "Required field." },
                            disabled: !m && !i,
                            defaultValue: d.syncByDefault !== void 0 && d.syncByDefault !== null ? String(d.syncByDefault) : "",
                            render: ({ field: e }) => /* @__PURE__ */ s(pe, { row: !0, ...e, value: e.value, children: [
                              /* @__PURE__ */ a(
                                L,
                                {
                                  value: "true",
                                  control: /* @__PURE__ */ a(B, { disabled: !m && !i, size: "small" }),
                                  label: /* @__PURE__ */ a(c, { variant: "body2", children: "Yes" })
                                }
                              ),
                              /* @__PURE__ */ a(
                                L,
                                {
                                  value: "false",
                                  control: /* @__PURE__ */ a(B, { disabled: !m && !i, size: "small" }),
                                  label: /* @__PURE__ */ a(c, { variant: "body2", children: "No" })
                                }
                              )
                            ] })
                          }
                        ) })
                      ] }),
                      /* @__PURE__ */ s(p, { size: 6, xs: 12, children: [
                        /* @__PURE__ */ s(c, { variant: "body2", sx: { fontWeight: 600, mb: 0.5 }, children: [
                          "Has Media ",
                          /* @__PURE__ */ a("span", { style: { color: "#ef4444" }, children: "*" })
                        ] }),
                        /* @__PURE__ */ a(Y, { children: /* @__PURE__ */ a(
                          T,
                          {
                            name: "hasMedia",
                            id: "hasMedia",
                            control: n.control,
                            rules: { required: "Required field." },
                            disabled: !m && !i,
                            defaultValue: d.hasMedia !== void 0 && d.hasMedia !== null ? String(d.hasMedia) : "",
                            render: ({ field: e }) => /* @__PURE__ */ s(pe, { row: !0, ...e, value: e.value, children: [
                              /* @__PURE__ */ a(
                                L,
                                {
                                  value: "true",
                                  control: /* @__PURE__ */ a(B, { disabled: !m && !i, size: "small" }),
                                  label: /* @__PURE__ */ a(c, { variant: "body2", children: "Yes" })
                                }
                              ),
                              /* @__PURE__ */ a(
                                L,
                                {
                                  value: "false",
                                  control: /* @__PURE__ */ a(B, { disabled: !m && !i, size: "small" }),
                                  label: /* @__PURE__ */ a(c, { variant: "body2", children: "No" })
                                }
                              )
                            ] })
                          }
                        ) })
                      ] })
                    ] })
                  ] }),
                  A === "true" && /* @__PURE__ */ s(W, { children: [
                    /* @__PURE__ */ a(c, { variant: "h6", className: "mt-2", sx: { fontWeight: 600, color: "#566A79" }, children: "Media Configuration:" }),
                    /* @__PURE__ */ s(p, { container: !0, spacing: 2, className: "mt-2", children: [
                      /* @__PURE__ */ s(p, { size: 6, xs: 12, children: [
                        /* @__PURE__ */ s(c, { variant: "subtitle2", sx: { mb: 0.5, fontWeight: 600 }, children: [
                          "Download Type",
                          /* @__PURE__ */ a("span", { style: { color: "red" }, children: "*" }),
                          ":"
                        ] }),
                        /* @__PURE__ */ a(
                          T,
                          {
                            name: "downloadType",
                            control: n.control,
                            rules: {
                              validate: (e) => A !== "true" || !!e || "Download Type is required."
                            },
                            render: ({ field: { onChange: e, value: r }, fieldState: { error: t } }) => /* @__PURE__ */ a(
                              se,
                              {
                                options: Ie,
                                value: r || null,
                                disabled: !m && !i,
                                onChange: (l, o) => e(o),
                                renderInput: (l) => /* @__PURE__ */ a(
                                  V,
                                  {
                                    ...l,
                                    size: "small",
                                    placeholder: "Select download type",
                                    error: !!t,
                                    helperText: t == null ? void 0 : t.message
                                  }
                                )
                              }
                            )
                          }
                        )
                      ] }),
                      /* @__PURE__ */ a(p, { size: 12, children: /* @__PURE__ */ s(
                        f,
                        {
                          sx: {
                            border: "1px solid #ddd",
                            borderRadius: "8px",
                            p: 2,
                            backgroundColor: "#fafafa"
                          },
                          children: [
                            /* @__PURE__ */ a(c, { variant: "subtitle1", sx: { fontWeight: 600, mb: 1.5, color: "#374151" }, children: "Download URL" }),
                            /* @__PURE__ */ s(c, { variant: "subtitle2", sx: { mb: 0.5, fontWeight: 600 }, children: [
                              "API Endpoint",
                              /* @__PURE__ */ a("span", { style: { color: "red" }, children: "*" }),
                              ":"
                            ] }),
                            /* @__PURE__ */ a(
                              T,
                              {
                                name: "apiEndpoint",
                                control: n.control,
                                rules: {
                                  validate: (e) => A !== "true" || !!(e != null && e.trim()) || "API Endpoint is required."
                                },
                                render: ({ field: e, fieldState: { error: r } }) => /* @__PURE__ */ a(
                                  V,
                                  {
                                    ...e,
                                    value: e.value || "",
                                    size: "small",
                                    variant: "outlined",
                                    fullWidth: !0,
                                    placeholder: "https://api.example.com/endpoint",
                                    error: !!r,
                                    helperText: r == null ? void 0 : r.message,
                                    slotProps: { input: { readOnly: !m && !i } },
                                    sx: { mb: 2 }
                                  }
                                )
                              }
                            ),
                            /* @__PURE__ */ s(f, { sx: { display: "flex", alignItems: "center", mb: 1 }, children: [
                              /* @__PURE__ */ s(c, { variant: "subtitle2", sx: { fontWeight: 600, color: "#374151", flex: 1 }, children: [
                                "Request Parameters",
                                /* @__PURE__ */ a("span", { style: { color: "red" }, children: "*" }),
                                ":"
                              ] }),
                              (m || i) && /* @__PURE__ */ a(E, { title: "Add parameter", arrow: !0, children: /* @__PURE__ */ a(
                                O,
                                {
                                  size: "small",
                                  onClick: () => {
                                    const e = [...K, { key: "", value: "" }];
                                    z(e), n.setValue("requestParameters", e, {
                                      shouldDirty: !0,
                                      shouldValidate: !0
                                    });
                                  },
                                  sx: {
                                    backgroundColor: "#566A79",
                                    color: "white",
                                    "&:hover": { backgroundColor: "#3d4f5c" },
                                    borderRadius: "6px",
                                    width: "28px",
                                    height: "28px"
                                  },
                                  children: /* @__PURE__ */ a(x, { iconName: "faPlus", className: "text-[0.75rem]" })
                                }
                              ) })
                            ] }),
                            K.length === 0 && /* @__PURE__ */ a(c, { variant: "caption", sx: { color: "#9ca3af", fontStyle: "italic" }, children: "No request parameters added." }),
                            K.map((e, r) => /* @__PURE__ */ s(
                              f,
                              {
                                sx: {
                                  display: "flex",
                                  gap: 1,
                                  alignItems: "flex-start",
                                  mb: 1,
                                  p: 1,
                                  borderRadius: "6px",
                                  backgroundColor: "#f0f4f8",
                                  border: "1px solid #e2e8f0"
                                },
                                children: [
                                  /* @__PURE__ */ a(
                                    V,
                                    {
                                      size: "small",
                                      label: "Key",
                                      value: e.key,
                                      placeholder: "parameterKey",
                                      disabled: !m && !i,
                                      onChange: (t) => {
                                        const l = K.map(
                                          (o, u) => u === r ? { ...o, key: t.target.value } : o
                                        );
                                        z(l), n.setValue("requestParameters", l, {
                                          shouldDirty: !0,
                                          shouldValidate: !0
                                        });
                                      },
                                      sx: { flex: 1 }
                                    }
                                  ),
                                  /* @__PURE__ */ a(
                                    se,
                                    {
                                      size: "small",
                                      options: v.map((t) => t.name),
                                      value: e.value || null,
                                      disabled: !m && !i,
                                      noOptionsText: v.length === 0 ? "No synced columns yet" : "No match",
                                      onChange: (t, l) => {
                                        const o = K.map(
                                          (u, h) => h === r ? { ...u, value: l || "" } : u
                                        );
                                        z(o), n.setValue("requestParameters", o, {
                                          shouldDirty: !0,
                                          shouldValidate: !0
                                        });
                                      },
                                      renderInput: (t) => /* @__PURE__ */ a(V, { ...t, label: "Value (Column)", placeholder: "Select column" }),
                                      sx: { flex: 1 }
                                    }
                                  ),
                                  (m || i) && /* @__PURE__ */ a(E, { title: "Remove parameter", arrow: !0, children: /* @__PURE__ */ a(
                                    O,
                                    {
                                      size: "small",
                                      onClick: () => {
                                        const t = K.filter((l, o) => o !== r);
                                        z(t), n.setValue("requestParameters", t, {
                                          shouldDirty: !0,
                                          shouldValidate: !0
                                        });
                                      },
                                      sx: { color: "#ef4444", alignSelf: "center" },
                                      children: /* @__PURE__ */ a(x, { iconName: "faTrashCan", className: "text-[0.85rem]" })
                                    }
                                  ) })
                                ]
                              },
                              r
                            )),
                            n.formState.errors.requestParameters && /* @__PURE__ */ a(c, { variant: "caption", sx: { color: "#ef4444", mt: 0.5, display: "block" }, children: n.formState.errors.requestParameters.message })
                          ]
                        }
                      ) }),
                      /* @__PURE__ */ s(p, { size: 6, xs: 12, children: [
                        /* @__PURE__ */ s(c, { variant: "subtitle2", sx: { mb: 0.5, fontWeight: 600 }, children: [
                          "Directory Path",
                          /* @__PURE__ */ a("span", { style: { color: "red" }, children: "*" }),
                          ":"
                        ] }),
                        /* @__PURE__ */ a(
                          T,
                          {
                            name: "directoryPath",
                            control: n.control,
                            defaultValue: "",
                            rules: {
                              validate: (e) => A !== "true" || !!(e != null && e.trim()) && e.trim().length > 0 || "Directory Path is required."
                            },
                            render: ({ field: e, fieldState: { error: r } }) => /* @__PURE__ */ a(
                              V,
                              {
                                ...e,
                                size: "small",
                                variant: "outlined",
                                fullWidth: !0,
                                error: !!r,
                                helperText: r == null ? void 0 : r.message,
                                slotProps: {
                                  input: {
                                    readOnly: !m && !i,
                                    startAdornment: /* @__PURE__ */ a(ye, { position: "start", children: "#directoryPath#/" }),
                                    endAdornment: /* @__PURE__ */ a(ye, { position: "end", children: "/" })
                                  }
                                }
                              }
                            )
                          }
                        )
                      ] })
                    ] })
                  ] })
                ] }),
                /* @__PURE__ */ a(p, { size: 5, children: /* @__PURE__ */ s(he, { variant: "outlined", sx: { px: 2, borderRadius: 2.5, height: "100%", mb: 1 }, children: [
                  /* @__PURE__ */ s(
                    f,
                    {
                      sx: {
                        display: "flex",
                        justifyContent: "space-between",
                        alignItems: "center",
                        flexWrap: "wrap",
                        gap: 1,
                        pt: 1.5
                      },
                      children: [
                        /* @__PURE__ */ s(
                          f,
                          {
                            sx: {
                              display: "inline-flex",
                              gap: 0.5,
                              p: 0.5,
                              backgroundColor: "action.hover",
                              borderRadius: 2,
                              border: "1px solid",
                              borderColor: "divider",
                              mb: 1
                            },
                            children: [
                              !i && /* @__PURE__ */ a(
                                P,
                                {
                                  size: "small",
                                  onClick: () => {
                                    re(0), F("");
                                  },
                                  sx: {
                                    px: 1.5,
                                    py: 0.4,
                                    borderRadius: 1.5,
                                    textTransform: "none",
                                    fontSize: "0.78rem",
                                    fontWeight: g === 0 ? 700 : 500,
                                    color: g === 0 ? "primary.dark" : "text.secondary",
                                    backgroundColor: g === 0 ? "background.paper" : "transparent",
                                    boxShadow: g === 0 ? "0px 1px 4px rgba(0,0,0,0.06)" : "none",
                                    border: "1px solid",
                                    borderColor: g === 0 ? "divider" : "transparent",
                                    "&:hover": { backgroundColor: g === 0 ? "background.paper" : "action.hover" }
                                  },
                                  children: "Synced Columns"
                                }
                              ),
                              S !== void 0 && /* @__PURE__ */ a(
                                P,
                                {
                                  size: "small",
                                  onClick: () => {
                                    re(1), F("");
                                  },
                                  sx: {
                                    px: 1.5,
                                    py: 0.4,
                                    borderRadius: 1.5,
                                    textTransform: "none",
                                    fontSize: "0.78rem",
                                    fontWeight: g === 1 ? 700 : 500,
                                    color: g === 1 ? "primary.dark" : "text.secondary",
                                    backgroundColor: g === 1 ? "background.paper" : "transparent",
                                    boxShadow: g === 1 ? "0px 1px 4px rgba(0,0,0,0.06)" : "none",
                                    border: "1px solid",
                                    borderColor: g === 1 ? "divider" : "transparent",
                                    "&:hover": { backgroundColor: g === 1 ? "background.paper" : "action.hover" }
                                  },
                                  children: i ? "Columns" : "DB Columns"
                                }
                              )
                            ]
                          }
                        ),
                        g === 0 && v.length > 0 && $ && /* @__PURE__ */ a(f, { sx: { minWidth: 200, marginLeft: 2 }, children: /* @__PURE__ */ a(
                          se,
                          {
                            size: "small",
                            options: v.map((e) => e.name),
                            value: n.getValues("primaryKey") || "",
                            readOnly: !m && !i,
                            onChange: (e, r) => {
                              const t = v.map((l) => ({
                                ...l,
                                isPrimaryKey: l.name === r
                              }));
                              D(t), n.setValue("selectedColumns", t, { shouldDirty: !0 }), n.setValue("primaryKey", r);
                            },
                            renderInput: (e) => /* @__PURE__ */ a(V, { ...e, label: "Primary Key", placeholder: "Select column" }),
                            renderOption: (e, r) => /* @__PURE__ */ a("li", { ...e, children: /* @__PURE__ */ a(E, { title: r, placement: "left", arrow: !0, children: /* @__PURE__ */ a("span", { className: "truncate max-w-[250px]", children: r }) }) })
                          }
                        ) }),
                        (i || m) && /* @__PURE__ */ a(
                          P,
                          {
                            id: "edit-button-anchor",
                            size: "small",
                            variant: "contained",
                            sx: {
                              borderRadius: 2,
                              fontWeight: 600,
                              textTransform: "none",
                              boxShadow: "none",
                              px: 1.5,
                              ml: 1
                            },
                            disabled: !!n.formState.errors.tableName,
                            onClick: async (e) => {
                              const r = e.currentTarget;
                              await n.trigger("tableName") && (ne(null), le(r));
                            },
                            startIcon: /* @__PURE__ */ a(x, { iconName: "faPlus" }),
                            children: "Column"
                          }
                        ),
                        (i || m) && /* @__PURE__ */ a(
                          ua,
                          {
                            id: Ze,
                            open: Le,
                            anchorEl: Ee,
                            onClose: async () => {
                              le(null), n.setValue("newColumnName", ""), n.setValue("newColumnType", null), n.setValue("isPrimaryKey", !1), n.clearErrors(["newColumnName", "newColumnType"]), ne(null);
                            },
                            anchorOrigin: {
                              vertical: "bottom",
                              horizontal: "left"
                            },
                            children: /* @__PURE__ */ s(
                              p,
                              {
                                container: !0,
                                spacing: 1,
                                sx: {
                                  p: 1,
                                  width: "200px",
                                  height: (De = n.getValues("selectedColumns")) != null && De.some((e) => e.isPrimaryKey) ? "180px" : "210px"
                                },
                                children: [
                                  /* @__PURE__ */ a(p, { size: 12, className: "h-fit", children: /* @__PURE__ */ a(Y, { fullWidth: !0, children: /* @__PURE__ */ a(
                                    T,
                                    {
                                      name: "newColumnName",
                                      id: "newColumnName",
                                      control: n.control,
                                      render: ({ field: { onChange: e, value: r, ...t }, fieldState: { error: l } }) => /* @__PURE__ */ a(
                                        V,
                                        {
                                          ...t,
                                          value: (r == null ? void 0 : r.trim()) || "",
                                          variant: "outlined",
                                          fullWidth: !0,
                                          size: "small",
                                          error: !!l,
                                          helperText: l == null ? void 0 : l.message,
                                          label: "Column Name",
                                          sx: {
                                            "& .MuiInputLabel-root": {
                                              fontSize: "0.9rem"
                                            },
                                            margin: 0
                                          },
                                          onChange: (o) => {
                                            e(o.target.value), oa(o.target.value);
                                          }
                                        }
                                      )
                                    }
                                  ) }) }),
                                  /* @__PURE__ */ a(p, { size: 12, className: "h-fit", children: /* @__PURE__ */ a(Y, { fullWidth: !0, children: /* @__PURE__ */ a(
                                    T,
                                    {
                                      name: "newColumnType",
                                      id: "newColumnType",
                                      control: n.control,
                                      render: ({ field: { onChange: e, value: r }, fieldState: { error: t } }) => /* @__PURE__ */ a(
                                        se,
                                        {
                                          options: Oe || [],
                                          value: (r == null ? void 0 : r.trim()) || null,
                                          getOptionLabel: (l) => l,
                                          onChange: (l, o) => {
                                            e(o);
                                          },
                                          renderInput: (l) => /* @__PURE__ */ a(
                                            V,
                                            {
                                              ...l,
                                              size: "small",
                                              error: !!t,
                                              helperText: t == null ? void 0 : t.message,
                                              sx: {
                                                "& .MuiInputLabel-root": {
                                                  fontSize: "0.9rem"
                                                },
                                                m: 0
                                              },
                                              label: "Column Type",
                                              onChange: (o) => {
                                                e(o.target.value), n.setValue("newColumnType", o.target.value, {
                                                  shouldDirty: !0
                                                });
                                              }
                                            }
                                          )
                                        }
                                      )
                                    }
                                  ) }) }),
                                  H === null && !n.getValues("selectedColumns").some((e) => e.isPrimaryKey) && /* @__PURE__ */ a(p, { size: 12, className: "h-fit", children: /* @__PURE__ */ a(
                                    L,
                                    {
                                      control: /* @__PURE__ */ a(
                                        T,
                                        {
                                          name: "isPrimaryKey",
                                          control: n.control,
                                          render: ({ field: { onChange: e, value: r } }) => /* @__PURE__ */ a(
                                            ca,
                                            {
                                              checked: r || !1,
                                              onChange: (t) => e(t.target.checked),
                                              sx: {
                                                margin: "0px"
                                              }
                                            }
                                          )
                                        }
                                      ),
                                      label: "Primary Key"
                                    }
                                  ) }),
                                  /* @__PURE__ */ a(p, { children: /* @__PURE__ */ a(
                                    P,
                                    {
                                      size: "small",
                                      variant: "contained",
                                      disabled: !Ae || !We || Ae.trim() === "" || !Oe.includes(We.trim()),
                                      onClick: async () => {
                                        const e = n.getValues("isPrimaryKey"), r = n.getValues("newColumnName"), t = n.getValues("newColumnType"), l = n.getValues("selectedColumns").some((h) => h.isPrimaryKey);
                                        let o = [...n.getValues("selectedColumns")];
                                        if (H !== null)
                                          o[H] = {
                                            ...o[H],
                                            name: r,
                                            type: t
                                          };
                                        else {
                                          if (o.some((y) => y.name === r)) {
                                            R({ message: "Column already exists", type: "error" });
                                            return;
                                          }
                                          const h = {
                                            name: r,
                                            type: t
                                          };
                                          !l && e && (n.setValue("primaryKey", r), h.isPrimaryKey = !0), o.push(h);
                                        }
                                        n.setValue("selectedColumns", o, {
                                          shouldDirty: !0
                                        });
                                        const u = [...o].sort((h, y) => h.isPrimaryKey ? -1 : y.isPrimaryKey ? 1 : h.name.localeCompare(y.name));
                                        D(u), i && await me(o), ne(null), le(null), g !== 0 && re(0), n.setValue("newColumnName", " "), n.setValue("newColumnType", " "), n.setValue("isPrimaryKey", null);
                                      },
                                      children: H !== null ? "Update" : "Add"
                                    }
                                  ) })
                                ]
                              }
                            )
                          }
                        )
                      ]
                    }
                  ),
                  /* @__PURE__ */ a(
                    ma,
                    {
                      sx: {
                        maxHeight: A === "true" ? "112vh" : "59vh",
                        border: "1px solid",
                        borderColor: "divider",
                        borderRadius: 2
                      },
                      children: /* @__PURE__ */ s(ha, { stickyHeader: !0, children: [
                        /* @__PURE__ */ a(pa, { children: /* @__PURE__ */ a(J, { children: /* @__PURE__ */ s(X, { className: " px-3 ", sx: { backgroundColor: "white" }, children: [
                          /* @__PURE__ */ a(
                            V,
                            {
                              size: "small",
                              placeholder: "Search Columns",
                              variant: "outlined",
                              value: ae,
                              onChange: (e) => {
                                F(e.target.value);
                              },
                              className: "w-full py-0.5 text-xs",
                              InputProps: {
                                startAdornment: /* @__PURE__ */ a(ye, { position: "start", children: /* @__PURE__ */ a(O, { children: /* @__PURE__ */ a(x, { iconName: "faMagnifyingGlass", className: "text-[1rem]" }) }) })
                              }
                            }
                          ),
                          !ce && /* @__PURE__ */ s(c, { variant: "body2", color: "info", className: "mb-0", children: [
                            /* @__PURE__ */ a("span", { style: { color: "red" }, children: "*" }),
                            " Select a primary key for the table before submitting."
                          ] })
                        ] }) }) }),
                        g === 0 && /* @__PURE__ */ a(_e, { children: v.length ? v.map((e, r) => /* @__PURE__ */ a(
                          J,
                          {
                            className: `border-b ${r === v.length - 1 ? "border-none" : "border-[#ccc]"}`,
                            sx: {
                              backgroundColor: e.onlyMobileDb ? "#d3ecc7" : e.isTypeChanged ? "rgba(255, 0, 0, 0.1)" : "#fff",
                              "&:hover": {
                                backgroundColor: e.onlyMobileDb ? "#d2f7c0" : e.isTypeChanged ? "#e79a9a" : "#e9f3ff"
                              }
                            },
                            children: /* @__PURE__ */ s(X, { className: "p-2 px-4 flex justify-between", children: [
                              /* @__PURE__ */ a(
                                E,
                                {
                                  title: e.onlyMobileDb ? "Column only present in mobile database" : e.isTypeChanged ? "Type changed" : "",
                                  placement: "top",
                                  arrow: !0,
                                  disableHoverListener: !(e.onlyMobileDb || e.isTypeChanged),
                                  children: /* @__PURE__ */ s(c, { variant: "caption", className: "w-full text-ellipsis cursor-pointer", children: [
                                    e.name,
                                    " (",
                                    e.type,
                                    ")"
                                  ] })
                                }
                              ),
                              /* @__PURE__ */ s(f, { display: "flex", alignItems: "center", children: [
                                e.isPrimaryKey && /* @__PURE__ */ a(O, { sx: { height: "1.5rem", marginRight: 0, paddingRight: 1 }, children: /* @__PURE__ */ a(x, { iconName: "faKey", className: "text-[1rem] text-[#d3bb51]" }) }),
                                (i || m) && /* @__PURE__ */ s(W, { children: [
                                  /* @__PURE__ */ s(
                                    E,
                                    {
                                      title: !i && e.isPrimaryKey && !$ ? "Deletion of primary key is not allowed." : "",
                                      arrow: !0,
                                      placement: "left",
                                      children: [
                                        " ",
                                        /* @__PURE__ */ a("span", { children: /* @__PURE__ */ a(
                                          O,
                                          {
                                            sx: { height: "1.3rem", marginRight: "0" },
                                            disabled: !i && e.isPrimaryKey && !$,
                                            onClick: async () => {
                                              const t = n.getValues("selectedColumns");
                                              F("");
                                              const l = t.filter((h) => h.name !== e.name);
                                              n.setValue("selectedColumns", l, { shouldDirty: !0 });
                                              const o = ae.trim().toLowerCase(), u = o ? l.filter((h) => h.name.toLowerCase().includes(o)) : l;
                                              D(u), q(
                                                (h) => h.map((y) => y.name === e.name ? { ...y, isSynced: !1 } : y)
                                              ), e.isPrimaryKey && n.setValue("primaryKey", ""), i && await me(l);
                                            },
                                            children: /* @__PURE__ */ a(
                                              x,
                                              {
                                                iconName: "faTrashCan",
                                                className: "text-[1rem] text-[#df5f5f]"
                                              }
                                            )
                                          }
                                        ) })
                                      ]
                                    }
                                  ),
                                  i && /* @__PURE__ */ a(
                                    O,
                                    {
                                      sx: { height: "1.3rem", marginRight: "0", color: "success" },
                                      onClick: () => {
                                        const t = n.getValues("selectedColumns").findIndex((l) => l.name === e.name);
                                        ne(t), n.setValue("newColumnName", e.name), n.setValue("newColumnType", e.type), le(document.getElementById("edit-button-anchor") ?? null);
                                      },
                                      children: /* @__PURE__ */ a(x, { iconName: "faPen", className: "text-[1rem] text-[#4f4f4f]" })
                                    }
                                  )
                                ] })
                              ] })
                            ] })
                          },
                          r + 1
                        )) : /* @__PURE__ */ a(J, { children: /* @__PURE__ */ a(X, { colSpan: 1, className: "p-2", children: /* @__PURE__ */ s(c, { variant: "body2", children: [
                          " ",
                          n.getValues("selectedColumns").length === 0 ? "There are no columns to display." : v.length === 0 ? "No columns for search query." : null
                        ] }) }) }) }),
                        g === 1 && /* @__PURE__ */ a(_e, { children: _.length ? _.map((e, r) => {
                          const t = e.name === d.primaryKey, l = e.isSynced || !1, o = /* @__PURE__ */ a(
                            fa,
                            {
                              icon: /* @__PURE__ */ a(
                                f,
                                {
                                  sx: {
                                    backgroundColor: "#001e3c",
                                    borderRadius: "50%",
                                    width: 20,
                                    height: 20,
                                    display: "flex",
                                    alignItems: "center",
                                    justifyContent: "center"
                                  },
                                  children: /* @__PURE__ */ a(x, { iconName: "faBan", size: "sm", className: "pr-[0.4px]" })
                                }
                              ),
                              checkedIcon: /* @__PURE__ */ a(
                                f,
                                {
                                  sx: {
                                    backgroundColor: "#4caf50",
                                    borderRadius: "50%",
                                    width: 20,
                                    height: 20,
                                    display: "flex",
                                    alignItems: "center",
                                    justifyContent: "center"
                                  },
                                  children: /* @__PURE__ */ a(x, { iconName: "faRotate", className: "text-white text-xs" })
                                }
                              ),
                              checked: l,
                              disabled: !m,
                              onChange: (h) => {
                                const y = h.target.checked;
                                if (!y && m && !$ && !i && e.name === d.primaryKey)
                                  return;
                                const M = [..._], U = {
                                  ...M[r],
                                  isSynced: h.target.checked
                                };
                                M[r] = U, q(M);
                                const k = [...v];
                                if (y) {
                                  const b = v.some((G) => G.isPrimaryKey);
                                  e.name === d.primaryKey && !b ? (k.push({ ...U, isPrimaryKey: !0 }), n.setValue("primaryKey", e.name)) : k.push(U);
                                } else {
                                  const b = k.findIndex((G) => G.name === M[r].name);
                                  if (b > -1) {
                                    const G = k[b].isPrimaryKey;
                                    k.splice(b, 1), G && n.setValue("primaryKey", "");
                                  }
                                }
                                D(k), n.setValue("selectedColumns", k, { shouldDirty: !0 });
                              }
                            }
                          ), u = /* @__PURE__ */ a(
                            O,
                            {
                              sx: {
                                height: "2rem",
                                marginRight: m ? 1 : 0,
                                paddingRight: m ? 1 : 0
                              },
                              children: /* @__PURE__ */ a(x, { iconName: "faKey", className: "text-lg text-[#d3bb51]" })
                            }
                          );
                          return /* @__PURE__ */ a(
                            J,
                            {
                              className: `border-b ${r === _.length - 1 ? "border-none" : "border-[#ccc]"}`,
                              sx: { "&:hover": { backgroundColor: "#e9f3ff" } },
                              children: /* @__PURE__ */ s(
                                X,
                                {
                                  sx: {
                                    p: 0,
                                    px: 2,
                                    display: "flex",
                                    justifyContent: "space-between",
                                    alignItems: "center"
                                  },
                                  children: [
                                    /* @__PURE__ */ s(
                                      c,
                                      {
                                        variant: "caption",
                                        className: "w-full text-ellipsis cursor-pointer align-content-center",
                                        children: [
                                          e.name,
                                          " (",
                                          e.type,
                                          ")"
                                        ]
                                      }
                                    ),
                                    m ? t ? i ? u : /* @__PURE__ */ s(f, { sx: { display: "flex", alignItems: "center" }, children: [
                                      u,
                                      /* @__PURE__ */ a(
                                        E,
                                        {
                                          title: m && !$ && e.name === d.primaryKey ? "Primary key cannot be unsynced in edit mode." : "",
                                          arrow: !0,
                                          placement: "top",
                                          children: /* @__PURE__ */ a("span", { children: o })
                                        }
                                      )
                                    ] }) : o : l ? /* @__PURE__ */ a(
                                      f,
                                      {
                                        sx: {
                                          backgroundColor: "#4caf50",
                                          borderRadius: "50%",
                                          width: 20,
                                          height: 20,
                                          display: "flex",
                                          alignItems: "center",
                                          justifyContent: "center",
                                          margin: "9px 0px"
                                        },
                                        children: /* @__PURE__ */ a(x, { iconName: "faRotate", className: "text-white text-xs" })
                                      }
                                    ) : t ? u : /* @__PURE__ */ a(
                                      f,
                                      {
                                        sx: {
                                          backgroundColor: "#001e3c",
                                          borderRadius: "50%",
                                          width: 20,
                                          height: 20,
                                          display: "flex",
                                          alignItems: "center",
                                          justifyContent: "center",
                                          margin: "9px 0px"
                                        },
                                        children: /* @__PURE__ */ a(x, { iconName: "faBan", className: "text-white pl-[0.5px]" })
                                      }
                                    )
                                  ]
                                }
                              )
                            },
                            r + 1
                          );
                        }) : /* @__PURE__ */ a(J, { children: /* @__PURE__ */ a(X, { colSpan: 1, className: "p-2", children: /* @__PURE__ */ a(c, { variant: "body2", children: "No columns for search query." }) }) }) })
                      ] })
                    }
                  )
                ] }) })
              ] })
            ] })
          }
        ),
        Re && /* @__PURE__ */ a(ya, { open: Re, onClose: ra, children: /* @__PURE__ */ s(f, { sx: { ...Ca }, children: [
          /* @__PURE__ */ s(f, { sx: { display: "flex", justifyContent: "space-between", alignItems: "center", mb: 2 }, children: [
            /* @__PURE__ */ a(c, { variant: "h6", children: "Generated Migration Script" }),
            /* @__PURE__ */ s(c, { variant: "body2", children: [
              "From : ",
              /* @__PURE__ */ s("strong", { children: [
                "v",
                te == null ? void 0 : te.from_version
              ] }),
              " ",
              /* @__PURE__ */ a(x, { iconName: "faArrowRight", size: "sm", className: "m-[0.3rem 0.3rem 0 0.3rem]" }),
              " To :",
              " ",
              /* @__PURE__ */ s("strong", { children: [
                "v",
                te == null ? void 0 : te.to_version
              ] })
            ] })
          ] }),
          /* @__PURE__ */ a(
            ie,
            {
              height: "50vh",
              defaultLanguage: "sql",
              theme: "light",
              options: {
                fontSize: 12,
                minimap: { enabled: !0 },
                automaticLayout: !0,
                scrollBeyondLastLine: !1,
                wordWrap: "on",
                occurrencesHighlight: !1,
                selectionHighlight: !1
              },
              value: Q || "",
              defaultValue: Q || "",
              onChange: la,
              editorProps: { $blockScrolling: !0 }
            }
          ),
          /* @__PURE__ */ a(P, { variant: "contained", color: "primary", className: "mt-2", onClick: () => Be(null, !0), children: "OK" })
        ] }) })
      ]
    }
  );
}
const Ca = {
  position: "absolute",
  top: "50%",
  left: "50%",
  transform: "translate(-50%, -50%)",
  width: "50%",
  height: "70%",
  bgcolor: "background.paper",
  boxShadow: 24,
  padding: "15px",
  borderRadius: "8px"
};
va.propTypes = {
  tableInfo: N.any,
  table: N.any,
  isEditMode: N.bool,
  updateEditMode: N.any,
  tableCompleteInfo: N.any,
  reloadComponents: N.any,
  isCreateTableMode: N.bool,
  isSyncTableMode: N.bool,
  updateCreateTableMode: N.any,
  openDeleteModal: N.bool,
  setOpenDeleteModal: N.func
};
export {
  va as default
};
//# sourceMappingURL=TableDetails-DzREeJkm-B-WEBbQz.js.map
