/**
 * Handles the value to be set trimmed having no space entered first.
 * @param event The event is the change event value for the input elements.
 */
export const trimValue = (
    e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>
) => {
    const value = e.target.value.trimStart() // Remove leading spaces

    if (value === '') {
        e.target.value = ''
        return
    }

    e.target.value = value.replace(/\s+/g, ' ') // Replace multiple spaces with a single space
}

export function formatUtcToIst(timestamp: string): string {
  // Force UTC interpretation
  const date = new Date(timestamp.endsWith("Z") ? timestamp : `${timestamp}Z`);

  // IST offset = +5 hours 30 minutes
  const istTime = new Date(date.getTime() + 5.5 * 60 * 60 * 1000);

  const hours = istTime.getUTCHours().toString().padStart(2, "0");
  const minutes = istTime.getUTCMinutes().toString().padStart(2, "0");

  return `${hours}:${minutes}`;
}


