// Copyright 2014 Apple Inc.  All Rights Reserved.
(function(){return function(e,t,r){var a=Scanner.fromMessage(e);a.setLocale(t);var n,i,p,g,o,u,x,l=[],d=[],s=[],h=1,m="Confirmed";g=a.getSpan().nextText(r.price).nextText("\n"),g=a.getSpan().withInterval(g.getEnd(),g.nextText("\n").getStart()),o=g.innerCapture(regExpFormatted(/([\d., ]+)/),1).trim(),u=g.innerCapture(regExpFormatted(/([^\d., ]+)/),1),n=a.getSpan().nextText(r.passenger).nextText("\n"),n=a.getSpan().withInterval(n.getEnd(),n.nextText(r.passengerSuffix).getStart()),p=a.getSpan().innerCapture(regExpFormatted(/\1\s*(\w*)\s/,r.reservationId),1);do ASSERT(n)&&d.push({name:n}),n=n.nextText("\n"),n=a.getSpan().withInterval(n.getEnd(),n.nextText("\n").getStart());while(n.getLength());for(i=a.getSpan().nextText(r.flight).nextText("[1]"),a.getSpan().nextText(r.limit).exists()?m="Pending":a.getSpan().nextText(r.cancel).exists()?m="Cancelled":a.getSpan().nextText(r.refund).exists()&&(m="Cancelled");i.exists();){var c,T,v,S={},z=i.nextDate(),f=i.nextRegExp(/([0-9A-Z]{2,3}?)\s?(\d{3,4})/).innerCapture(/([0-9A-Z]{2,3}?)\s?(\d{3,4})/);switch(S.airlineCode=f[1],""+S.airlineCode){case"ANA":S.airlineCode="NH"}S.flightNumber=f[2],T=S.flightNumber.nextDate(),c=S.flightNumber.nextDate().nextDate(),S.departureAirportFuzzy=a.getSpan().withInterval(S.flightNumber.getEnd(),T.previousText("(").getStart()).trim(),S.arrivalAirportFuzzy=a.getSpan().withInterval(S.flightNumber.nextText("-").getEnd(),c.previousText("(").getStart()).trim(),S.departureTime=getFuzzyDate(a.getDetachedSpan(z+" "+T)),S.arrivalTime=getFuzzyDate(a.getDetachedSpan(z+" "+c)),v=i.nextText(r.ticket),S.ticketNumber=a.getSpan().withInterval(v.getEnd(),v.nextText("\n").getStart()).trim(),ASSERT(S.arrivalAirportFuzzy,S.departureAirportFuzzy,S.flightNumber,S.departureTime,S.arrivalTime)&&l.push(S),h++,i=i.nextText("["+h+"]")}for(var y=0;y<l.length;y++)for(var A=l[y],C=0;C<d.length;C++){var F=d[C],N={"@context":"http://schema.org","@type":"http://schema.org/FlightReservation",reservationFor:{"@type":"http://apple.com/FuzzyFlight",airlineCode:A.airlineCode,flightNumber:A.flightNumber,departureAirportFuzzy:A.departureAirportFuzzy,departureAirportCode:A.departureAirportCode,departureTime:A.departureTime,arrivalAirportFuzzy:A.arrivalAirportFuzzy,arrivalAirportCode:A.arrivalAirportCode,arrivalTime:A.arrivalTime},underName:{"@type":"http://schema.org/Person",name:F.name},checkinUrl:x,reservationId:p,reservationStatus:"http://schema.org/Reservation"+m,totalPrice:o,priceCurrency:u,reservedTicket:{"@type":"http://schema.org/Ticket",ticketNumber:A.ticketNumber,ticketedSeat:{"@type":"http://schema.org/Seat",seatNumber:A.seatNumber,seatingType:""}}};s.push(N)}if(s.length)return s}}).call();