//
//  YMCustServiceAlertView.m
//  PCDBank
//
//  Created by Gusont on 2021/8/17.
//  Copyright © 2021 SLAiELTS. All rights reserved.
//

#import "YMCustServiceAlertView.h"

@interface YMCustServiceAlertView()

@property (nonatomic, strong) UIView *bgView;

@property (nonatomic, strong) UIButton *cleanBtn;
@end

@implementation YMCustServiceAlertView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self confignUI];
    }
    return self;
}

- (void)confignUI
{
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.centerY.equalTo(self).offset(-20);
        make.left.mas_equalTo(16 * KScaleW);
    }];
    [self.cleanBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.width.height.mas_equalTo(40);
        make.top.equalTo(self.bgView.mas_bottom).offset(60);
    }];
    
    self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.3];
    self.bgView.layer.cornerRadius = 8.0f;
}

- (void)cleanBtnClick
{
    [self removeFromSuperview];
}

- (void)imageTap:(UIGestureRecognizer *)tap
{
//    YMModuleListQryDetails *qryDetail = [self.details objectAtIndex:tap.view.tag - 3000];
//    if (self.custServiceBtnBlock) {
//        self.custServiceBtnBlock(qryDetail);
//        [self removeFromSuperview];
//    }
}

//- (void)confignCustServiceViewWith:(NSArray<YMModuleListQryDetails *> *)details
//{
//    [self.bgView.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
//        [obj removeFromSuperview];
//    }];
//    self.details = details;
//    WS(weakSelf);
//    [details enumerateObjectsUsingBlock:^(YMModuleListQryDetails * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
//        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectZero];
//        imageView.isAccessibilityElement = YES;
//        imageView.accessibilityLabel = obj.voiceText;
//        [weakSelf.bgView addSubview:imageView];
//        [imageView sd_setImageWithURL:[YMUtil getCdnImageURL:obj.detailSpecifications.backgroudFilePath]];
//        [imageView mas_remakeConstraints:^(MASConstraintMaker *make) {
//            make.centerX.equalTo(weakSelf.bgView);
//            make.top.equalTo(weakSelf.bgView.mas_top).offset((16 + 116 * idx) * KScaleW);
//            make.height.mas_equalTo(100 * KScaleW);
//            make.left.mas_equalTo(16 * KScaleW);
//        }];
//        if (idx == details.count - 1) {
//            [imageView mas_updateConstraints:^(MASConstraintMaker *make) {
//                make.bottom.equalTo(weakSelf.bgView.mas_bottom).offset(-16 * KScaleW);
//            }];
//        }
//        imageView.tag = 3000 + idx;
//        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageTap:)];
//        imageView.userInteractionEnabled = YES;
//        [imageView addGestureRecognizer:tap];
//    }];
//}

- (UIView *)bgView
{
    if (!_bgView) {
        _bgView = [[UIView alloc] initWithFrame:CGRectZero];
        _bgView.backgroundColor = [UIColor whiteColor];
        [self addSubview:_bgView];
    }
    return _bgView;
}

- (UIButton *)cleanBtn
{
    if (!_cleanBtn) {
        _cleanBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_cleanBtn setImage:[UIImage imageNamed:@"icon3_clean_btn"] forState:UIControlStateNormal];
        [_cleanBtn addTarget:self action:@selector(cleanBtnClick) forControlEvents:UIControlEventTouchUpInside];
        _cleanBtn.accessibilityLabel = @"关闭";
        [self addSubview:_cleanBtn];
    }
    return _cleanBtn;
}

@end
