// Generate and return timezones as an array of options
import { OptionType } from '../types';

export default function () {
	// Get all time zones
    const timeZones = Intl.supportedValuesOf('timeZone');

	// Map timezone name and time
    const timeZoneOffsets = timeZones.map((timeZone) => {
        const date = new Date();
        const formatter = new Intl.DateTimeFormat('en-US', {
            timeZone,
            timeZoneName: 'short',
        });

        // Extract the time zone offset information
        const parts = formatter.formatToParts(date);
        const offset = parts.find((part) => part.type === 'timeZoneName').value;

        return <OptionType>{
			label: `${offset} ${timeZone}`,
			value: timeZone
		};
    });

    return timeZoneOffsets;
}
