import {
  ApiKeysTable,
  sortApiKeys
} from "/build/_shared/chunk-FXDK75EI.js";
import "/build/_shared/chunk-B7SHUSBW.js";
import {
  Input
} from "/build/_shared/chunk-E6JFCF7O.js";
import "/build/_shared/chunk-O67VWZBP.js";
import {
  Label
} from "/build/_shared/chunk-Z3FLWRAR.js";
import {
  Button
} from "/build/_shared/chunk-UWBTKPLD.js";
import "/build/_shared/chunk-ERWYPUCA.js";
import "/build/_shared/chunk-P3C75TI5.js";
import {
  PageLayout
} from "/build/_shared/chunk-BXT5AGPN.js";
import "/build/_shared/chunk-5YPGPC4O.js";
import "/build/_shared/chunk-7K73PJIB.js";
import "/build/_shared/chunk-EJE2TVVM.js";
import {
  CheckCircledIcon
} from "/build/_shared/chunk-LGQ4GCFK.js";
import "/build/_shared/chunk-B7TG3BDD.js";
import "/build/_shared/chunk-7NMI3PDC.js";
import "/build/_shared/chunk-AI5FD5Y6.js";
import {
  withAuth
} from "/build/_shared/chunk-NHF4CNMF.js";
import "/build/_shared/chunk-KQKP3VNY.js";
import {
  init_esm2 as init_esm,
  useFetcher,
  useLoaderData,
  useMatches,
  useParams
} from "/build/_shared/chunk-ZC2TL3GZ.js";
import {
  require_jsx_dev_runtime
} from "/build/_shared/chunk-ED7KKCRB.js";
import "/build/_shared/chunk-RYE6BCZB.js";
import {
  require_react
} from "/build/_shared/chunk-PECDPABK.js";
import {
  require_node
} from "/build/_shared/chunk-G7CHZRZX.js";
import "/build/_shared/chunk-TLLKLDIT.js";
import {
  Routes
} from "/build/_shared/chunk-N27UEDHN.js";
import {
  createHotContext,
  init_remix_hmr
} from "/build/_shared/chunk-G7KTOMTD.js";
import "/build/_shared/chunk-ZIPKILLR.js";
import {
  __toESM
} from "/build/_shared/chunk-PNG5AS42.js";

// app/routes/app+/project+/$projectId+/env+/$envId+/api-keys.tsx
init_remix_hmr();
var import_node = __toESM(require_node(), 1);
init_esm();

