export const convertKTC = (dt, nation = true) => {
	if (!dt) return "";
	if (typeof dt !== "string") return "";

	const date = new Date(dt.endsWith("Z") ? dt : `${dt}Z`);
	const options = {
		year: 'numeric',
		month: '2-digit',
		day: '2-digit',
		hour: '2-digit',
		minute: '2-digit',
		hour12: true, // 오전/오후 형식을 위해 true 설정
		timeZone: 'Asia/Seoul',
	};

	return nation ? date.toLocaleString('ko-KR', options) + " KST" : date.toLocaleString('ko-KR', options);
}

export const convertKTCDate = (dt) => {
	if(!dt) return "";
	const date = new Date(dt);
	date.setHours(date.getHours() + 9);
	return date;
}

export const convertUTC = (dt) => {
	if (!dt) return null;
	const date = new Date(dt);
	return new Date(date.setHours(date.getHours() - 9));
}

export const combineDateTime = (date, hour, min) => {
	if (!date) return null;
	return new Date(date.getFullYear(), date.getMonth(), date.getDate(), hour, min);
};

export const timeDiffMinute = (mainDt, subDt) => {
	const main_data = new Date(mainDt);
	const sub_data = new Date(subDt);
	return (main_data.getTime() - sub_data.getTime()) / 1000 / 60
}

export const formatStringDate = (date) => {
	const year = date.getFullYear();
	const month = String(date.getMonth() + 1).padStart(2, '0');
	const day = String(date.getDate()).padStart(2, '0');

	return `${year}-${month}-${day}`;
}

export const truncateText = (text) => {
	const maxLength = 30;
	if (text.length > maxLength) {
		return text.substring(0, maxLength) + '...';
	}
	return text;
};