//
//  UITextField.swift
//  Kalker
//

import Foundation
import UIKit

extension UITextField {
    
    func setDefaultTextField() {
        setBottomLine(borderColor: .white)
        self.tintColor = UIColor.white
    }
    
    func setBottomLine(borderColor: UIColor) {
        self.borderStyle = UITextBorderStyle.none
        self.backgroundColor = UIColor.clear
        
        let borderLine = UIView()
        let height = 1.0
        borderLine.frame = CGRect(x: 0, y: Double(self.frame.height) - height, width: Double(self.frame.width), height: height)
        
        borderLine.backgroundColor = borderColor
        self.addSubview(borderLine)
    }
}

extension UITextView {
    
    func addBottomBorderWithColor() {
        let border = UIView()
        border.frame = CGRect(x: self.frame.origin.x, y: self.frame.origin.y + self.frame.height, width: self.frame.width, height: 1.0)
        border.backgroundColor = UIColor.white
        self.superview!.insertSubview(border, aboveSubview: self)
        
        self.tintColor = UIColor.white
        self.backgroundColor = UIColor.clear
    }
    
    func setPlaceholder() {
        
        let placeholderLabel = UILabel()
        placeholderLabel.text = "Wprowadź opis"
        placeholderLabel.font = UIFont.systemFont(ofSize: 14.0)
        placeholderLabel.sizeToFit()
        placeholderLabel.tag = 222
        placeholderLabel.frame.origin = CGPoint(x: 0, y: (self.font?.pointSize)! / 2)
        placeholderLabel.textColor = UIColor.white
        placeholderLabel.isHidden = !self.text.isEmpty
        
        self.addSubview(placeholderLabel)
    }
    
    func checkPlaceholder() {
        let placeholderLabel = self.viewWithTag(222) as! UILabel
        placeholderLabel.isHidden = !self.text.isEmpty
    }
}

extension UILabel {
    
    func setRoundedLabel() {
        self.layer.cornerRadius = self.frame.width / 2
        self.clipsToBounds = true
    }
}