// app/pages/apiKeys/ApiKeysPage.tsx
init_remix_hmr();
init_esm();
var import_react2 = __toESM(require_react(), 1);
var import_jsx_dev_runtime = __toESM(require_jsx_dev_runtime(), 1);
if (!window.$RefreshReg$ || !window.$RefreshSig$ || !window.$RefreshRuntime$) {
  console.warn("remix:hmr: React Fast Refresh only works when the Remix compiler is running in development mode.");
} else {
  prevRefreshReg = window.$RefreshReg$;
  prevRefreshSig = window.$RefreshSig$;
  window.$RefreshReg$ = (type, id) => {
    window.$RefreshRuntime$.register(type, '"app/pages/apiKeys/ApiKeysPage.tsx"' + id);
  };
  window.$RefreshSig$ = window.$RefreshRuntime$.createSignatureFunctionForTransform;
}
var prevRefreshReg;
var prevRefreshSig;
var _s = $RefreshSig$();
if (import.meta) {
  import.meta.hot = createHotContext(
    //@ts-expect-error
    "app/pages/apiKeys/ApiKeysPage.tsx"
  );
  import.meta.hot.lastModified = "1713199469912.294";
}
var ApiKeysPage = ({
  sortedEnvironments
}) => {
  _s();
  const params = useParams();
  const matches = useMatches();
  const fetcher = useFetcher();
  const initialKey = matches.find((match) => match.id === "routes/app+/project+/$projectId+/env+/$envId+/_layout").data.project.openaiApiKey;
  const [openAIKey, setOpenAIKey] = (0, import_react2.useState)(initialKey);
  const breadcrumbs = [{
    label: "API Keys"
  }];
  const handleSetOpenAIKey = () => {
    fetcher.submit({
      key: openAIKey
    }, {
      method: "POST",
      action: Routes.actions.project.setOpenAIKey(params.projectId),
      encType: "application/json"
    });
  };
  const isSaveDisabled = openAIKey === initialKey;
  const fetcherApiKey = fetcher.data?.project.openaiApiKey;
  const showSaved = fetcher.state === "idle" && fetcherApiKey && openAIKey.startsWith(fetcherApiKey.replaceAll("*", ""));
  return /* @__PURE__ */ (0, import_jsx_dev_runtime.jsxDEV)(PageLayout, { breadcrumbs, children: /* @__PURE__ */ (0, import_jsx_dev_runtime.jsxDEV)("div", { className: "flex flex-col gap-8", children: [
    /* @__PURE__ */ (0, import_jsx_dev_runtime.jsxDEV)("div", { children: [
      /* @__PURE__ */ (0, import_jsx_dev_runtime.jsxDEV)(Label, { children: "Montelo" }, void 0, false, {
        fileName: "app/pages/apiKeys/ApiKeysPage.tsx",
        lineNumber: 58,
        columnNumber: 11
      }, this),
      /* @__PURE__ */ (0, import_jsx_dev_runtime.jsxDEV)(ApiKeysTable, { sortedEnvironments, projectId: params.projectId }, void 0, false, {
        fileName: "app/pages/apiKeys/ApiKeysPage.tsx",
        lineNumber: 59,
        columnNumber: 11
      }, this)
    ] }, void 0, true, {
      fileName: "app/pages/apiKeys/ApiKeysPage.tsx",
      lineNumber: 57,
      columnNumber: 9
    }, this),
    /* @__PURE__ */ (0, import_jsx_dev_runtime.jsxDEV)("div", { children: [
      /* @__PURE__ */ (0, import_jsx_dev_runtime.jsxDEV)(Label, { children: "OpenAI" }, void 0, false, {
        fileName: "app/pages/apiKeys/ApiKeysPage.tsx",
        lineNumber: 62,
        columnNumber: 11
      }, this),
      /* @__PURE__ */ (0, import_jsx_dev_runtime.jsxDEV)("p", { className: "text-muted-foreground text-sm", children: "Your OpenAI key will only be used for Fine-Tuning." }, void 0, false, {
        fileName: "app/pages/apiKeys/ApiKeysPage.tsx",
        lineNumber: 63,
        columnNumber: 11
      }, this),
      /* @__PURE__ */ (0, import_jsx_dev_runtime.jsxDEV)("div", { className: "flex gap-2", children: [
        /* @__PURE__ */ (0, import_jsx_dev_runtime.jsxDEV)(Input, { className: "w-1/3", placeholder: "sk-...", value: openAIKey, onChange: (e) => setOpenAIKey(e.target.value) }, void 0, false, {
          fileName: "app/pages/apiKeys/ApiKeysPage.tsx",
          lineNumber: 65,
          columnNumber: 13
        }, this),
        /* @__PURE__ */ (0, import_jsx_dev_runtime.jsxDEV)(Button, { onClick: handleSetOpenAIKey, disabled: isSaveDisabled, className: "flex gap-1", children: [
          showSaved && /* @__PURE__ */ (0, import_jsx_dev_runtime.jsxDEV)(CheckCircledIcon, { className: "h-4 w-4" }, void 0, false, {
            fileName: "app/pages/apiKeys/ApiKeysPage.tsx",
            lineNumber: 67,
            columnNumber: 29
          }, this),
          showSaved ? "Saved" : "Save"
        ] }, void 0, true, {
          fileName: "app/pages/apiKeys/ApiKeysPage.tsx",
          lineNumber: 66,
          columnNumber: 13
        }, this)
      ] }, void 0, true, {
        fileName: "app/pages/apiKeys/ApiKeysPage.tsx",
        lineNumber: 64,
        columnNumber: 11
      }, this)
    ] }, void 0, true, {
      fileName: "app/pages/apiKeys/ApiKeysPage.tsx",
      lineNumber: 61,
      columnNumber: 9
    }, this)
  ] }, void 0, true, {
    fileName: "app/pages/apiKeys/ApiKeysPage.tsx",
    lineNumber: 56,
    columnNumber: 7
  }, this) }, void 0, false, {
    fileName: "app/pages/apiKeys/ApiKeysPage.tsx",
    lineNumber: 55,
    columnNumber: 10
  }, this);
};
_s(ApiKeysPage, "Ga8zED6vPJB3B07YI/2aKTEWvjA=", false, function() {
  return [useParams, useMatches, useFetcher];
});
_c = ApiKeysPage;
var _c;
$RefreshReg$(_c, "ApiKeysPage");
window.$RefreshReg$ = prevRefreshReg;
window.$RefreshSig$ = prevRefreshSig;

// app/routes/app+/project+/$projectId+/env+/$envId+/api-keys.tsx
var import_jsx_dev_runtime2 = __toESM(require_jsx_dev_runtime(), 1);
if (!window.$RefreshReg$ || !window.$RefreshSig$ || !window.$RefreshRuntime$) {
  console.warn("remix:hmr: React Fast Refresh only works when the Remix compiler is running in development mode.");
} else {
  prevRefreshReg = window.$RefreshReg$;
  prevRefreshSig = window.$RefreshSig$;
  window.$RefreshReg$ = (type, id) => {
    window.$RefreshRuntime$.register(type, '"app/routes/app+/project+/$projectId+/env+/$envId+/api-keys.tsx"' + id);
  };
  window.$RefreshSig$ = window.$RefreshRuntime$.createSignatureFunctionForTransform;
}
var prevRefreshReg;
var prevRefreshSig;
var _s2 = $RefreshSig$();
if (import.meta) {
  import.meta.hot = createHotContext(
    //@ts-expect-error
    "app/routes/app+/project+/$projectId+/env+/$envId+/api-keys.tsx"
  );
  import.meta.hot.lastModified = "1713199469916.5754";
}
var loader = withAuth(async ({
  api
}) => {
  const apiKeyDtos = await api.apiKey.apiKeyControllerGetApiKeysForProject();
  return (0, import_node.json)(apiKeyDtos);
});
function ApiKeysRoute() {
  _s2();
  const data = useLoaderData();
  const sortedEnvironments = sortApiKeys(data || []);
  return /* @__PURE__ */ (0, import_jsx_dev_runtime2.jsxDEV)(ApiKeysPage, { sortedEnvironments }, void 0, false, {
    fileName: "app/routes/app+/project+/$projectId+/env+/$envId+/api-keys.tsx",
    lineNumber: 37,
    columnNumber: 10
  }, this);
}
_s2(ApiKeysRoute, "5thj+e1edPyRpKif1JmVRC6KArE=", false, function() {
  return [useLoaderData];
});
_c2 = ApiKeysRoute;
var _c2;
$RefreshReg$(_c2, "ApiKeysRoute");
window.$RefreshReg$ = prevRefreshReg;
window.$RefreshSig$ = prevRefreshSig;
export {
  ApiKeysRoute as default
};
//# sourceMappingURL=/build/routes/app+/project+/$projectId+/env+/$envId+/api-keys-CFB6FJHR.js.map
