import { ONE_MINUTE_MS, ONE_MINUTE_SECOND } from '../assets/data/adminConstants';

export const convertStartDateToISO = (date) => {
	if (!date) return null;
	const startDate = new Date(date);
	startDate.setHours(0, 0, 0, 0);
	return startDate.toISOString();
};

export const convertEndDateToISO = (date) => {
	if (!date) return null;
	const endDate = new Date(date);
	endDate.setHours(23, 59, 59, 999);
	return endDate.toISOString();
};

export const getSearchPeriodISO = (startDate, endDate) => {
	return {
		startDateISO: convertStartDateToISO(startDate),
		endDateISO: convertEndDateToISO(endDate)
	};
};

export const getTimeOnly = (dateString) => {
	const date = new Date(dateString);
	return date.toLocaleTimeString('ko-KR', {
		hour: '2-digit',
		minute: '2-digit',
		second: '2-digit',
		hour12: false
	});
};

export const getDateOnly = (dateString) => {
	const date = new Date(dateString);
	return date.toLocaleDateString('ko-KR', {
		year: 'numeric',
		month: '2-digit',
		day: '2-digit',
		timeZone: 'Asia/Seoul'
	}).replace(/\. /g, '-').replace('.', '');
}

export const msToMinutes = (ms) => {
	return ms / ONE_MINUTE_MS;
}

export const secondToMinutes = (second) => {
	return second / ONE_MINUTE_SECOND;
}

export const isValidDayRange = (start_dt, end_dt) => {
	const startDate = new Date(start_dt);
	const endDate = new Date(end_dt);

	// 시간을 00:00:00으로 설정하여 날짜만 비교
	const startDateOnly = new Date(startDate.getFullYear(), startDate.getMonth(), startDate.getDate());
	const endDateOnly = new Date(endDate.getFullYear(), endDate.getMonth(), endDate.getDate());

	const diffTime = endDateOnly.getTime() - startDateOnly.getTime();

	const oneDay = 24 * 60 * 60 * 1000;

	return diffTime >= oneDay;
}