//
//  WMWeixinShareView.m
//  Gengmei
//
//  Created by Sean Lee on 7/6/15.
//  Copyright (c) 2015 Wanmeichuangyi. All rights reserved.
//

#import "GMWeixinShareView.h"
#import "NSMutableDictionary+GMShareSDK.h"
#import "GMShareSDK.h"
#import "GMShareConstant.h"
@import GMPhobos;
@import GMKit;
@import GMFoundation;
@interface GMWeixinShareView ()
@property (weak, nonatomic) IBOutlet UITapGestureRecognizer *tapGestureRecognizer;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *shareViewBottomConstraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *shareViewHeight;
@end


@implementation GMWeixinShareView
+ (GMWeixinShareView *)shareView{
    GMWeixinShareView *shareView = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass([GMWeixinShareView class]) owner:nil options:nil].firstObject;
    shareView.shareViewHeight.constant = UIDevice.aspectRatioType == GMDeviceAspectRatioTypeWide ? 184 : 150;
    return shareView;
}

- (IBAction)shareButtonClicked:(UIButton *)button{
    [self hideShareView:nil];
    GMSharePlatform type = (GMSharePlatform)button.tag;
    //分享埋点
    [self weixin_click_share_channel:type];
    if (self.platformClick) {
        self.platformClick(type);
    }
}

- (void)showShareView:(id)sender {
    self.hidden = NO;
    self.tapGestureRecognizer.enabled = YES;
    [UIView animateWithDuration:0.25 animations:^{
        self.backgroundColor = [UIColor colorWithWhite:0 alpha:0.6];
        self.shareViewBottomConstraint.constant = [UIDevice aspectRatioType] == GMDeviceAspectRatioTypeWide ? 184 : 150;
        [self layoutIfNeeded];
    }];
}

- (IBAction)hideShareView:(id)sender {
    self.tapGestureRecognizer.enabled = NO;
    [UIView animateWithDuration:0.25 animations:^{
        self.backgroundColor = [UIColor colorWithWhite:0 alpha:0];
        self.shareViewBottomConstraint.constant = 0;
        [self layoutIfNeeded];
    } completion:^(BOOL finished) {
        self.hidden = YES;
    }];
}
//埋点
- (void)weixin_click_share_channel:(NSInteger)type {
    //type 3-微信好友, 4-朋友圈
    [Phobos track:@"weixin_click_share_channel" attributes:@{
            @"share_channel" : type == 3 ? @"微信好友" : @"朋友圈",
            @"from" : self.weixinShareObject.from.isNonEmpty ? self.weixinShareObject.from : @""}];
}

@end
