/***
 * Excerpted from "Developing for Apple Watch",
 * published by The Pragmatic Bookshelf.
 * Copyrights apply to this code. It may not be used to create training material, 
 * courses, books, articles, and the like. Contact us if you are in doubt.
 * We make no guarantees that this code is fit for any purpose. 
 * Visit http://www.pragmaticprogrammer.com/titles/jkwatch for more book information.
***/
//
//  LapDetailRowController.m
//  tapalap
//
//  Created by Jeff Kelley on 2/27/15.
//  Copyright (c) 2015 Pragmatic Bookshelf. All rights reserved.
//


#import "LapDetailRowController.h"


@interface LapDetailRowController ()

@property (weak) IBOutlet WKInterfaceLabel *lapNumberLabel;
@property (weak) IBOutlet WKInterfaceLabel *lapDurationLabel;

@property (readonly, nonatomic) NSDateComponentsFormatter *durationFormatter;

@end


@implementation LapDetailRowController

- (void)configureForLap:(NSTimeInterval)lapTime
                atIndex:(NSUInteger)lapIndex
{
    [self.lapDurationLabel setText:
     [self.durationFormatter stringFromTimeInterval:lapTime]];
    
    [self.lapNumberLabel setText:
     [NSString stringWithFormat:@"%lu", (unsigned long)lapIndex + 1]];
}

@synthesize durationFormatter = _durationFormatter;

- (NSDateComponentsFormatter *)durationFormatter
{
    if (_durationFormatter == nil) {
        _durationFormatter = [[NSDateComponentsFormatter alloc] init];
        _durationFormatter.unitsStyle = NSDateComponentsFormatterUnitsStylePositional;
    }
    return _durationFormatter;
}

@end
