//
//  InvitationAnswerPopupView
//  kneet
//
//  Created by Jason Lee on 6/15/15.
//  Copyright (c) 2015 ntels. All rights reserved.
//
#import "JDObject.h"
#import "CustomLabel.h"
#import "CustomCheckBox.h"

#import "InvitationAnswerPopupView.h"
#import "LoginModel.h"
#import "DatePickerButton.h"



@interface InvitationAnswerPopupView () {
}

@end

@implementation InvitationAnswerPopupView

- (id)initFromNib {

    for (UIView *view in [CommonUtil nibViews:@"InvitationAnswerPopupView"]) {
        if ([view isKindOfClass:[InvitationAnswerPopupView class]]) {
            self = (InvitationAnswerPopupView *)view;

            //XIB의 경우, 현재 화면 사이즈로 맞춰줘야 함.
            self.frame = [UIScreen mainScreen].bounds;

            self.lblTitle.text = NSLocalizedString(@"멤버 인증퀴즈", @"멤버 인증퀴즈");
            _btnDate.date = [NSDate date];
            _btnDate.placeHolder = _btnDate.dateString;
            
            [self.btnConfirm setTitle:NSLocalizedString(@"확인", @"확인") forState:UIControlStateNormal];
            [self.btnCancel setTitle:NSLocalizedString(@"취소", @"취소") forState:UIControlStateNormal];
        }
    }

    return self;
}

- (void)didMoveToSuperview {

}

- (void)setInvitation:(InvitationModel *)invitation {
    _invitation = invitation;
    
//    22, 16
//    18, 13 f
    //1. title height
    NSString *desc = [NSString stringWithFormat:NSLocalizedString(@"퀴즈를 맞춰서 [%@]의 홈 멤버가 되세요", @"퀴즈를 맞춰서 [%@]의 홈 멤버가 되세요"), _invitation.homegrpName];
    NSString *quiz = [NSString stringWithFormat:@"\"%@\"", _invitation.authorizationQuestion];
    
    CGFloat width = IPHONE_WIDTH - 62; //258
    CustomLabel *lblTemp = [[CustomLabel alloc] initWithFrame:CGRectMake(0, 0, width, 16)];
    lblTemp.font = [UIFont systemFontOfSize:kUIFontSize04];
    lblTemp.numberOfLines = 0;
    
    
    CGFloat adjustHeight = [CommonUtil getSizeFromString:desc font:lblTemp.font width:width].height;
    adjustHeight = adjustHeight < 16 ? 0 : adjustHeight - 16;


    CustomLabel *lblTemp2 = [[CustomLabel alloc] initWithFrame:CGRectMake(0, 0, width, 22)];
    lblTemp2.font = [UIFont systemFontOfSize:kUIFontSize05];
    lblTemp2.numberOfLines = 0;
    
    CGFloat adjustHeight2 = [CommonUtil getSizeFromString:quiz font:lblTemp2.font width:width].height;
    adjustHeight2 = adjustHeight2 < 22 ? 0 : adjustHeight2 - 22;
    
    _lblDesc.text = desc;
    _lblQuiz.text = quiz;
}

- (NSString *)selectedDate {
    return _btnDate.dateString ? _btnDate.dateString : ksEmptyString;
}

- (void)btnConfirmTouched:(id)sender {

    //validate
    if (!_btnDate.date) {
        [[JDFacade facade] alert:NSLocalizedString(@"날짜를 선택해주세요", @"날짜를 선택해주세요")];
        return;
    }

    [super btnConfirmTouched:sender];
}

@end
