import {
  ApiKeysTable,
  sortApiKeys
} from "/build/_shared/chunk-ENCXM5GX.js";
import "/build/_shared/chunk-F5GZ2BM6.js";
import {
  Input
} from "/build/_shared/chunk-UBPDBSOY.js";
import {
  Label
} from "/build/_shared/chunk-LNJLDAPX.js";
import {
  Button
} from "/build/_shared/chunk-ZESRKRPI.js";
import "/build/_shared/chunk-HCRGASHR.js";
import {
  PageDocLink
} from "/build/_shared/chunk-TPFG27GP.js";
import "/build/_shared/chunk-4EISWT2J.js";
import "/build/_shared/chunk-D7HH3MFR.js";
import "/build/_shared/chunk-L7VKH6VP.js";
import "/build/_shared/chunk-4CHLX6OP.js";
import "/build/_shared/chunk-EEPFRJZL.js";
import "/build/_shared/chunk-MZIT35JI.js";
import {
  PageLayout
} from "/build/_shared/chunk-IVHXUM2B.js";
import {
  CheckCircledIcon
} from "/build/_shared/chunk-P2DAPPQF.js";
import "/build/_shared/chunk-W2WK7NJF.js";
import "/build/_shared/chunk-527IW2Z6.js";
import "/build/_shared/chunk-AI5FD5Y6.js";
import {
  useAppLayoutData
} from "/build/_shared/chunk-CUOCTUZ2.js";
import {
  require_jsx_dev_runtime
} from "/build/_shared/chunk-D5XSJF2M.js";
import {
  init_esm2 as init_esm,
  useFetcher,
  useLoaderData,
  useParams
} from "/build/_shared/chunk-VJFCZKPM.js";
import "/build/_shared/chunk-OCFPP4X2.js";
import {
  require_react
} from "/build/_shared/chunk-HWKMUXRS.js";
import {
  withAuth
} from "/build/_shared/chunk-RHQW4WCH.js";
import {
  require_node
} from "/build/_shared/chunk-MDLUSIM2.js";
import "/build/_shared/chunk-EB6A6RVQ.js";
import {
  Routes
} from "/build/_shared/chunk-5222SY3A.js";
import {
  createHotContext,
  init_remix_hmr
} from "/build/_shared/chunk-4FTV3JJX.js";
import "/build/_shared/chunk-YLRAJVC6.js";
import {
  __toESM
} from "/build/_shared/chunk-RODUX5XG.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();

// app/pages/apiKeys/ProviderApiKeys.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/ProviderApiKeys.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/ProviderApiKeys.tsx"
  );
  import.meta.hot.lastModified = "1715882071659.0623";
}
var ProviderApiKeys = ({
  provider,
  title,
  subtitle,
  link,
  initialKey,
  route
}) => {
  _s();
  const fetcher = useFetcher();
  const [key, setKey] = (0, import_react2.useState)(initialKey);
  const fetcherApiKey = provider === "openai" ? fetcher.data?.project.openaiApiKey : fetcher.data?.project.cohereApiKey;
  const isSaveDisabled = key === initialKey;
  const showSaved = fetcher.state === "idle" && fetcherApiKey && key.startsWith(fetcherApiKey.replaceAll("*", ""));
  const handleSubmit = () => {
    fetcher.submit({
      key
    }, {
      method: "POST",
      action: route,
      encType: "application/json"
    });
  };
  return /* @__PURE__ */ (0, import_jsx_dev_runtime.jsxDEV)("div", { className: "w-1/2", children: [
    /* @__PURE__ */ (0, import_jsx_dev_runtime.jsxDEV)(Label, { children: title }, void 0, false, {
      fileName: "app/pages/apiKeys/ProviderApiKeys.tsx",
      lineNumber: 53,
      columnNumber: 7
    }, this),
    /* @__PURE__ */ (0, import_jsx_dev_runtime.jsxDEV)("p", { className: "text-muted-foreground mb-2 text-sm", children: [
      subtitle,
      "\xA0",
      /* @__PURE__ */ (0, import_jsx_dev_runtime.jsxDEV)(PageDocLink, { to: link, children: "Get your keys here." }, void 0, false, {
        fileName: "app/pages/apiKeys/ProviderApiKeys.tsx",
        lineNumber: 55,
        columnNumber: 25
      }, this)
    ] }, void 0, true, {
      fileName: "app/pages/apiKeys/ProviderApiKeys.tsx",
      lineNumber: 54,
      columnNumber: 7
    }, this),
    /* @__PURE__ */ (0, import_jsx_dev_runtime.jsxDEV)("div", { className: "flex gap-2", children: [
      /* @__PURE__ */ (0, import_jsx_dev_runtime.jsxDEV)(Input, { placeholder: "API Key", value: key, onChange: (e) => setKey(e.target.value) }, void 0, false, {
        fileName: "app/pages/apiKeys/ProviderApiKeys.tsx",
        lineNumber: 58,
        columnNumber: 9
      }, this),
      /* @__PURE__ */ (0, import_jsx_dev_runtime.jsxDEV)(Button, { onClick: handleSubmit, 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/ProviderApiKeys.tsx",
          lineNumber: 60,
          columnNumber: 25
        }, this),
        showSaved ? "Saved" : "Save"
      ] }, void 0, true, {
        fileName: "app/pages/apiKeys/ProviderApiKeys.tsx",
        lineNumber: 59,
        columnNumber: 9
      }, this)
    ] }, void 0, true, {
      fileName: "app/pages/apiKeys/ProviderApiKeys.tsx",
      lineNumber: 57,
      columnNumber: 7
    }, this)
  ] }, void 0, true, {
    fileName: "app/pages/apiKeys/ProviderApiKeys.tsx",
    lineNumber: 52,
    columnNumber: 10
  }, this);
};
_s(ProviderApiKeys, "RE7Xmwg34CSpHI4qSL1nz84Rlms=", false, function() {
  return [useFetcher];
});
_c = ProviderApiKeys;
var _c;
$RefreshReg$(_c, "ProviderApiKeys");
window.$RefreshReg$ = prevRefreshReg;
window.$RefreshSig$ = prevRefreshSig;

