import { createRequire as _createRequire } from 'node:module';
const require = _createRequire(import.meta.url);
import {
  syncLatestTypes
} from "./chunk-UC4R2FMF.js";
import {
  useProjectModel
} from "./chunk-VLXZIAOF.js";
import "./chunk-SR7TTQEG.js";
import {
  useVeloClient
} from "./chunk-R5WNFZTS.js";
import "./chunk-RFWFU5ZV.js";
import "./chunk-C7TVBDR6.js";
import "./chunk-KDZXPOOF.js";
import "./chunk-QRGKMYDD.js";
import "./chunk-MHV22UIU.js";
import "./chunk-BRX4HWJE.js";
import {
  usePanoramaMethodLogger
} from "./chunk-ZBFOAJ5H.js";
import "./chunk-YNEGRO3E.js";
import {
  pRetry,
  useAuth
} from "./chunk-YHFCDWGT.js";
import "./chunk-IVQPYJ5M.js";
import {
  Trans,
  useTranslation
} from "./chunk-MDUBZZTI.js";
import "./chunk-RPTAJN5Y.js";
import {
  Spinner,
  useAsync
} from "./chunk-QK47PIWK.js";
import {
  require_react
} from "./chunk-TODKQSCF.js";
import "./chunk-AFPDHQYI.js";
import "./chunk-HYKBBZLS.js";
import "./chunk-C5RTKQVL.js";
import "./chunk-DGJS6KZB.js";
import "./chunk-YT5BPQDJ.js";
import "./chunk-LU3R3EBR.js";
import {
  getTestOverrides
} from "./chunk-XZUGLEBK.js";
import {
  outputDir,
  outputFile
} from "./chunk-AYCGCYN3.js";
import "./chunk-SDLCFZRL.js";
import {
  CliError,
  CliErrorCode,
  require_lib
} from "./chunk-WGV2XQSB.js";
import {
  __toESM,
  init_esm_shims
} from "./chunk-EXLZF52D.js";

// ../cli-site-live/src/components/DevCommand/DevCommand.tsx
init_esm_shims();
var import_react5 = __toESM(require_react(), 1);

// ../cli-site-live/src/components/DevCommand/InitializingState.tsx
init_esm_shims();
var import_react3 = __toESM(require_react(), 1);
var import_variant = __toESM(require_lib(), 1);

// ../cli-site-live/src/velo-types-sync-client/useVeloTypesSyncClient.ts
init_esm_shims();
var import_react = __toESM(require_react(), 1);

// ../cli-site-live/src/velo-types-sync-client/velo-types-sync-client.ts
init_esm_shims();
var VeloTypesSyncClient = class {
  constructor(projectFolder, getToken) {
    this.projectFolder = projectFolder;
    this.getToken = getToken;
    const { minRetryTimeout } = getTestOverrides();
    this.retryOptions = {
      retries: 3,
      minTimeout: minRetryTimeout,
      maxTimeout: 3 * 1e3
    };
  }
  retryOptions;
  syncLatestTypes = async () => {
    const token = await this.getToken();
    try {
      await pRetry(
        () => syncLatestTypes(this.projectFolder, {
          getAppToken: () => token
        }),
        this.retryOptions
      );
    } catch (e) {
      throw new CliError({
        code: CliErrorCode.FailedToSyncPagesTypes(),
        cause: e
      });
    }
  };
};

// ../cli-site-live/src/velo-types-sync-client/useVeloTypesSyncClient.ts
function useVeloTypesSyncClient(projectFolder) {
  const { getAccessToken } = useAuth();
  const client = (0, import_react.useMemo)(
    () => new VeloTypesSyncClient(projectFolder, getAccessToken),
    [projectFolder, getAccessToken]
  );
  return usePanoramaMethodLogger(client);
}

// ../cli-site-live/src/project-files-service/useProjectFilesService.ts
init_esm_shims();
var import_react2 = __toESM(require_react(), 1);

// ../cli-site-live/src/project-files-service/project-files-service.ts
init_esm_shims();
import { join } from "node:path";
var ProjectFilesService = class {
  constructor(projectFolder) {
    this.projectFolder = projectFolder;
  }
  addDir = async (file) => {
    const filePath = this.getFullPath(file);
    await outputDir(filePath);
  };
  saveFile = async (file) => {
    const filePath = this.getFullPath(file);
    await outputFile(filePath, file.content);
  };
  getFullPath = (file) => join(this.projectFolder, file.path);
};

// ../cli-site-live/src/project-files-service/useProjectFilesService.ts
var useProjectFilesService = () => {
  const { projectFolder } = useProjectModel();
  return (0, import_react2.useMemo)(() => new ProjectFilesService(projectFolder), [projectFolder]);
};

// ../cli-site-live/src/components/DevCommand/InitializingState.tsx
var InitializingState = ({ children }) => {
  const { t } = useTranslation();
  const veloClient = useVeloClient();
  const projectFilesService = useProjectFilesService();
  const { veloAppId, projectFolder } = useProjectModel();
  const veloTypeSyncer = useVeloTypesSyncClient(projectFolder);
  const { status } = useAsync(async () => {
    async function initProjectFiles() {
      const { files, directories } = await veloClient.listAppFiles(veloAppId);
      await Promise.all([
        ...directories.map(projectFilesService.addDir),
        ...files.map(projectFilesService.saveFile)
      ]);
    }
    await Promise.all([initProjectFiles(), veloTypeSyncer.syncLatestTypes()]);
  }, []);
  return (0, import_variant.match)(status, {
    Success: () => children,
    Error: () => null,
    Loading: () => /* @__PURE__ */ import_react3.default.createElement(Spinner, { text: t("dev_command.init.fetching_files") })
  });
};

// ../cli-site-live/src/components/DevCommand/ReadyState.tsx
init_esm_shims();
var import_react4 = __toESM(require_react(), 1);
var ReadyState = () => {
  return /* @__PURE__ */ import_react4.default.createElement(Trans, { i18nKey: "dev_command.welcome" });
};

// ../cli-site-live/src/components/DevCommand/DevCommand.tsx
var DevCommand = () => {
  return /* @__PURE__ */ import_react5.default.createElement(InitializingState, null, /* @__PURE__ */ import_react5.default.createElement(ReadyState, null));
};
export {
  DevCommand
};
//# sourceMappingURL=DevCommand-2SYVKEP5.js.map