function [cur_time,f] = UTM_next_event(flights)
% UTM_next_event - get nest discrete event
% On input:
%     flights (flight struct): flight info
% On output:
%     cur_time (float): current time in simulation
%     f (int): flight index
% Call:
%     [cur_time,f] = UTM_next_event(flights);
% Author:
%     T. Henderson
%     UU
%     summer 2020
%

WAITING = 1;
IN_FLIGHT = 0;
DONE = -1;

cur_time = 0;
f = 0;

list = [];
num_flights = length(flights);
for k = 1:num_flights
    if flights(k).status==WAITING
        list = [list; k, flights(k).start_time];
    elseif flights(k).status==IN_FLIGHT
        lane_index = flights(k).lane_index;
        TOA = flights(k).TOA(lane_index);
        list = [list; k, TOA];
    end
end
[vals,indexes] = sort(list(:,2));
cur_time = list(indexes(1),2);
f = list(indexes(1),1);
tch = 0;
