//
//  CommonEditorCellImg.m
//  RedAnt ERP Mobile
//
//  Created by Ray on 11/4/15.
//  Copyright © 2015 United Software Applications, Inc. All rights reserved.
//

#import "CommonEditorCellImg.h"

#import "RAUtils.h"

#import "ImageUploadViewController.h"
#import "ImageViewController.h"

@implementation CommonEditorCellImg

- (void)awakeFromNib {
    self.touchImageView0.delegate=self;

    self.touchImageView1.delegate=self;

    self.touchImageView2.delegate=self;

    self.imgs= [@[@"", @"",@""] mutableCopy];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}
- (void)TouchImageViewOnTouche:(TouchImageView *)touchImageView
{
    __block int tag = touchImageView.tag;
    UIViewController* vc=[RAUtils getViewController :touchImageView];
    
    if(self.editable==true)
    {
        
        
        ImageUploadViewController * uploadvc =[ vc.storyboard instantiateViewControllerWithIdentifier:@"ImageUploadViewController"];
        
        //        UIImage* img =[self.buttonImg backgroundImageForState:UIControlStateNormal];;
        
        if(self.img_validate)
            uploadvc.img= touchImageView.image;
        
        uploadvc.returnValue = ^(NSString* url_down,NSString* url_up,UIImage* img)
        {
            
            self.imgs[tag] = url_up;
            
            NSString* newurl=[RAUtils arr2string:self.imgs separator:@"," trim:false];
            
            touchImageView.image=img;
            
            if(self.imgChanged)
                self.imgChanged(url_down,newurl,tag,url_up);
            
        };
        
        [vc.navigationController pushViewController:uploadvc animated:false];
    }
    else
    {
        if(touchImageView.image==nil)
            return ;
        ImageViewController * imagevc =[ vc.storyboard instantiateViewControllerWithIdentifier:@"ImageViewController"];
        
        
        UIImage* img=touchImageView.image;
        
        if(self.img_validate)
            imagevc.image = img;//.imageView.image = [self.buttonImg backgroundImageForState:UIControlStateNormal];
        
        //        uploadvc.returnValue = ^(NSString* url_down,NSString* url_up,UIImage* img)
        //        {
        //
        //            [self.buttonImg setBackgroundImage:img forState:UIControlStateNormal];
        //
        //            if(self.imgChanged)
        //                self.imgChanged(url_down,url_up);
        //
        //        };
        
        [vc.navigationController pushViewController:imagevc animated:false];
    }
    //    bundleVC.content_data = self.bundle_item;
    
    
}
//- (IBAction)ImgButtonClicked:(UIButton *)sender {
//
//    __block int tag = sender.tag;
//    UIViewController* vc=[RAUtils getViewController :sender];
//
//    if(self.editable==true)
//    {
//
//
//    ImageUploadViewController * uploadvc =[ vc.storyboard instantiateViewControllerWithIdentifier:@"ImageUploadViewController"];
//
////        UIImage* img =[self.buttonImg backgroundImageForState:UIControlStateNormal];;
//
//    if(self.img_validate)
//    uploadvc.img= [sender backgroundImageForState:UIControlStateNormal];
//
//    uploadvc.returnValue = ^(NSString* url_down,NSString* url_up,UIImage* img)
//    {
//
//        [sender setBackgroundImage:img forState:UIControlStateNormal];
//
//        if(self.imgChanged)
//            self.imgChanged(url_down,url_up,tag);
//
//    };
//
//    [vc.navigationController pushViewController:uploadvc animated:false];
//    }
//    else
//    {
//        ImageViewController * imagevc =[ vc.storyboard instantiateViewControllerWithIdentifier:@"ImageViewController"];
//
//
//        UIImage* img=[sender backgroundImageForState:UIControlStateNormal];
//
//        if(self.img_validate)
//        imagevc.image = img;//.imageView.image = [self.buttonImg backgroundImageForState:UIControlStateNormal];
//
////        uploadvc.returnValue = ^(NSString* url_down,NSString* url_up,UIImage* img)
////        {
////
////            [self.buttonImg setBackgroundImage:img forState:UIControlStateNormal];
////
////            if(self.imgChanged)
////                self.imgChanged(url_down,url_up);
////
////        };
//
//        [vc.navigationController pushViewController:imagevc animated:false];
//    }
////    bundleVC.content_data = self.bundle_item;
//
//
//}
//
//
//-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
//{
//    if(self.editable==true)
//        return;
//    self.isFullScreen = !self.isFullScreen;
//    UITouch *touch = [touches anyObject];
//
//    CGPoint touchPoint = [touch locationInView:self.contentView];
//
//    CGPoint imagePoint = self.imageView.frame.origin;
//    //touchPoint.x ，touchPoint.y 就是触点的坐标
//
//    // 触点在imageView内，点击imageView时 放大,再次点击时缩小
//    if(imagePoint.x <= touchPoint.x && imagePoint.x +self.imageView.frame.size.width >=touchPoint.x && imagePoint.y <=  touchPoint.y && imagePoint.y+self.imageView.frame.size.height >= touchPoint.y)
//    {
//        // 设置图片放大动画
//        [UIView beginAnimations:nil context:nil];
//        // 动画时间
//        [UIView setAnimationDuration:1];
//
//        if (self.isFullScreen) {
//            // 放大尺寸
//
//            self.buttonImg.frame = CGRectMake(0, 0, 768, 1024);
//        }
//        else {
//            // 缩小尺寸
//            self.buttonImg.frame = CGRectMake(50, 65, 100, 100);
//        }
//
//        // commit动画
//        [UIView commitAnimations];
//
//    }
//
//}
@end
