// Copyright 2014 Apple Inc.  All Rights Reserved.
(function(){return function(e,r){var t=Scanner.fromMessage(e);t.setLocale(r);var a,i,n,p,m,o,l,s,g,h,u,d,c,v,f,T=[],N={};p=t.getSpan().innerCapture(/Dear ($<wholeName>(.*?)(?: and (.*))?),/);var b=p.$wholeName.trim(),S=""+t.getSpan().innerCapture(regExpFormatted(/\1 SkyMiles #($<membershipNumber>\d+)/,""+b),1);p=p.slice(2).filter(function(e){return valid(e)});for(var x,y=0;x=p[y++];)N[""+x.trim()]={name:""+x.trim(),membershipNumber:S,programName:"SkyMiles",seats:{},seatingType:{}};i=t.getSpan().innerCapture(/Delta Confirmation #(\w+)/,1),n=t.getSpan().innerCapture(/Your flight (?:.*) is available for check ?-?in <(.*)>/,1);for(var C=["One","Two","Three","Four","Five","Six","Seven","Eight"],$=0,D=t.getSpan().nextText("Flight Status"),A=function(e){e.innerText("UPGRADE").exists()&&(e=e.withStart(e.innerText("UPGRADE").getEnd()));var r=e.allInnerTags("table7").map(function(e){return e.allInnerTagsFiltered("td7")});if(r.length%3===0)for(var a=0,i=r.length/3;a<i;a++){if(m=r[3*a][0],l=r[3*a][1].innerCapture(/^($<airlineName>.*) ($<flightNumber>\d+)/),s=l?l.$airlineName:null,o=l?l.$flightNumber:null,h=r[3*a+1][0].innerCapture(/Departs ($<time>\d{1,2}:\d{2} (?:am|pm)) ($<airport>.*)/),h&&(u=t.getDetachedSpan(""+m+" "+h.$time).innerDate(),d=h.$airport),c=r[3*a+1][1].innerCapture(/Arrives ($<time>\d{1,2}:\d{2} (?:am|pm)) (?:\(($<nextDate>.*)\) )?($<airport>.*)/),c&&(v=t.getDetachedSpan((not(c.$nextDate)?""+m:""+c.$nextDate)+" "+c.$time),f=c.$airport),r[3*a+2].length){var n=r[3*a+2][0].innerCapture(/Seat ([\w,\s]+)/,1).trim();if(n){n=n.split(", ");for(var p,b=Object.keys(N),S=0;p=b[S];S++)N[p].seats[o]=n[S]}}g=/delta/gi.test(s)?"DL":null,ASSERT(g,s,o,d,u,f,v)&&T.push({airlineCode:g,airlineName:s,flightNumber:o,departureAirport:d,departureTime:u,arrivalAirport:f,arrivalTime:v,passengers:N})}};D.nextText("Trip "+C[$]).exists()&&$<C.length;)A(D.withEnd(D.nextText("Trip "+C[$]).getEnd())),D=D.nextText("Trip "+C[$]),$++;A(D.withEnd(t.getSpan().nextText("Thank you for choosing Delta.").getEnd()));for(var k=[],y=0;y<T.length;y++)for(var F=T[y],E=Object.keys(F.passengers),w=0;w<E.length;w++){var z=F.passengers[E[w]],P={"@context":"http://schema.org","@type":"http://schema.org/FlightReservation",reservationFor:{"@type":"http://apple.com/FuzzyFlight",airlineName:F.airlineName,airlineCode:F.airlineCode,flightNumber:F.flightNumber,departureAirportFuzzy:F.departureAirport,departureAirportCode:F.departureCode,departureTime:F.departureTime,arrivalAirportFuzzy:F.arrivalAirport,arrivalAirportCode:F.arrivalCode,arrivalTime:F.arrivalTime},underName:{"@type":"http://schema.org/Person",name:z.name},checkinUrl:n,reservationId:i,reservationStatus:"http://schema.org/ReservationConfirmed",totalPrice:z.totalPrice,priceCurrency:z.priceCurrency,reservedTicket:{"@type":"http://schema.org/Ticket",ticketNumber:a,ticketedSeat:{"@type":"http://schema.org/Seat",seatNumber:z.seats[F.flightNumber],seatingType:z.seatingType[F.flightNumber]}}};valid(z.membershipNumber,z.programName)&&(P.programMembershipUsed={"@type":"http://schema.org/ProgramMembership",membershipNumber:z.membershipNumber,programName:z.programName}),k.push(P)}if(k.length)return k}}).call();