// app/pages/apiKeys/ApiKeysPage.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/pages/apiKeys/ApiKeysPage.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/pages/apiKeys/ApiKeysPage.tsx"
  );
  import.meta.hot.lastModified = "1715882071658.6382";
}
var ApiKeysPage = ({
  sortedEnvironments
}) => {
  _s2();
  const params = useParams();
  const appLayoutData = useAppLayoutData();
  const initialOpenAIKey = appLayoutData?.project?.openaiApiKey;
  const initialCohereKey = appLayoutData?.project?.cohereApiKey;
  const breadcrumbs = [{
    label: "API Keys"
  }];
  return /* @__PURE__ */ (0, import_jsx_dev_runtime2.jsxDEV)(PageLayout, { breadcrumbs, children: /* @__PURE__ */ (0, import_jsx_dev_runtime2.jsxDEV)("div", { className: "flex flex-col gap-4", children: [
    /* @__PURE__ */ (0, import_jsx_dev_runtime2.jsxDEV)(ApiKeysTable, { sortedEnvironments, projectId: params.projectId }, void 0, false, {
      fileName: "app/pages/apiKeys/ApiKeysPage.tsx",
      lineNumber: 41,
      columnNumber: 9
    }, this),
    /* @__PURE__ */ (0, import_jsx_dev_runtime2.jsxDEV)(ProviderApiKeys, { provider: "openai", title: "OpenAI", subtitle: "Your OpenAI API key will only be used for Fine-Tuning.", link: "https://platform.openai.com/api-keys", initialKey: initialOpenAIKey, route: Routes.actions.project.setOpenAIKey(params.projectId) }, void 0, false, {
      fileName: "app/pages/apiKeys/ApiKeysPage.tsx",
      lineNumber: 42,
      columnNumber: 9
    }, this),
    /* @__PURE__ */ (0, import_jsx_dev_runtime2.jsxDEV)(ProviderApiKeys, { provider: "cohere", title: "Cohere", subtitle: "Your Cohere API key will only be used for Fine-Tuning.", link: "https://dashboard.cohere.com/api-keys", initialKey: initialCohereKey, route: Routes.actions.project.setCohereKey(params.projectId) }, void 0, false, {
      fileName: "app/pages/apiKeys/ApiKeysPage.tsx",
      lineNumber: 43,
      columnNumber: 9
    }, this)
  ] }, void 0, true, {
    fileName: "app/pages/apiKeys/ApiKeysPage.tsx",
    lineNumber: 40,
    columnNumber: 7
  }, this) }, void 0, false, {
    fileName: "app/pages/apiKeys/ApiKeysPage.tsx",
    lineNumber: 39,
    columnNumber: 10
  }, this);
};
_s2(ApiKeysPage, "FGN2Kv8QFqbXINmC/jlKcEw7TiQ=", false, function() {
  return [useParams, useAppLayoutData];
});
_c2 = ApiKeysPage;
var _c2;
$RefreshReg$(_c2, "ApiKeysPage");
window.$RefreshReg$ = prevRefreshReg;
window.$RefreshSig$ = prevRefreshSig;

// app/routes/app+/project+/$projectId+/env+/$envId+/api-keys.tsx
var import_jsx_dev_runtime3 = __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 _s3 = $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 = "1715882071671.9697";
}
var loader = withAuth(async ({
  api
}) => {
  const apiKeyDtos = await api.apiKey.apiKeyControllerGetApiKeysForProject();
  return (0, import_node.json)(apiKeyDtos);
});
function ApiKeysRoute() {
  _s3();
  const data = useLoaderData();
  const sortedEnvironments = sortApiKeys(data || []);
  return /* @__PURE__ */ (0, import_jsx_dev_runtime3.jsxDEV)(ApiKeysPage, { sortedEnvironments }, void 0, false, {
    fileName: "app/routes/app+/project+/$projectId+/env+/$envId+/api-keys.tsx",
    lineNumber: 37,
    columnNumber: 10
  }, this);
}
_s3(ApiKeysRoute, "5thj+e1edPyRpKif1JmVRC6KArE=", false, function() {
  return [useLoaderData];
});
_c3 = ApiKeysRoute;
var _c3;
$RefreshReg$(_c3, "ApiKeysRoute");
window.$RefreshReg$ = prevRefreshReg;
window.$RefreshSig$ = prevRefreshSig;
export {
  ApiKeysRoute as default
};
//# sourceMappingURL=/build/routes/app+/project+/$projectId+/env+/$envId+/api-keys-6G36IGWA.js.map
