import { Y as writable } from './internal-B3VUlLoc.js';

//#region src/lib/stores/app-settings.ts
var defaultAppSettings = {
	commitMessageProvider: "codex",
	commitMessageModel: "gpt-5.4-mini",
	timeFormat: "12h",
	dateFormat: "locale",
	telegramBotToken: null,
	telegramChatId: null
};
var appSettings = writable(defaultAppSettings);
var appSettingsLoading = writable(true);
var appSettingsError = writable(null);
async function updateAppSettings(patch) {
	const res = await fetch("/api/settings", {
		method: "PATCH",
		headers: { "Content-Type": "application/json" },
		body: JSON.stringify(patch)
	});
	if (!res.ok) {
		appSettingsError.set(await res.text());
		return null;
	}
	const settings = await res.json();
	appSettings.set(settings);
	return settings;
}
//#endregion
//#region src/lib/formatting.ts
function pad(value) {
	return String(value).padStart(2, "0");
}
function formatTime(value, format = "12h") {
	const date = new Date(value);
	if (isNaN(date.getTime())) return "—";
	if (format === "24h") return new Intl.DateTimeFormat(void 0, {
		hour: "2-digit",
		minute: "2-digit",
		hour12: false
	}).format(date);
	return new Intl.DateTimeFormat(void 0, {
		hour: "2-digit",
		minute: "2-digit",
		hour12: true
	}).format(date);
}
function formatDate(value, format = "locale") {
	const date = new Date(value);
	if (isNaN(date.getTime())) return "—";
	const year = date.getFullYear();
	const month = pad(date.getMonth() + 1);
	const day = pad(date.getDate());
	switch (format) {
		case "iso": return `${year}-${month}-${day}`;
		case "us": return `${month}/${day}/${year}`;
		case "eu": return `${day}/${month}/${year}`;
		case "long": return new Intl.DateTimeFormat(void 0, {
			year: "numeric",
			month: "long",
			day: "numeric"
		}).format(date);
		default: return new Intl.DateTimeFormat(void 0, {
			year: "numeric",
			month: "short",
			day: "numeric"
		}).format(date);
	}
}
function formatDateTime(value, dateFormat = "locale", timeFormat = "12h") {
	return `${formatDate(value, dateFormat)} ${formatTime(value, timeFormat)}`;
}

export { appSettings as a, formatTime as b, appSettingsLoading as c, defaultAppSettings as d, formatDateTime as f, updateAppSettings as u };
//# sourceMappingURL=formatting-Cq2KfAoL.js.map
