//
//  FuelServiceItemCell.m
//  TopUp
//
//  Created by Frank Mcpherson on 5/29/10.
//  Copyright 2010 intrepidinnovations.com. All rights reserved.
//

#import "FuelServiceItemCell.h"
#import "FuelService.h"

@implementation FuelServiceItemCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) {
        serviceDateLabel = [[UILabel alloc] initWithFrame:CGRectZero];
		[[self contentView] addSubview:serviceDateLabel];
		[serviceDateLabel release];
		
		totalCostLabel = [[UILabel alloc] initWithFrame:CGRectZero];
		[[self contentView] addSubview:totalCostLabel];
		[totalCostLabel release];
    }
    return self;
}

- (void)layoutSubviews
{
	[super layoutSubviews];
	float inset = 5.0;
	CGRect bounds = [[self contentView] bounds];
	float h = bounds.size.height;
	float w = bounds.size.width;
	float innerWidth = w/2 - inset;
	
	CGRect innerFrame = CGRectMake(inset, inset, innerWidth, h - inset * 2.0);
	[serviceDateLabel setFrame:innerFrame];
	
	// Move it over and re-use 
	innerFrame.origin.x += innerWidth;
	[totalCostLabel setFrame:innerFrame];
}

- (void)setFuelService:(FuelService *)service
{
	NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
	[dateFormatter setDateStyle:NSDateFormatterShortStyle];
	[dateFormatter setTimeStyle:NSDateFormatterNoStyle];
	
	[serviceDateLabel setText:[dateFormatter stringFromDate:[service serviceDate]]];
	[totalCostLabel setText:[[service totalCost] stringValue]];
	[dateFormatter release];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {

    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}


- (void)dealloc {
    [super dealloc];
}


@end
