import { k as backupSetupInputs, a$ as runDeploy, aT as resolveDeployJournalPath, am as isSetupComplete, aZ as resolveStackDir, aE as readDeployJournal, aw as markSetupComplete } from './src-CidJbygh.js';

//#region src/lib/server/setup-deploy.ts
var _state = {
	deploying: false,
	setupComplete: false,
	deployStatus: [],
	deployError: null,
	imageWarning: null,
	phase: "writing-config"
};
var _deployPromise = null;
function deployStateFromJournal(state) {
	const journal = readDeployJournal(resolveDeployJournalPath(state));
	return {
		deploying: journal.deploying,
		interrupted: journal.interrupted,
		setupComplete: journal.setupComplete || isSetupComplete(resolveStackDir()),
		deployStatus: journal.deployStatus,
		deployError: journal.deployError,
		imageWarning: journal.imageWarning,
		phase: journal.phase
	};
}
function getDeployState(state) {
	if (state) _state = deployStateFromJournal(state);
	else if (!_state.setupComplete && !_state.deploying && isSetupComplete(resolveStackDir())) _state.setupComplete = true;
	return {
		..._state,
		deployStatus: _state.deployStatus.map((entry) => ({ ...entry }))
	};
}
function resetDeployState() {
	_state = {
		deploying: false,
		setupComplete: false,
		deployStatus: [],
		deployError: null,
		imageWarning: null,
		phase: "writing-config"
	};
}
function startDeploy(state) {
	if (_deployPromise) {
		_state.deployError = "install_in_progress: A deploy is already running. Wait for it to finish.";
		return;
	}
	_deployPromise = (async () => {
		await runDeploy(state, {
			journalPath: resolveDeployJournalPath(state),
			onUpdate(progress) {
				_state = {
					deploying: progress.deploying,
					interrupted: progress.interrupted,
					setupComplete: progress.setupComplete,
					deployStatus: progress.deployStatus,
					deployError: progress.deployError,
					imageWarning: progress.imageWarning,
					phase: progress.phase
				};
			},
			markSetupComplete() {
				markSetupComplete(state);
			}
		});
	})().finally(() => {
		_deployPromise = null;
	});
}
function prepareSetupRestorePoint(state) {
	return backupSetupInputs(state);
}

export { getDeployState as g, prepareSetupRestorePoint as p, resetDeployState as r, startDeploy as s };
//# sourceMappingURL=setup-deploy-B--th9ts.js.map
