// Copyright 2014 Apple Inc.  All Rights Reserved.
(function(){return function(e,r,t){if(!e||!r||!t)return CONTINUE;var a=Scanner.fromMessage(e);a.setLocale(r);var n,i,p,m,l,s,o,g,u,d,c,h,v,x,C,T,N,b,y,f,$,F,S=[],E={};i=a.getSpan().nextRegExp(regExpFormatted(/\1/,t.travellers)).nextAnyTag("table");var k=i.getTagNumber();if(i=i.allInnerTags("tr"+k).map(function(e){return e.allInnerTagsFiltered("td"+k)}),!i.length)return CONTINUE;m=a.getSpan().nextText(t.priceSummary).nextText(t.totalPrice).parentAnyTag("td").tagContents(),l=m.innerCapture(regExpFormatted(/\1.*?([\d,.]+)/,t.totalPrice),1),s=m.innerCapture(regExpFormatted(/\1.*?([^\d,.\s]+)/,t.totalPrice),1),o=a.getSpan().innerCapture(regExpFormatted(/\1 (\d+)/,t.reservationId),1),a.getSpan().nextRegExp(regExpFormatted(/\1/,t.cancelled)).exists()?g="Cancelled":a.getSpan().next(t.pending).exists()&&(g="Pending");for(var A=0;A<i.length;A++)p=i[A],n=p[0].innerCapture(/(.*)\s/,1).trim(),C=p[1].innerCapture(regExpFormatted(/^\1/,t.noProgramName))?null:p[1].innerCapture(/($<name>.*) ($<number>\w+)/),p[2]&&(x=p[2].innerCapture(regExpFormatted(/^\1.*?(\d+)/,t.ticketNumber),1)),E[""+n]={name:n,totalPrice:l,priceCurrency:s,seats:{},seatingType:{},programName:C?C.$name:null,membershipNumber:C?C.$number:null,ticketNumber:x};v=a.getSpan().nextRegExp(regExpFormatted(/\1/,t.travellers));for(var I=/^($<code>[A-Z]{3})\s+($<time>\d{1,2}(?::|\sh\s)\d{2}(?:am|pm)?)($<nextDay>\s+\+1)?/;v.nextText(t.totalTravelTime).exists();){v=v.nextText(t.totalTravelTime),c=a.getDetachedSpan((""+v.previousTag("td"+(k-1)).tagContents()).replace(",","")).innerDate(),v=v.nextTag("table"+k),h=v.allInnerTagsFiltered("td"+k);for(var P,D,z,R=0;P=h[R];R++)if(P.innerCapture(I)&&h[R+1]&&h[R+1].innerCapture(I)&&h[R+3]){P=P.innerCapture(I),f=P.$code,y=a.getDetachedSpan(""+c+" "+P.$time).innerDate(),D=h[R+1].innerCapture(I),z=D.$nextDay,F=D.$code,$=a.getDetachedSpan(((""+z).length?""+h[R+1].lastInnerDate():""+c)+" "+D.$time),h[R+1].nextText(t.checkin).exists()&&R++,/\d+/.test(""+h[R+2])||R++,T=h[R+2].innerCapture(/($<name>.*)\s($<flightNumber>\d+)/),N=T?T.$name.trim():null,b=T?T.$flightNumber:null,u=h[R+3].innerCapture(/($<type>.*?) \| ($<list>[^|]+)/);var U=u?u.$type:null;if(d=u&&u.$list.innerCapture(regExpFormatted(/^\1/,t.seat))?u.$list.innerCapture(regExpFormatted(/^\1 (.*)/,t.seat),1).split(",").map(function(e){return e.trim()}):null,valid(b)){i=Object.keys(E);for(var A=0;A<i.length;A++)valid(d)&&(E[i[A]].seats[""+b]=d[A]),valid(U)&&(E[i[A]].seatingType[""+b]=U)}ASSERT(N,b,f,y,F,$)&&S.push({airlineName:N,flightNumber:b,reservationId:o,reservationStatus:g,departureCode:f,departureTime:y,arrivalCode:F,arrivalTime:$,passengers:E})}}for(var O,M=[],R=0;R<S.length;R++){O=S[R];for(var j=Object.keys(O.passengers),w=0;w<j.length;w++){var L=O.passengers[j[w]],Z={"@context":"http://schema.org","@type":"http://schema.org/FlightReservation",reservationFor:{"@type":"http://apple.com/FuzzyFlight",airlineName:O.airlineName,airlineCode:O.airlineCode,flightNumber:O.flightNumber,departureAirportFuzzy:O.departureAirport,departureAirportCode:O.departureCode,departureTime:O.departureTime,arrivalAirportFuzzy:O.arrivalAirport,arrivalAirportCode:O.arrivalCode,arrivalTime:O.arrivalTime},underName:{"@type":"http://schema.org/Person",name:L.name},checkinUrl:O.checkinUrl,reservationId:O.reservationId,reservationStatus:"http://schema.org/Reservation"+(O.reservationStatus||"Confirmed"),totalPrice:L.totalPrice,priceCurrency:L.priceCurrency,reservedTicket:{"@type":"http://schema.org/Ticket",ticketNumber:L.ticketNumber,ticketedSeat:{"@type":"http://schema.org/Seat",seatNumber:L.seats[O.flightNumber],seatingType:L.seatingType[O.flightNumber]}}};valid(L.membershipNumber,L.programName)&&(Z.programMembershipUsed={"@type":"http://schema.org/ProgramMembership",membershipNumber:L.membershipNumber,programName:L.programName}),M.push(Z)}}return M.length?M:void 0}}).call();