<commit_before>import Eureka
import RealmSwift

class NewItemViewController: FormViewController {

    var item: Item!
    var editingItem = false
    var notificationToken: NotificationToken?

    @IBAction func cancelButtonTapped(_ sender: UIBarButtonItem) {
        // Only delete the item on cancel if this is the first time the item is being added, not
        // when it is being edited.
        if !editingItem, let realm = item.realm {
            try! realm.write {
                realm.delete(item)
            }
        }

        dismiss()
    }

    struct RowTags {
        static let description = "description"
        static let brand = "brand"
        static let size = "size"
        static let cost = "cost"
        static let dateListed = "dateListed"
        static let listPrice = "listPrice"
        static let shippingCost = "shippingCost"
        static let suppliesCost = "suppliesCost"
        static let breakEven = "breakEven"
        static let fee = "fee"
        static let profit = "profit"
        static let sold = "sold"
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        if item != nil {
            editingItem = true
            title = "Edit Item"
        } else {
            item = Item()
        }

        form
        +++ Section("Item Details")
            <<< TextRow() { row in
                row.title = "Description"
                row.placeholder = "Cute T-Rex Sweater"
                row.tag = RowTags.description

                if item.itemDescription.characters.count > 0 {
                    row.value = item.itemDescription
                }
            }.onChange { row in
                if let value = row.value {
                    let realm = try! Realm()
                    try! realm.write {
                        realm.add(self.item, update: true)
                        self.item.itemDescription = value
                    }
                }
            }
            <<< TextRow() { row in
                row.title = "Brand"
                row.placeholder = "Carters"
                row.tag = RowTags.brand

                if item.brand.characters.count > 0 {
                    row.value = item.brand
                }
            }.onChange { row in
                if let value = row.value {
                    try! Realm().write {
                        self.item.brand = value
                    }
                }
            }
            <<< TextRow() { row in
                row.title = "Size"
                row.placeholder = "2T"
                row.tag = RowTags.size

                if item.size.characters.count > 0 {
                    row.value = item.size
                }
            }.onChange { row in
                if let value = row.value {
                    try! Realm().write {
                        self.item.size = value
                    }
                }
            }
            <<< DateRow() { row in
                row.title = "Date Listed"
                row.tag = RowTags.dateListed

                row.value = item.dateListed
            }.onChange { row in
                if let value = row.value {
                    try! Realm().write {
                        self.item.dateListed = value
                    }
                }
            }
            <<< SwitchRow() { row in
                row.title = "Sold?"
                row.tag = RowTags.sold<commit_msg>Changed Date Listed row to an inline date picker.<commit_after>import Eureka
import RealmSwift

class NewItemViewController: FormViewController {

    var item: Item!
    var editingItem = false
    var notificationToken: NotificationToken?

    @IBAction func cancelButtonTapped(_ sender: UIBarButtonItem) {
        // Only delete the item on cancel if this is the first time the item is being added, not
        // when it is being edited.
        if !editingItem, let realm = item.realm {
            try! realm.write {
                realm.delete(item)
            }
        }

        dismiss()
    }

    struct RowTags {
        static let description = "description"
        static let brand = "brand"
        static let size = "size"
        static let cost = "cost"
        static let dateListed = "dateListed"
        static let listPrice = "listPrice"
        static let shippingCost = "shippingCost"
        static let suppliesCost = "suppliesCost"
        static let breakEven = "breakEven"
        static let fee = "fee"
        static let profit = "profit"
        static let sold = "sold"
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        if item != nil {
            editingItem = true
            title = "Edit Item"
        } else {
            item = Item()
        }

        form
        +++ Section("Item Details")
            <<< TextRow() { row in
                row.title = "Description"
                row.placeholder = "Cute T-Rex Sweater"
                row.tag = RowTags.description

                if item.itemDescription.characters.count > 0 {
                    row.value = item.itemDescription
                }
            }.onChange { row in
                if let value = row.value {
                    let realm = try! Realm()
                    try! realm.write {
                        realm.add(self.item, update: true)
                        self.item.itemDescription = value
                    }
                }
            }
            <<< TextRow() { row in
                row.title = "Brand"
                row.placeholder = "Carters"
                row.tag = RowTags.brand

                if item.brand.characters.count > 0 {
                    row.value = item.brand
                }
            }.onChange { row in
                if let value = row.value {
                    try! Realm().write {
                        self.item.brand = value
                    }
                }
            }
            <<< TextRow() { row in
                row.title = "Size"
                row.placeholder = "2T"
                row.tag = RowTags.size

                if item.size.characters.count > 0 {
                    row.value = item.size
                }
            }.onChange { row in
                if let value = row.value {
                    try! Realm().write {
                        self.item.size = value
                    }
                }
            }
            <<< DateInlineRow() { row in
                row.title = "Date Listed"
                row.tag = RowTags.dateListed
                row.value = item.dateListed
            }.onChange { row in
                if let value = row.value {
                    try! Realm().write {
                        self.item.dateListed = value
                    }
                }
            }
            <<< SwitchRow() { row in
                row.title = "Sold?"
                row.tag = RowTags.sold
{'fraction_non_alphanumeric': 0.08274368231046932, 'fraction_numerical': 0.0011552346570397113, 'mean_word_length': 1.06684571769621, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 9, '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': '4803605', 'n_tokens_mistral': 1801, 'n_tokens_neox': 1666, 'n_words': 473}