//
//  WPSearchViewController.m

#import "WPSearchViewController.h"
#import "WallPapaerADManager.h"
#define WPScreen_w  [UIScreen mainScreen].bounds.size.width
#define WPScreen_h [UIScreen mainScreen].bounds.size.height
#define WP_COLOR_WITH_HEX(HEX) [UIColor colorWithRed:((HEX >> 16) & 0xFF) / 255.0f green:((HEX >> 8) & 0xFF) / 255.0f blue:((HEX) & 0xFF) / 255.0f alpha:1.0f]
@interface WPSearchViewController ()<UITextFieldDelegate>
@property(nonatomic,strong)UIButton *backItem;
@property(nonatomic,strong)UIImageView *navImage;
@end

@implementation WPSearchViewController
- (void)backItemEvent{
    __weak typeof(self) weakSelf = self;
    [[WallPapaerADManager shareInstance] showIntersitialAD_Back:^(NSInteger actionType) {
        [weakSelf.navigationController popViewControllerAnimated:YES];
    }];
    
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController.navigationBar addSubview:self.backItem];
    [self.navigationController.navigationBar addSubview:self.navImage];
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self.backItem removeFromSuperview];
    [self.navImage removeFromSuperview];
}
- (instancetype)init
{
    self = [super init];
    if (self) {
        self.hidesBottomBarWhenPushed = YES;
    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.hidesBackButton = YES;
    UIImageView *bgImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, WPScreen_w, 360)];
    bgImage.image = [UIImage imageNamed:@"bgsearch"];
    bgImage.userInteractionEnabled = YES;
    [self.view addSubview:bgImage];
    
    UIButton *backItem = [[UIButton alloc] initWithFrame:CGRectMake(20, 0, 74, 44)];
    [backItem setImage:[UIImage imageNamed:@"backitem"] forState:UIControlStateNormal];
    [backItem addTarget:self action:@selector(backItemEvent) forControlEvents:UIControlEventTouchUpInside];
    self.backItem = backItem;
    
    UIImageView *navImage = [[UIImageView alloc] initWithFrame:CGRectMake(WPScreen_w-150, 8, 130, 28)];
    navImage.image = [UIImage imageNamed:@"navsearch"];
    self.navImage = navImage;
    
    UIView *tfBg = [[UIView alloc] initWithFrame:CGRectMake(40, bgImage.frame.size.height-70, bgImage.frame.size.width-80, 50)];
    tfBg.layer.cornerRadius = 25;
    tfBg.layer.masksToBounds = YES;
    tfBg.layer.borderColor = WP_COLOR_WITH_HEX(0xF78E9C).CGColor;
    tfBg.layer.borderWidth = 2;
    
    UITextField *wpsearch = [[UITextField alloc] initWithFrame:CGRectMake(30, 0, tfBg.frame.size.width-60, 50)];
    wpsearch.returnKeyType = UIReturnKeySearch;
    wpsearch.placeholder = @"请输入要搜索的壁纸";
    wpsearch.delegate = self;
    [tfBg addSubview:wpsearch];
    
    [bgImage addSubview:tfBg];
    
    UIImageView *nodata = [[UIImageView alloc] initWithFrame:CGRectMake((WPScreen_w-150)/2, 430, 150, 150)];
    nodata.image = [UIImage imageNamed:@"no"];
    [self.view addSubview:nodata];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField resignFirstResponder];
    return YES;
}
@end
