<commit_before>//
//  RBSRealmObjectCell.swift
//  Pods
//
//  Created by <NAME> on 14/04/16.
//
//

import UIKit
import RealmSwift

protocol RBSRealmPropertyCellDelegate: AnyObject {
    func textFieldDidFinishEdit(_ input: String, property: Property)
}

internal final class RBSRealmPropertyCell: UITableViewCell {
    private lazy var circleView: UIView = {
        let view = UIView()
        view.backgroundColor = .random
        return view
    }()
    private lazy var labelPropertyTitle = {
        return labelWithAttributes(fontSize: 16, weight:0.3, text: "")
    }()
    private var textFieldPropValue: UITextField = {
        let textField  = UITextField()
        let spacing = UIView(frame:CGRect(x: 0.0, y: 0.0, width: 10.0, height: 0.0))
        spacing.backgroundColor = .clear
        textField.leftViewMode = .always
        textField.leftView = spacing
        textField.rightViewMode = .always
        textField.rightView = spacing
        textField.returnKeyType = .done
        textField.backgroundColor = .white
        textField.textAlignment = .right
        textField.autocorrectionType = .no
        return textField
    }()
    private lazy var labelPropertyType: UILabel = {
        let label = UILabel()
        label.font = UIFont.systemFont(ofSize: 14.0)
        label.textColor = .lightGray
        return label
    }()
    private lazy var toggle: UISwitch = {
        let toggle = UISwitch()
        toggle.addTarget(self, action: .toggleSwitch, for: .valueChanged)
        return toggle
    }()
    
    private var property: Property?
    weak var delegate: RBSRealmPropertyCellDelegate?
    
    private let margin: CGFloat = 20.0
    private let padding: CGFloat = 10.0
    private var disposables: [NSKeyValueObservation] = []
    @objc private dynamic var isEditingAllowed = false
    
    override init(style: CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        selectionStyle = .none
        UITextField.appearance().tintColor = RealmStyle.tintColor
        contentView.addSubview(textFieldPropValue)
        contentView.addSubview(circleView)
        contentView.addSubview(labelPropertyTitle)
        contentView.addSubview(labelPropertyType)
        toggle.frame = .zero
        disposables.append(
            toggle.observe(\.isHidden, onChange: { [weak self] (value) in
            self?.textFieldPropValue.isHidden = !value
        }))
        disposables.append(
            observe(\.isEditingAllowed, onChange: { [weak self] (value) in
                self?.textFieldPropValue.isUserInteractionEnabled = value
                self?.setTextFieldBorders(for: value)
            })
        )
        toggle.isHidden = true
        contentView.addSubview(toggle)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func prepareForReuse() {
        super.prepareForReuse()
        textFieldPropValue.text = ""
        labelPropertyTitle.text = ""
        labelPropertyType.text = ""
        textFieldPropValue.frame = .zero
        toggle.frame = .zero
        toggle.isHidden = true
    }
    <commit_msg>Disable toggle when not in edit mode<commit_after>//
//  RBSRealmObjectCell.swift
//  Pods
//
//  Created by <NAME> on 14/04/16.
//
//

import UIKit
import RealmSwift

protocol RBSRealmPropertyCellDelegate: AnyObject {
    func textFieldDidFinishEdit(_ input: String, property: Property)
}

internal final class RBSRealmPropertyCell: UITableViewCell {
    private lazy var circleView: UIView = {
        let view = UIView()
        view.backgroundColor = .random
        return view
    }()
    private lazy var labelPropertyTitle = {
        return labelWithAttributes(fontSize: 16, weight:0.3, text: "")
    }()
    private var textFieldPropValue: UITextField = {
        let textField  = UITextField()
        let spacing = UIView(frame:CGRect(x: 0.0, y: 0.0, width: 10.0, height: 0.0))
        spacing.backgroundColor = .clear
        textField.leftViewMode = .always
        textField.leftView = spacing
        textField.rightViewMode = .always
        textField.rightView = spacing
        textField.returnKeyType = .done
        textField.backgroundColor = .white
        textField.textAlignment = .right
        textField.autocorrectionType = .no
        return textField
    }()
    private lazy var labelPropertyType: UILabel = {
        let label = UILabel()
        label.font = UIFont.systemFont(ofSize: 14.0)
        label.textColor = .lightGray
        return label
    }()
    private lazy var toggle: UISwitch = {
        let toggle = UISwitch()
        toggle.addTarget(self, action: .toggleSwitch, for: .valueChanged)
        return toggle
    }()
    
    private var property: Property?
    weak var delegate: RBSRealmPropertyCellDelegate?
    
    private let margin: CGFloat = 20.0
    private let padding: CGFloat = 10.0
    private var disposables: [NSKeyValueObservation] = []
    @objc private dynamic var isEditingAllowed = false
    
    override init(style: CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        selectionStyle = .none
        UITextField.appearance().tintColor = RealmStyle.tintColor
        contentView.addSubview(textFieldPropValue)
        contentView.addSubview(circleView)
        contentView.addSubview(labelPropertyTitle)
        contentView.addSubview(labelPropertyType)
        toggle.frame = .zero
        disposables.append(
            toggle.observe(\.isHidden, onChange: { [weak self] (value) in
            self?.textFieldPropValue.isHidden = !value
        }))
        disposables.append(
            observe(\.isEditingAllowed, onChange: { [weak self] (value) in
                self?.textFieldPropValue.isUserInteractionEnabled = value
                self?.setTextFieldBorders(for: value)
                self?.toggle.isEnabled = value
            })
        )
        toggle.isHidden = true
        contentView.addSubview(toggle)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func prepareForReuse() {
        super.prepareForReuse()
        textFieldPropValue.text = ""
        labelPropertyTitle.text = ""
        labelPropertyType.text = ""
        textFieldPropValue.frame = .zero
        toggle.frame = .zero
        toggle.isHidden = true
    }
    
{'fraction_non_alphanumeric': 0.09099321406539174, 'fraction_numerical': 0.00863664404688464, 'mean_word_length': 2.4275898520084565, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3208814', 'n_tokens_mistral': 1900, 'n_tokens_neox': 1840, 'n_words': 420}