const CGFloat NAMapViewPinAnimationDuration = 0.5f;

@interface NAPinAnnotation ()
@property (nonatomic, readonly, weak) NAPinAnnotationView *view;
@end

@implementation NAPinAnnotation

- (id)initWithPoint:(CGPoint)point
{
    self = [super initWithPoint:point];
    if (self) {
        self.color = NAPinColorRed;
        self.title = nil;
        self.subtitle = nil;
        self.rightCalloutAccessoryView = nil;
    }
    return self;
}

- (UIView *)createViewOnMapView:(NAMapView *)mapView
{
    return [[NAPinAnnotationView alloc] initWithAnnotation:self onMapView:mapView];
}

- (void)addToMapView:(NAMapView *)mapView animated:(BOOL)animate
{
    [super addToMapView:mapView animated:animate];

    if (animate) {
        self.view.transform = CGAffineTransformTranslate(CGAffineTransformIdentity, 0.0f, -self.view.center.y);
    }

    [mapView addSubview:self.view];

    if (animate) {
        self.view.animating = YES;
        [UIView animateWithDuration:NAMapViewPinAnimationDuration animations:^{
            self.view.transform = CGAffineTransformIdentity;
        } completion:^ (BOOL finished) {
            self.view.animating = NO;
        }];
    }
}

- (void)updatePosition
{
    [self.view updatePosition];
}

@end
