import { jsxs as a, jsx as e } from "react/jsx-runtime";
import { addServer as ce, addServerMappingList as de, updateServer as ue, updateServerMappingList as pe, getAllServer as he, getAllServerDetails as me } from "@/common/services/SyncWithServer";
import { FontAwesomeIcon as v } from "@fortawesome/react-fontawesome";
import { faPen as V, faPlus as H, faServer as Q, faCircleCheck as X, faMagnifyingGlass as fe, faCircleXmark as ge } from "@fortawesome/free-solid-svg-icons";
import { useTheme as te } from "@mui/material/styles";
import { Dialog as ve, DialogTitle as be, Box as F, Typography as c, DialogContent as ye, Divider as G, Autocomplete as B, TextField as I, FormHelperText as Z, FormControl as Se, RadioGroup as xe, FormControlLabel as _, Radio as ee, Chip as b, DialogActions as Ce, Button as Y, Paper as re, InputAdornment as Pe, TableContainer as Ae, Table as ze, TableHead as we, TableRow as J, TableCell as h, TableBody as Te, Tooltip as oe, IconButton as ke } from "@mui/material";
import f from "@mui/material/Grid2";
import { Box as z } from "@mui/system";
import { useState as P, useEffect as le, createElement as ne, useMemo as Re } from "react";
import { showToast as C } from "@/common/toaster/toaster";
import { useDebounceFn as We } from "@/hooks/useDebounceFn";
import U from "@/views/custom-components/CustomTextField";
import { yupResolver as Ne } from "@hookform/resolvers/yup";
import y from "prop-types";
import { useForm as Fe, Controller as q } from "react-hook-form";
import * as R from "yup";
import { useTranslateProvider as qe } from "@/common/languageTranslator/TranslationContext";
function ae({
  openAddServer: O,
  openAddServerFunc: W,
  allServerList: x,
  reloadPageFunc: w,
  editServer: g,
  editServerFunc: N,
  serverData: d = {}
}) {
  var k;
  const { translate: u } = qe(), [S, E] = P(""), M = ["STAGING", "PRODUCTION"], D = te(), A = (l) => D.palette.mode === "light" ? l : `${l}-dark`, $ = R.object().shape({
    name: R.string().required("Name is required"),
    code: R.string().required("Code is required"),
    type: R.string().required("Type is required"),
    url: R.string().required("URL is required").matches(
      /^https?:\/\/(localhost|\d{1,3}(?:\.\d{1,3}){3}|[a-zA-Z0-9.-]+)(:\d+)?(\/.*)?$/,
      "Invalid URL"
    ),
    isActive: R.boolean().required("This field is required.")
  }), s = Fe({
    defaultValues: {
      name: "",
      code: "",
      type: "",
      url: "",
      isActive: null,
      canPullServer: [],
      canPushServer: []
    },
    resolver: Ne($),
    mode: "onChange"
  });
  le(() => {
    g && s.reset({
      name: d.name,
      code: d.code,
      type: d.type,
      url: d.url,
      isActive: d.isActive,
      canPullServer: d.canPullServers ? d.canPullServers : [],
      canPushServer: d.canPushServers ? d.canPushServers : []
    });
  }, []);
  const T = () => {
    W(!1), N(!1);
  }, L = We(async (l) => {
    x != null && x.find((o) => o.code === l) ? s.setError("code", {
      type: "manual",
      message: "Code already exists"
    }) : E(`${l} is available`);
  }, 500), j = async (l) => {
    var n, i;
    let o = /* @__PURE__ */ new Map();
    (n = l.canPullServer) == null || n.forEach((t) => {
      let p = {
        canPull: !0,
        canPush: !1
      };
      o.set(t.code, p);
    }), (i = l.canPushServer) == null || i.forEach((t) => {
      if (o.has(t.code))
        o.get(t.code).canPush = !0;
      else {
        let p = {
          canPull: !1,
          canPush: !0
        };
        o.set(t.code, p);
      }
    });
    const r = [];
    if (o.forEach((t, p) => {
      r.push({
        sourceServerCode: l.code,
        destinationServerCode: p,
        canPull: t.canPull,
        canPush: t.canPush
      }), r.push({
        sourceServerCode: p,
        destinationServerCode: l.code,
        canPull: t.canPush,
        canPush: t.canPull
      });
    }), g)
      try {
        if (o.size === 0 && r.push({
          sourceServerCode: l.code,
          destinationServerCode: null,
          canPull: null,
          canPush: null
        }), l.uuid = d.uuid, await ue(l), C({
          type: "success",
          message: "Server updated successfully"
        }), r.length > 0)
          try {
            await pe(r), C({
              type: "success",
              message: "Server mapping updated successfully"
            });
          } catch (t) {
            C({
              type: "error",
              message: "Failed to update server mapping"
            }), console.error("Error updating server mapping:", t);
          }
        w((t) => !t), T();
      } catch (t) {
        C({
          type: "error",
          message: "Failed to update server"
        }), console.error("Error updating server:", t);
      }
    else
      try {
        const t = {
          name: l.name,
          code: l.code,
          type: l.type,
          url: l.url,
          isActive: l.isActive
        };
        if (await ce(t), C({
          type: "success",
          message: "Server added successfully"
        }), r.length > 0)
          try {
            await de(r), C({
              type: "success",
              message: "Server mapping added successfully"
            });
          } catch (p) {
            C({
              type: "error",
              message: "Failed to add server mapping"
            }), console.error("Error adding server mapping:", p);
          }
        w((p) => !p), W(!1);
      } catch (t) {
        C({
          type: "error",
          message: "Failed to add server"
        }), console.error("Error adding server:", t);
      }
  }, m = ({ label: l, required: o, children: r }) => /* @__PURE__ */ a(F, { sx: { display: "flex", flexDirection: "column", gap: 0.75 }, children: [
    /* @__PURE__ */ a(
      c,
      {
        variant: "body2",
        sx: { fontWeight: 600, color: "text.primary" },
        children: [
          l,
          o && /* @__PURE__ */ e(c, { component: "span", sx: { color: "error.main", ml: 0.5 }, children: "*" })
        ]
      }
    ),
    r
  ] });
  return m.propTypes = {
    label: y.string.isRequired,
    required: y.bool,
    children: y.node.isRequired
  }, /* @__PURE__ */ a(
    ve,
    {
      open: O,
      fullWidth: !0,
      maxWidth: "sm",
      onClose: T,
      className: A("add-server-dialog"),
      PaperProps: {
        sx: {
          borderRadius: 3,
          scrollbarWidth: "none",
          msOverflowStyle: "none",
          "&::-webkit-scrollbar": { display: "none" },
          "& .MuiDialogContent-root": {
            scrollbarWidth: "none",
            msOverflowStyle: "none",
            "&::-webkit-scrollbar": { display: "none" }
          }
        }
      },
      children: [
        /* @__PURE__ */ e(
          be,
          {
            sx: {
              px: 3,
              pt: 2.5,
              pb: 2,
              borderBottom: "1px solid",
              borderColor: "divider",
              backgroundColor: "background.paper"
            },
            children: /* @__PURE__ */ a(F, { sx: { display: "flex", alignItems: "center", gap: 1.5 }, children: [
              /* @__PURE__ */ e(
                F,
                {
                  sx: {
                    width: 36,
                    height: 36,
                    borderRadius: 2,
                    display: "flex",
                    alignItems: "center",
                    justifyContent: "center",
                    backgroundColor: "primary.main",
                    color: "primary.contrastText",
                    flexShrink: 0
                  },
                  children: /* @__PURE__ */ e(
                    v,
                    {
                      icon: g ? V : H,
                      style: { fontSize: "0.85rem" }
                    }
                  )
                }
              ),
              /* @__PURE__ */ a(F, { children: [
                /* @__PURE__ */ e(c, { variant: "h6", sx: { fontWeight: 700, lineHeight: 1.3 }, children: u(g ? "Update Server" : "Add Server") }),
                /* @__PURE__ */ e(c, { variant: "caption", color: "text.secondary", children: g ? "Modify server configuration and sync permissions." : "Configure a new server connection." })
              ] })
            ] })
          }
        ),
        /* @__PURE__ */ a("form", { noValidate: !0, onSubmit: s.handleSubmit(j), children: [
          /* @__PURE__ */ e(
            ye,
            {
              sx: {
                px: 3,
                py: 3,
                scrollbarWidth: "none",
                "&::-webkit-scrollbar": { display: "none" }
              },
              children: /* @__PURE__ */ a(f, { container: !0, spacing: 2.5, children: [
                /* @__PURE__ */ a(f, { size: 12, children: [
                  /* @__PURE__ */ e(
                    c,
                    {
                      variant: "subtitle2",
                      sx: {
                        fontWeight: 700,
                        color: "text.primary",
                        mb: 0.5,
                        textTransform: "uppercase",
                        fontSize: "0.7rem",
                        letterSpacing: "0.05em"
                      },
                      children: "Server Details"
                    }
                  ),
                  /* @__PURE__ */ e(G, {})
                ] }),
                /* @__PURE__ */ e(f, { size: 6, children: /* @__PURE__ */ e(m, { label: u("Name"), required: !0, children: /* @__PURE__ */ e(
                  U,
                  {
                    control: s.control,
                    name: "name",
                    id: "name",
                    errors: s.formState.errors,
                    placeholder: "Enter server name"
                  }
                ) }) }),
                /* @__PURE__ */ e(f, { size: 6, children: /* @__PURE__ */ e(m, { label: u("Code"), required: !0, children: /* @__PURE__ */ e(
                  U,
                  {
                    control: s.control,
                    name: "code",
                    id: "code",
                    disabled: g,
                    errors: s.formState.errors,
                    placeholder: "Enter server code",
                    successMessage: S,
                    onChange: (l) => L(l.target.value)
                  }
                ) }) }),
                /* @__PURE__ */ e(f, { size: 6, children: /* @__PURE__ */ a(m, { label: u("Type"), required: !0, children: [
                  /* @__PURE__ */ e(
                    q,
                    {
                      name: "type",
                      control: s.control,
                      render: ({ field: { onChange: l, value: o } }) => /* @__PURE__ */ e(
                        B,
                        {
                          size: "small",
                          options: M || [],
                          getOptionLabel: (r) => r,
                          defaultValue: o,
                          onChange: (r, n) => {
                            l(n);
                          },
                          renderInput: (r) => {
                            var n;
                            return /* @__PURE__ */ e(
                              I,
                              {
                                ...r,
                                placeholder: "Select type",
                                variant: "outlined",
                                error: !!((n = s.formState.errors) != null && n.type)
                              }
                            );
                          }
                        }
                      )
                    }
                  ),
                  s.formState.errors.type && /* @__PURE__ */ e(Z, { error: !0, children: (k = s.formState.errors.type) == null ? void 0 : k.message })
                ] }) }),
                /* @__PURE__ */ e(f, { size: 6, children: /* @__PURE__ */ e(m, { label: u("URL"), required: !0, children: /* @__PURE__ */ e(
                  U,
                  {
                    control: s.control,
                    name: "url",
                    id: "url",
                    errors: s.formState.errors,
                    placeholder: "https://example.com"
                  }
                ) }) }),
                /* @__PURE__ */ e(f, { size: 12, children: /* @__PURE__ */ e(m, { label: u("Active"), required: !0, children: /* @__PURE__ */ e(
                  q,
                  {
                    name: "isActive",
                    control: s.control,
                    rules: { required: "This field is required." },
                    render: ({
                      field: { onChange: l, value: o },
                      fieldState: { error: r }
                    }) => {
                      var n;
                      return /* @__PURE__ */ a(Se, { component: "fieldset", error: !!r, children: [
                        /* @__PURE__ */ a(xe, { row: !0, value: o, onChange: l, children: [
                          /* @__PURE__ */ e(
                            _,
                            {
                              value: !0,
                              control: /* @__PURE__ */ e(ee, { size: "small" }),
                              label: /* @__PURE__ */ e(c, { variant: "body2", children: "Yes" })
                            }
                          ),
                          /* @__PURE__ */ e(
                            _,
                            {
                              value: !1,
                              control: /* @__PURE__ */ e(ee, { size: "small" }),
                              label: /* @__PURE__ */ e(c, { variant: "body2", children: "No" })
                            }
                          )
                        ] }),
                        r && /* @__PURE__ */ e(Z, { children: (n = s.formState.errors.isActive) == null ? void 0 : n.message })
                      ] });
                    }
                  }
                ) }) }),
                /* @__PURE__ */ a(f, { size: 12, sx: { mt: 0.5 }, children: [
                  /* @__PURE__ */ e(
                    c,
                    {
                      variant: "subtitle2",
                      sx: {
                        fontWeight: 700,
                        color: "text.primary",
                        mb: 0.5,
                        textTransform: "uppercase",
                        fontSize: "0.7rem",
                        letterSpacing: "0.05em"
                      },
                      children: "Sync Permissions"
                    }
                  ),
                  /* @__PURE__ */ e(G, {})
                ] }),
                /* @__PURE__ */ e(f, { size: 12, children: /* @__PURE__ */ e(m, { label: u("Can Pull From"), children: /* @__PURE__ */ e(
                  q,
                  {
                    name: "canPullServer",
                    control: s.control,
                    render: ({ field: { onChange: l, value: o } }) => /* @__PURE__ */ e(
                      B,
                      {
                        size: "small",
                        multiple: !0,
                        options: x || [],
                        getOptionLabel: (r) => r.name || "",
                        getOptionKey: (r) => r.code || "",
                        getOptionDisabled: (r) => r.code === s.getValues("code") || s.getValues("canPullServer").some((n) => n.code === r.code),
                        value: o,
                        onChange: (r, n) => {
                          l(n);
                        },
                        renderTags: (r, n) => r.map((i, t) => /* @__PURE__ */ ne(
                          b,
                          {
                            ...n({ index: t }),
                            key: i.code,
                            label: i.name,
                            size: "small",
                            color: "primary",
                            variant: "outlined",
                            sx: { borderRadius: 2, fontWeight: 500 }
                          }
                        )),
                        renderInput: (r) => /* @__PURE__ */ e(
                          I,
                          {
                            ...r,
                            placeholder: (o == null ? void 0 : o.length) > 0 ? "" : "Select servers to pull from...",
                            variant: "outlined"
                          }
                        )
                      }
                    )
                  }
                ) }) }),
                /* @__PURE__ */ e(f, { size: 12, children: /* @__PURE__ */ e(m, { label: u("Can Push To"), children: /* @__PURE__ */ e(
                  q,
                  {
                    name: "canPushServer",
                    control: s.control,
                    render: ({ field: { onChange: l, value: o } }) => /* @__PURE__ */ e(
                      B,
                      {
                        size: "small",
                        multiple: !0,
                        options: x || [],
                        getOptionLabel: (r) => r.name || "",
                        getOptionKey: (r) => r.code || "",
                        getOptionDisabled: (r) => r.code === s.getValues("code") || s.getValues("canPushServer").some((n) => n.code === r.code),
                        value: o,
                        onChange: (r, n) => {
                          l(n);
                        },
                        renderTags: (r, n) => r.map((i, t) => /* @__PURE__ */ ne(
                          b,
                          {
                            ...n({ index: t }),
                            key: i.code,
                            label: i.name,
                            size: "small",
                            color: "primary",
                            variant: "outlined",
                            sx: { borderRadius: 2, fontWeight: 500 }
                          }
                        )),
                        renderInput: (r) => /* @__PURE__ */ e(
                          I,
                          {
                            ...r,
                            placeholder: (o == null ? void 0 : o.length) > 0 ? "" : "Select servers to push to...",
                            variant: "outlined"
                          }
                        )
                      }
                    )
                  }
                ) }) })
              ] })
            }
          ),
          /* @__PURE__ */ a(
            Ce,
            {
              sx: {
                px: 3,
                py: 2,
                borderTop: "1px solid",
                borderColor: "divider",
                gap: 1
              },
              children: [
                /* @__PURE__ */ e(
                  Y,
                  {
                    onClick: T,
                    size: "small",
                    variant: "outlined",
                    sx: {
                      borderRadius: 2,
                      textTransform: "none",
                      fontWeight: 600,
                      px: 2.5,
                      borderColor: "divider",
                      color: "text.secondary",
                      "&:hover": {
                        backgroundColor: "action.hover",
                        borderColor: "text.disabled"
                      }
                    },
                    children: u("Cancel")
                  }
                ),
                /* @__PURE__ */ e(
                  Y,
                  {
                    type: "submit",
                    size: "small",
                    variant: "contained",
                    sx: {
                      borderRadius: 2,
                      textTransform: "none",
                      fontWeight: 600,
                      px: 2.5,
                      boxShadow: "none"
                    },
                    startIcon: /* @__PURE__ */ e(
                      v,
                      {
                        icon: g ? V : H,
                        style: { fontSize: "0.75rem" }
                      }
                    ),
                    children: g ? "Update Server" : "Add Server"
                  }
                )
              ]
            }
          )
        ] })
      ]
    }
  );
}
ae.propTypes = {
  openAddServer: y.bool,
  openAddServerFunc: y.func,
  allServerList: y.array,
  reloadPageFunc: y.func,
  editServer: y.bool,
  editServerFunc: y.func,
  serverData: y.object
};
function Qe() {
  const [O, W] = P([]), [x, w] = P(!1), [g, N] = P(!1), [d, u] = P({}), [S, E] = P([]), [M, D] = P(!1), [A, $] = P(""), s = te();
  le(() => {
    (async () => (await K(), await L()))();
  }, [M]);
  const T = (o) => s.palette.mode === "light" ? o : `${o}-dark`, K = async () => {
    try {
      const o = (await he()).data;
      o && W(
        o.map((r) => ({ code: r.code, name: r.name }))
      );
    } catch (o) {
      console.error("Error fetching servers:", o);
    }
  }, L = async () => {
    try {
      const o = (await me()).data;
      o && (o.forEach((r) => {
        let n = r.canPullServers ? JSON.parse(r.canPullServers) : [], i = r.canPushServers ? JSON.parse(r.canPushServers) : [];
        r.canPullServers = JSON.parse(r.canPullServers), r.canPushServers = JSON.parse(r.canPushServers), r.pullServersName = n.length > 0 ? n.map((t) => t.name) : [], r.pushServersName = i.length > 0 ? i.map((t) => t.name) : [];
      }), E(o));
    } catch (o) {
      console.error("Error fetching servers:", o);
    }
  }, j = (o) => {
    N(!0), u(o), w(!0);
  }, m = Re(() => {
    if (!A.trim()) return S;
    const o = A.toLowerCase();
    return S.filter(
      (r) => {
        var n, i, t;
        return ((n = r.name) == null ? void 0 : n.toLowerCase().includes(o)) || ((i = r.code) == null ? void 0 : i.toLowerCase().includes(o)) || ((t = r.url) == null ? void 0 : t.toLowerCase().includes(o));
      }
    );
  }, [S, A]), k = S.filter((o) => o.isActive).length, l = (o) => {
    if (!o) return "-";
    const r = new Date(o), n = String(r.getDate()).padStart(2, "0"), t = [
      "Jan",
      "Feb",
      "Mar",
      "Apr",
      "May",
      "Jun",
      "Jul",
      "Aug",
      "Sep",
      "Oct",
      "Nov",
      "Dec"
    ][r.getMonth()], p = r.getFullYear(), se = String(r.getHours()).padStart(2, "0"), ie = String(r.getMinutes()).padStart(2, "0");
    return `${n} ${t} ${p}, ${se}:${ie}`;
  };
  return /* @__PURE__ */ a(f, { pt: 2, sx: { height: "calc(100vh)", zoom: "0.9" }, children: [
    /* @__PURE__ */ e(z, { sx: { p: 3 }, className: T("server-management-wrapper"), children: /* @__PURE__ */ a(
      re,
      {
        elevation: 0,
        sx: {
          p: { xs: 2.5, md: 3 },
          border: "1px solid",
          borderColor: "divider",
          borderRadius: 3,
          backgroundColor: "background.paper"
        },
        children: [
          /* @__PURE__ */ a(z, { sx: { display: "flex", flexDirection: "column", gap: 3 }, children: [
            /* @__PURE__ */ a(
              z,
              {
                sx: {
                  display: "flex",
                  justifyContent: "space-between",
                  alignItems: "flex-start",
                  flexWrap: "wrap",
                  gap: 2
                },
                children: [
                  /* @__PURE__ */ a(z, { sx: { minWidth: { xs: "100%", lg: "40%" } }, children: [
                    /* @__PURE__ */ e(
                      c,
                      {
                        variant: "h5",
                        sx: { fontWeight: 800, color: "text.primary", mb: 0.5 },
                        children: "Server Management"
                      }
                    ),
                    /* @__PURE__ */ e(c, { variant: "body2", color: "text.secondary", children: "Configure and manage server connections, sync permissions, and server details." })
                  ] }),
                  /* @__PURE__ */ e(
                    z,
                    {
                      sx: {
                        display: "flex",
                        alignItems: "center",
                        gap: 1.5,
                        flexWrap: "wrap"
                      },
                      children: /* @__PURE__ */ e(
                        Y,
                        {
                          size: "small",
                          variant: "contained",
                          sx: {
                            borderRadius: 2,
                            fontWeight: 600,
                            px: 2,
                            boxShadow: "none",
                            textTransform: "none"
                          },
                          startIcon: /* @__PURE__ */ e(v, { icon: H }),
                          onClick: () => {
                            w(!0);
                          },
                          children: "Add Server"
                        }
                      )
                    }
                  )
                ]
              }
            ),
            /* @__PURE__ */ a(
              z,
              {
                sx: {
                  display: "flex",
                  justifyContent: "space-between",
                  alignItems: "center",
                  flexWrap: "wrap",
                  gap: 2,
                  backgroundColor: "action.hover",
                  p: 1.5,
                  borderRadius: 2.5,
                  border: "1px solid",
                  borderColor: "divider"
                },
                children: [
                  /* @__PURE__ */ a(z, { sx: { display: "flex", alignItems: "center", gap: 1.5 }, children: [
                    /* @__PURE__ */ e(
                      b,
                      {
                        icon: /* @__PURE__ */ e(
                          v,
                          {
                            icon: Q,
                            style: { fontSize: "0.7rem" }
                          }
                        ),
                        label: `${S.length} Total`,
                        size: "small",
                        variant: "outlined",
                        sx: {
                          fontWeight: 600,
                          borderRadius: 2,
                          px: 0.5,
                          borderColor: "divider"
                        }
                      }
                    ),
                    /* @__PURE__ */ e(
                      b,
                      {
                        icon: /* @__PURE__ */ e(
                          v,
                          {
                            icon: X,
                            style: { fontSize: "0.7rem" }
                          }
                        ),
                        label: `${k} Active`,
                        size: "small",
                        color: "success",
                        variant: "filled",
                        sx: { fontWeight: 700, borderRadius: 2, px: 0.5 }
                      }
                    ),
                    S.length - k > 0 && /* @__PURE__ */ e(
                      b,
                      {
                        label: `${S.length - k} Inactive`,
                        size: "small",
                        color: "default",
                        variant: "outlined",
                        sx: {
                          fontWeight: 600,
                          borderRadius: 2,
                          px: 0.5,
                          borderColor: "divider"
                        }
                      }
                    )
                  ] }),
                  /* @__PURE__ */ e(
                    I,
                    {
                      value: A,
                      size: "small",
                      placeholder: "Search servers...",
                      onChange: (o) => $(o.target.value),
                      InputProps: {
                        startAdornment: /* @__PURE__ */ e(Pe, { position: "start", children: /* @__PURE__ */ e(
                          v,
                          {
                            icon: fe,
                            style: { fontSize: "0.85rem", color: "#999" }
                          }
                        ) }),
                        sx: {
                          backgroundColor: "background.paper",
                          borderRadius: 2,
                          minWidth: 260
                        }
                      }
                    }
                  )
                ]
              }
            )
          ] }),
          /* @__PURE__ */ e(G, { sx: { my: 3 } }),
          /* @__PURE__ */ e(
            Ae,
            {
              className: T("server-table"),
              component: re,
              elevation: 0,
              sx: {
                borderRadius: 2.5,
                border: "1px solid",
                borderColor: "divider",
                overflowY: "auto",
                maxHeight: "calc(100vh - 340px)"
              },
              children: /* @__PURE__ */ a(ze, { stickyHeader: !0, children: [
                /* @__PURE__ */ e(we, { children: /* @__PURE__ */ e(J, { children: [
                  "Sr. No.",
                  "Name",
                  "Code",
                  "Type",
                  "URL",
                  "Status",
                  "Can Pull From",
                  "Can Push To",
                  "Modified On",
                  "Actions"
                ].map((o, r) => /* @__PURE__ */ e(
                  h,
                  {
                    align: o === "Actions" ? "center" : "left",
                    sx: {
                      fontWeight: 700,
                      fontSize: "0.78rem",
                      textTransform: "uppercase",
                      letterSpacing: "0.04em",
                      color: "text.secondary",
                      backgroundColor: "background.default",
                      borderBottom: "2px solid",
                      borderColor: "divider",
                      py: 1.5
                    },
                    children: o
                  },
                  r
                )) }) }),
                /* @__PURE__ */ a(Te, { children: [
                  m.map((o, r) => /* @__PURE__ */ a(
                    J,
                    {
                      sx: {
                        transition: "background-color 0.15s ease",
                        "&:hover": { backgroundColor: "action.hover" },
                        "&:last-child td": { borderBottom: 0 }
                      },
                      children: [
                        /* @__PURE__ */ e(
                          h,
                          {
                            sx: { color: "text.secondary", fontWeight: 500 },
                            children: r + 1
                          }
                        ),
                        /* @__PURE__ */ e(h, { sx: { fontWeight: 600 }, children: o.name }),
                        /* @__PURE__ */ e(h, { children: /* @__PURE__ */ e(
                          b,
                          {
                            label: o.code,
                            size: "small",
                            variant: "outlined",
                            sx: {
                              fontFamily: "monospace",
                              fontSize: "0.75rem",
                              borderRadius: 1.5,
                              borderColor: "divider"
                            }
                          }
                        ) }),
                        /* @__PURE__ */ e(h, { children: o.type }),
                        /* @__PURE__ */ e(
                          h,
                          {
                            sx: {
                              maxWidth: 200,
                              overflow: "hidden",
                              textOverflow: "ellipsis",
                              whiteSpace: "nowrap"
                            },
                            children: /* @__PURE__ */ e(oe, { title: o.url || "", arrow: !0, placement: "top", children: /* @__PURE__ */ e("span", { children: o.url }) })
                          }
                        ),
                        /* @__PURE__ */ e(h, { children: o.isActive ? /* @__PURE__ */ e(
                          b,
                          {
                            icon: /* @__PURE__ */ e(
                              v,
                              {
                                icon: X,
                                style: { fontSize: "0.7rem" }
                              }
                            ),
                            label: "Active",
                            size: "small",
                            color: "success",
                            variant: "filled",
                            sx: { fontWeight: 600, borderRadius: 2 }
                          }
                        ) : /* @__PURE__ */ e(
                          b,
                          {
                            icon: /* @__PURE__ */ e(
                              v,
                              {
                                icon: ge,
                                style: { fontSize: "0.7rem" }
                              }
                            ),
                            label: "Inactive",
                            size: "small",
                            color: "default",
                            variant: "outlined",
                            sx: {
                              fontWeight: 600,
                              borderRadius: 2,
                              borderColor: "divider"
                            }
                          }
                        ) }),
                        /* @__PURE__ */ e(h, { children: Array.isArray(o.pullServersName) && o.pullServersName.length > 0 ? o.pullServersName.map((n, i) => /* @__PURE__ */ e(
                          b,
                          {
                            label: n || "-",
                            color: "primary",
                            size: "small",
                            variant: "outlined",
                            sx: {
                              mr: 0.5,
                              mb: 0.5,
                              borderRadius: 2,
                              fontWeight: 500
                            }
                          },
                          i
                        )) : /* @__PURE__ */ e(c, { variant: "caption", color: "text.disabled", children: "—" }) }),
                        /* @__PURE__ */ e(h, { children: Array.isArray(o.pushServersName) && o.pushServersName.length > 0 ? o.pushServersName.map((n, i) => /* @__PURE__ */ e(
                          b,
                          {
                            label: n || "-",
                            color: "primary",
                            size: "small",
                            variant: "outlined",
                            sx: {
                              mr: 0.5,
                              mb: 0.5,
                              borderRadius: 2,
                              fontWeight: 500
                            }
                          },
                          i
                        )) : /* @__PURE__ */ e(c, { variant: "caption", color: "text.disabled", children: "—" }) }),
                        /* @__PURE__ */ e(h, { children: /* @__PURE__ */ e(
                          c,
                          {
                            variant: "caption",
                            sx: { color: "text.secondary" },
                            children: l(o.modifiedOn)
                          }
                        ) }),
                        /* @__PURE__ */ e(h, { align: "center", children: /* @__PURE__ */ e(oe, { title: "Edit server", arrow: !0, placement: "top", children: /* @__PURE__ */ e(
                          ke,
                          {
                            size: "small",
                            onClick: () => {
                              j(o);
                            },
                            sx: {
                              color: "primary.main",
                              "&:hover": { backgroundColor: "primary.50" }
                            },
                            children: /* @__PURE__ */ e(
                              v,
                              {
                                icon: V,
                                style: { fontSize: "0.8rem" }
                              }
                            )
                          }
                        ) }) })
                      ]
                    },
                    r
                  )),
                  m.length === 0 && /* @__PURE__ */ e(J, { children: /* @__PURE__ */ a(h, { colSpan: 10, align: "center", sx: { py: 6 }, children: [
                    /* @__PURE__ */ e(
                      v,
                      {
                        icon: Q,
                        style: {
                          fontSize: "2rem",
                          color: "#ccc",
                          marginBottom: 8,
                          display: "block",
                          margin: "0 auto 8px"
                        }
                      }
                    ),
                    /* @__PURE__ */ e(c, { variant: "body2", color: "text.secondary", children: A ? "No servers match your search." : 'No servers found. Click "Add Server" to get started.' })
                  ] }) })
                ] })
              ] })
            }
          )
        ]
      }
    ) }),
    x && /* @__PURE__ */ e(
      ae,
      {
        openAddServer: x,
        openAddServerFunc: w,
        allServerList: O,
        reloadPageFunc: D,
        editServer: g,
        editServerFunc: N,
        serverData: d
      }
    )
  ] });
}
export {
  Qe as default
};
//# sourceMappingURL=NewServerManagement-5YcAtF-g.js.map
