//
//  HistoryViewCell.m
//  DrivoMeter
//
//  Created by Mobi on 2/1/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "HistoryViewCell.h"
#import "Trip.h"
#import "NSDate+Extensions.h"

@implementation HistoryViewCell

@synthesize tripTypeLabel = tripTypeLabel_;
@synthesize dateLabel = dateLabel_;
@synthesize distanceLabel = distanceLabel_;
@synthesize purposeLabel = purposeLabel_;
@synthesize favoriteView = favoriteView_;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)fillWithTrip:(Trip *)trip {
  if (trip.isBusinessValue) {
    [tripTypeLabel_ setText:NSLocalizedString(@"history.cell.trip.type.business", nil)];    
  }
  else {
    [tripTypeLabel_ setText:NSLocalizedString(@"history.cell.trip.type.private", nil)];    
  }
  if (trip.favorite != nil) {
    [self addSubview:favoriteView_];
  } else {
    [favoriteView_ removeFromSuperview];
  }
  
  NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  [dateFormatter setDateFormat:@"dd.MM.yyyy"];
  
  NSString *tripDate = [dateFormatter stringFromDate:trip.beginDate];
  NSString *weekDay = [NSDate weekdayFromDate:trip.beginDate];
  [dateLabel_ setText:[NSString stringWithFormat:@"%@, %@", weekDay, tripDate]];
  [distanceLabel_ setText:[NSString stringWithFormat:NSLocalizedString(@"trip.view.distance.state.label.text", nil), trip.distanceValue]];  
  [purposeLabel_ setText:trip.purpose];
}

@end
