/* This program is free software: you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public License
   as published by the Free Software Foundation, either version 3 of
   the License, or (at your option) any later version.
   
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   
   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>. 
*/

otp.namespace("otp.planner");

/**
  * Web Map / TripPlanner
  */
try
{
otp.planner.ParamTemplate = 'fromPlace={[values.fromPlace.replace(/&/g,"@")]}'
        + '&toPlace={[values.toPlace.replace(/&/g,"@")]}'
        + '&arr={arriveBy}&min={opt}&maxWalkDistance={maxWalkDistance}&mode={mode}&itinID={itinID}&submit'
        + '&date={date}'
        + '&time={time}';

otp.planner.Templates = {
    TODO_FARE_ZONE : "2.30 - SEE BELOW - TODO PUT FARE ZONE IN XML",

    TP_ITINERARY : new Ext.XTemplate(
          '<p><a href="#">{id}</a>: {startTimeDisplay} - {endTimeDisplay} <tpl if="numTransfers"><br /><span class="transfers">({numTransfers} transbordo<tpl if="numTransfers != 1">s</tpl>, {duration} minuto<tpl if="duration != 1.0">s</tpl>)</span></tpl></p>'
    ).compile(),

    /**
     * templates for Trip Planner state messaging (eg: feedback emails, etc...).
     */
    // TODO - localize
//    tripFeedbackDetails : new Ext.XTemplate( 
//        'Trip Details: {fromPlace} to {toPlace} {arr} {time} on {date}, {opt} with a walk of {walk} via {mode}.'
//    ).compile(),
    tripFeedbackDetails : new Ext.XTemplate( 
        'Detalles del viaje: {[values.fromPlace.split("_")[0]]} a {[values.toPlace.split("_")[0]]} {arr} {time} el d\xEDa {date}, {opt} andando {walk} via {mode}.'
    ).compile(),

    tripPrintTemplate : new Ext.XTemplate( 
        '{url}?' + otp.planner.ParamTemplate
    ).compile(),

    TP_TRIPDETAILS : new Ext.XTemplate(
    '<div id="trip-details">',
    '<h3>Detalles del viaje:</h3>',
    '<table cellpadding="3" cellspacing="0" border="0">',
        '<tpl if="regularFare != null"><tr><td>Tarifa</td><td>{regularFare}</td></tr></tpl>',
        '<tr><td>Hora actual</td><td>{[new Date().format("D, j M H:i")]}</td></tr>',
        '<tr><td>Hora de salida</td><td>{startTimeDisplay}</td></tr>',
        '<tr><td>Tiempo</td><td>{duration} minuto<tpl if="duration != 1">s</tpl></td></tr>',
        '<tpl if="walkDistance != \'0 m\'"><tr><td>Andando</td><td>{walkDistance}</td></tr></tpl>',
    '</table></div>'
    ).compile(),

    TP_TRIPDETAILSBIKE : new Ext.XTemplate(
    '<div id="trip-details">',
    '<h3>Detalles del viaje:</h3>',
    '<table cellpadding="3" cellspacing="0" border="0">',
    	'<tpl if="regularFare != null"><tr><td>Tarifa</td><td>{regularFare}</td></tr></tpl>',
    	'<tr><td>Hora actual</td><td>{[new Date().format("D, j M H:i")]}</td></tr>',
    	'<tr><td>Hora de salida</td><td>{startTimeDisplay}</td></tr>',
    	'<tr><td>Tiempo</td><td>{duration} minuto<tpl if="duration != 1">s</tpl></td></tr>',
    	'<tpl if="walkDistance != \'0 m\'"><tr><td>En bicicleta</td><td>{walkDistance}</td></tr></tpl>',
    '</table></div>'
    ).compile(),

    TP_LEG_BASE_STR : ''
        + '<p><b>{startTimeDisplayShort}</b> Salida desde {fromName}'
        + '<tpl if="headsign != null && headsign.length &gt; 0"> ({headsign})</tpl>'
        + '<tpl if="fromStopId != null && fromStopId.length &gt; 0 && showStopIds"><br />Stop ID {fromStopId}</tpl>'
        + '</p>'
        + '<tpl if="duration != null"><div class="duration">{duration} minuto<tpl if="duration != 1.0">s</tpl></div></tpl>'
        + '<p><b>{endTimeDisplayShort}</b> Llegada a {toName}'
        + '<tpl if="toStopId != null && toStopId.length &gt; 0 && showStopIds"><br/>Stop ID {toStopId}</tpl>'
        + '</p>'
        + '<tpl if="alerts != null && alerts.length &gt; 0">'
        + '<tpl for="alerts">'
        +   '<p><br/><img src="images/ui/alert.gif" align="absmiddle"/> '
        +   '<b>Alert for route {parent.routeNumber}: </b>{.}</p>'
        + '</tpl>'
        + '</tpl>',
    //TODO
    TP_LEG_MODE : '<h4><a href="#">{[otp.locale.Spanish.modes[values["mode"]]]}</a> {routeName}</h4>',
    TP_LEG_CONTINUES : '<h4><a href="#">Continues as</a> {routeName} <span class="transfers">(stay on board)</span></h4>',

    m_transitLeg  : null,
    getTransitLeg : function()
    {
        if (this.m_transitLeg == null)
            this.m_transitLeg = new Ext.XTemplate(this.TP_LEG_MODE + this.TP_LEG_BASE_STR).compile();

        return this.m_transitLeg;
    },

    m_interlineLeg  : null,
    getInterlineLeg : function()
    {
        if (this.m_interlineLeg == null)
            this.m_interlineLeg = new Ext.XTemplate(this.TP_LEG_CONTINUES + this.TP_LEG_BASE_STR).compile();

        return this.m_interlineLeg;
    },

    TP_WALK_LEG : new Ext.XTemplate(
          '<h4><a href="#">Andar</a> {[otp.util.StringFormattingUtils.getDirection(values.direction)]} hasta {toName}</h4>',
          '<tpl if="toStopId != null && toStopId.length &gt; 0 && showStopIds"><p>Stop ID {toStopId}</p></tpl>',
          '<p class="transfers">Alrededor de {duration} minuto<tpl if="duration != 1.0">s</tpl> - {distance}</p>',
          '<ol class="steps"><tpl for="formattedSteps">',
              '{.}',
          '</tpl></ol>'
    ).compile(),
    
    TP_BICYCLE_LEG : new Ext.XTemplate(
            '<h4><a href="#">Bicicleta</a> {[otp.util.StringFormattingUtils.getDirection(values.direction)]} hasta {toName}</h4>',
            '<tpl if="toStopId != null && toStopId.length &gt; 0 && showStopIds"><p>Stop ID {toStopId}</p></tpl>',
            '<p class="transfers">Alrededor de {duration} minuto<tpl if="duration != 1.0">s</tpl> - {distance}</p>',
            '<ol class="steps"><tpl for="formattedSteps">',
                '{.}',
            '</tpl></ol>'
      ).compile(),
      
    TP_CAR_LEG : new Ext.XTemplate(
    		'<h4><a href="#">Coche</a> {[otp.util.StringFormattingUtils.getDirection(values.direction)]} hasta {toName}</h4>',
    		'<tpl if="toStopId != null && toStopId.length &gt; 0 && showStopIds"><p>Stop ID {toStopId}</p></tpl>',
    		'<p class="transfers">Alrededor de {duration} minuto<tpl if="duration != 1.0">s</tpl> - {distance}</p>',
    		'<ol class="steps"><tpl for="formattedSteps">',
    		'{.}',
    		'</tpl></ol>'
    ).compile(),
      
    TP_START : new Ext.XTemplate(
          '<h4><a href="#">Origen:</a> {name}</h4>'
    ).compile(), 

    TP_END : new Ext.XTemplate(
          '<h4><a href="#">Destino:</a> {name}</h4>'
    ).compile(), 

    CLASS_NAME: "otp.planner.Templates"
};
}
catch(e)
{
    console.log("planner.Templates Ext exception can be ignored -- just means you aren't including Ext.js in your app, which is OK");
}

