//
//  InputBoxView.swift
//  MobilePortal
//
//  Created by caiyang on 2020/4/9.
//  Copyright © 2020 yin chen. All rights reserved.
//

import UIKit

class InputBoxView: UIView {

    var block:selectBlock!
    
    lazy var bagImageView: UIImageView = {
        let bagImageView = UIImageView.init()
        bagImageView.contentMode = .scaleToFill
        bagImageView.image = UIImage.init(named: "input_image")
        self.addSubview(bagImageView)
        return bagImageView
    }()
    lazy var dialogueTextF: UITextField = {
        let dialogueTextF = UITextField.init()
//        dialogueTextF.clearButtonMode = .always
        dialogueTextF.keyboardType = .default
//        dialogueTextF.backgroundColor = UIColor.red
        self.addSubview(dialogueTextF)
        return dialogueTextF
    }()
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = UIColor.white
        bagImageView.frame = CGRect(x:13.33, y: 6.67, width:SCREEN_WHIDTH()-26.66 , height:33.33 )
        dialogueTextF.frame = bagImageView.frame
        addDoneBUttonOnKeyboard()
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    func addDoneBUttonOnKeyboard(){
        let doneToolbar = UIToolbar()
        let flexSpace = UIBarButtonItem.init(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)
        let done:UIBarButtonItem = UIBarButtonItem.init(title: "发送", style: .done, target: self, action: #selector(doneButtonAction))
        var items:[UIBarButtonItem] = []
        items.append(flexSpace)
        items.append(done)
        doneToolbar.items = items
        doneToolbar.sizeToFit()
        dialogueTextF.inputAccessoryView = doneToolbar
    }
    @objc func doneButtonAction(){
//        dialogueTextF.resignFirstResponder()
//        print(dialogueTextF.text)
        self.block()
    }
    
}
