<commit_before>protocol ExploreFeedSettingsItem {
    var title: String { get }
    var subtitle: String? { get }
    var disclosureType: WMFSettingsMenuItemDisclosureType { get }
    var disclosureText: String? { get }
    var iconName: String? { get }
    var iconColor: UIColor? { get }
    var iconBackgroundColor: UIColor? { get }
    var controlTag: Int { get }
    var isOn: Bool { get }
    func updateSubtitle(for displayType: ExploreFeedSettingsDisplayType)
    func updateDisclosureText(for displayType: ExploreFeedSettingsDisplayType)
    func updateIsOn(for displayType: ExploreFeedSettingsDisplayType)
}

extension ExploreFeedSettingsItem {
    var subtitle: String? { return nil }
    var disclosureType: WMFSettingsMenuItemDisclosureType { return .switch }
    var disclosureText: String? { return nil }
    var iconName: String? { return nil }
    var iconColor: UIColor? { return nil }
    var iconBackgroundColor: UIColor? { return nil }
    func updateSubtitle(for displayType: ExploreFeedSettingsDisplayType) {

    }
    func updateDisclosureText(for displayType: ExploreFeedSettingsDisplayType) {

    }
    func updateIsOn(for displayType: ExploreFeedSettingsDisplayType) {
        
    }
}

enum ExploreFeedSettingsMasterType {
    case entireFeed
    case singleFeedCard(WMFContentGroupKind)
}

private extension WMFContentGroupKind {
    var masterSwitchTitle: String {
        switch self {
        case .news:
            return WMFLocalizedString("explore-feed-preferences-show-news-title", value: "Show In the news card", comment: "Text for the setting that allows users to toggle the visibility of the In the news card")
        case .featuredArticle:
            return WMFLocalizedString("explore-feed-preferences-show-featured-article-title", value: "Show Featured article card", comment: "Text for the setting that allows users to toggle the visibility of the Featured article card")
        case .topRead:
            return WMFLocalizedString("explore-feed-preferences-show-top-read-title", value: "Show Top read card", comment: "Text for the setting that allows users to toggle the visibility of the Top read card")
        case .onThisDay:
            return WMFLocalizedString("explore-feed-preferences-show-on-this-day-title", value: "Show On this day card", comment: "Text for the setting that allows users to toggle the visibility of the On this day card")
        case .pictureOfTheDay:
            return WMFLocalizedString("explore-feed-preferences-show-picture-of-the-day-title", value: "Show Picture of the day card", comment: "Text for the setting that allows users to toggle the visibility of the Picture of the day card")
        case .locationPlaceholder:
            fallthrough
        case .location:
            return WMFLocalizedString("explore-feed-preferences-show-places-title", value: "Show Places card", comment: "Text for the setting that allows users to toggle the visibility of the Places card")
        case .random:
            return WMFLocalizedString("explore-feed-preferences-show-randomizer-title", value: "Show Randomizer card", comment: "Text for the setting that allows users to toggle the visibility of the Randomizer card")
        case .continueReading:
            return WMFLocalizedString("explore-feed-preferences-show-continue-reading-title", value: "Show Continue reading card", comment: "Text for the setting that allows users to toggle the visibility of the Continue reading card")
        case .relatedPages:
            return WMFLocalizedString("explore-feed-preferences-show-related-pages-title", value: "Show Because you read card", comment: "Text for the setting that allows users to toggle the visibility of the Because you read card")
        default:
            assertionFailure("\(self) is not customizable")
            return ""
        }
    }
}

class ExploreFeedSettingsMaster: ExploreFeedSettingsItem {
    let title: String
    let controlTag: Int = -1
    var isOn: Bool = false
    let type: ExploreFeedSettingsMasterType

    init(for type: ExploreFeedSettingsMasterType) {
        self.type = type
        if case let .singleFeedCard(contentGroupKind) = type {
            title = contentGroupKind.masterSwitchTitle
            isOn = contentGroupKind.isInFeed
        } else {
            title = WMFLocalizedString("explore-feed-preferences-explore-tab", value: "Explore tab", comment: "Text for the setting that allows users to toggle whether the Explore tab is enabled or not")
            isOn = UserDefaults.wmf_userDefaults().defaultTabType == .explore
        }
    }

    func updateIsOn(for displayType: ExploreFeedSettingsDisplayType) {
        if case let .singleFeedCard(contentGroupKind) = type {
            isOn = contentGroupKind.isInFeed
        } else {
            isOn = UserDefaults.wmf_userDefaults().defaultTabType == .explore
        }
    }
}

struct ExploreFeedSettingsSection {
    let headerTitle: String?
    let footerTitle: String
    let items: [ExploreFeedSettingsItem]
}

class ExploreFeedSettingsLanguage: ExploreFeedSettingsItem {
    let title: String
    let subtitle: String?
    let controlTag: Int
    var isOn: Bool = false
    let siteURL: URL
    let languageLink: MWKLanguageLink

    init(_ languageLink: MWKLanguageLink, controlTag: Int, displayType: ExploreFeedSettingsDisplayType) {
        self.languageLink = languageLink
        title = languageLink.localizedName
        subtitle = languageLink.languageCode.uppercased()
        self.controlTag = controlTag
        siteURL = languageLink.siteURL()
        updateIsOn(for: displayType)
    }

    func updateIsOn(for displayType: ExploreFeedSettingsDisplayType) {
        switch (displayType) {
        case .singleLanguage:
            return
        case .multipleLanguages:
            isOn = languageLink.isInFeed
        case .detail(let contentGroupKind):
            isOn = languageLink.isInFeed(for: contentGroupKind)
        }
    }
}

class ExploreFeedSettingsGlobalCards: ExploreFeedSettingsItem {
    let disclosureType: WMFSettingsMenuItemDisclosureType = .switch
    let title: String = WMFLocalizedString("explore-feed-preferences-global-cards-title", value: "Global cards", comment: "Title for the setting that allows users to toggle non-language specific feed cards")
    let subtitle: String? = WMFLocalizedString("explore-feed-preferences-global-cards-description", value: "Non-language specific cards", comment: "Description of global feed cards")
    let controlTag: Int = -2
    var isOn: Bool = SessionSingleton.sharedInstance().dataStore.feedContentController.areGlobalContentGroupKindsInFeed

    func updateIsOn(for displayType: ExploreFeedSettingsDisplayType) {
        guard displayType == .singleLanguage || displayType == .multipleLanguages else {
            return
        }
        isOn = SessionSingleton.sharedInstance().dataStore.feedContentController.areGlobalContentGroupKindsInFeed
    }
}

enum ExploreFeedSettingsDisplayType: Equatable {
    case singleLanguage
    case multipleLanguages
    case detail(WMFContentGroupKind)
}

class BaseExploreFeedSettingsViewController: UIViewController {
    @IBOutlet weak var tableView: UITableView!
    @objc var dataStore: MWKDataStore?
    var theme = Theme.standard

    private var cellsToItemsThatNeedReloading = [WMFSettingsTableViewCell: ExploreFeedSettingsItem]()

    override var nibName: String? {
        return "BaseExploreFeedSettingsViewController"
    }

    open var displayType: ExploreFeedSettingsDisplayType = .singleLanguage

    override func viewDidLoad() {
        super.viewDidLoad()
        tableView.register(WMFSettingsTableViewCell.wmf_classNib(), forCellReuseIdentifier: WMFSettingsTableViewCell.identifier)
        tableView.register(WMFTableHeaderFooterLabelView.wmf_classNib(), forHeaderFooterViewReuseIdentifier: WMFTableHeaderFooterLabelView.identifier)
        tableView.contentInset = UIEdgeInsets(top: 10, left: 0, bottom: 0, right: 0)
        tableView.sectionFooterHeight = UITableViewAutomaticDimension
        tableView.estimatedSectionFooterHeight = 44
        apply(theme: theme)
        NotificationCenter.default.addObserver(self, selector: #selector(exploreFeedPreferencesDidSave(_:)), name: NSNotification.Name.WMFExploreFeedPreferencesDidSave, object: nil)
        NotificationCenter.default.addObserver(self, selector: #selector(newExploreFeedPreferencesWereRejected(_:)), name: NSNotification.Name.WMFNewExploreFeedPreferencesWereRejected, object: nil)<commit_msg>make cellsToItemsThatNeedReloading internal so that children can access it<commit_after>protocol ExploreFeedSettingsItem {
    var title: String { get }
    var subtitle: String? { get }
    var disclosureType: WMFSettingsMenuItemDisclosureType { get }
    var disclosureText: String? { get }
    var iconName: String? { get }
    var iconColor: UIColor? { get }
    var iconBackgroundColor: UIColor? { get }
    var controlTag: Int { get }
    var isOn: Bool { get }
    func updateSubtitle(for displayType: ExploreFeedSettingsDisplayType)
    func updateDisclosureText(for displayType: ExploreFeedSettingsDisplayType)
    func updateIsOn(for displayType: ExploreFeedSettingsDisplayType)
}

extension ExploreFeedSettingsItem {
    var subtitle: String? { return nil }
    var disclosureType: WMFSettingsMenuItemDisclosureType { return .switch }
    var disclosureText: String? { return nil }
    var iconName: String? { return nil }
    var iconColor: UIColor? { return nil }
    var iconBackgroundColor: UIColor? { return nil }
    func updateSubtitle(for displayType: ExploreFeedSettingsDisplayType) {

    }
    func updateDisclosureText(for displayType: ExploreFeedSettingsDisplayType) {

    }
    func updateIsOn(for displayType: ExploreFeedSettingsDisplayType) {
        
    }
}

enum ExploreFeedSettingsMasterType {
    case entireFeed
    case singleFeedCard(WMFContentGroupKind)
}

private extension WMFContentGroupKind {
    var masterSwitchTitle: String {
        switch self {
        case .news:
            return WMFLocalizedString("explore-feed-preferences-show-news-title", value: "Show In the news card", comment: "Text for the setting that allows users to toggle the visibility of the In the news card")
        case .featuredArticle:
            return WMFLocalizedString("explore-feed-preferences-show-featured-article-title", value: "Show Featured article card", comment: "Text for the setting that allows users to toggle the visibility of the Featured article card")
        case .topRead:
            return WMFLocalizedString("explore-feed-preferences-show-top-read-title", value: "Show Top read card", comment: "Text for the setting that allows users to toggle the visibility of the Top read card")
        case .onThisDay:
            return WMFLocalizedString("explore-feed-preferences-show-on-this-day-title", value: "Show On this day card", comment: "Text for the setting that allows users to toggle the visibility of the On this day card")
        case .pictureOfTheDay:
            return WMFLocalizedString("explore-feed-preferences-show-picture-of-the-day-title", value: "Show Picture of the day card", comment: "Text for the setting that allows users to toggle the visibility of the Picture of the day card")
        case .locationPlaceholder:
            fallthrough
        case .location:
            return WMFLocalizedString("explore-feed-preferences-show-places-title", value: "Show Places card", comment: "Text for the setting that allows users to toggle the visibility of the Places card")
        case .random:
            return WMFLocalizedString("explore-feed-preferences-show-randomizer-title", value: "Show Randomizer card", comment: "Text for the setting that allows users to toggle the visibility of the Randomizer card")
        case .continueReading:
            return WMFLocalizedString("explore-feed-preferences-show-continue-reading-title", value: "Show Continue reading card", comment: "Text for the setting that allows users to toggle the visibility of the Continue reading card")
        case .relatedPages:
            return WMFLocalizedString("explore-feed-preferences-show-related-pages-title", value: "Show Because you read card", comment: "Text for the setting that allows users to toggle the visibility of the Because you read card")
        default:
            assertionFailure("\(self) is not customizable")
            return ""
        }
    }
}

class ExploreFeedSettingsMaster: ExploreFeedSettingsItem {
    let title: String
    let controlTag: Int = -1
    var isOn: Bool = false
    let type: ExploreFeedSettingsMasterType

    init(for type: ExploreFeedSettingsMasterType) {
        self.type = type
        if case let .singleFeedCard(contentGroupKind) = type {
            title = contentGroupKind.masterSwitchTitle
            isOn = contentGroupKind.isInFeed
        } else {
            title = WMFLocalizedString("explore-feed-preferences-explore-tab", value: "Explore tab", comment: "Text for the setting that allows users to toggle whether the Explore tab is enabled or not")
            isOn = UserDefaults.wmf_userDefaults().defaultTabType == .explore
        }
    }

    func updateIsOn(for displayType: ExploreFeedSettingsDisplayType) {
        if case let .singleFeedCard(contentGroupKind) = type {
            isOn = contentGroupKind.isInFeed
        } else {
            isOn = UserDefaults.wmf_userDefaults().defaultTabType == .explore
        }
    }
}

struct ExploreFeedSettingsSection {
    let headerTitle: String?
    let footerTitle: String
    let items: [ExploreFeedSettingsItem]
}

class ExploreFeedSettingsLanguage: ExploreFeedSettingsItem {
    let title: String
    let subtitle: String?
    let controlTag: Int
    var isOn: Bool = false
    let siteURL: URL
    let languageLink: MWKLanguageLink

    init(_ languageLink: MWKLanguageLink, controlTag: Int, displayType: ExploreFeedSettingsDisplayType) {
        self.languageLink = languageLink
        title = languageLink.localizedName
        subtitle = languageLink.languageCode.uppercased()
        self.controlTag = controlTag
        siteURL = languageLink.siteURL()
        updateIsOn(for: displayType)
    }

    func updateIsOn(for displayType: ExploreFeedSettingsDisplayType) {
        switch (displayType) {
        case .singleLanguage:
            return
        case .multipleLanguages:
            isOn = languageLink.isInFeed
        case .detail(let contentGroupKind):
            isOn = languageLink.isInFeed(for: contentGroupKind)
        }
    }
}

class ExploreFeedSettingsGlobalCards: ExploreFeedSettingsItem {
    let disclosureType: WMFSettingsMenuItemDisclosureType = .switch
    let title: String = WMFLocalizedString("explore-feed-preferences-global-cards-title", value: "Global cards", comment: "Title for the setting that allows users to toggle non-language specific feed cards")
    let subtitle: String? = WMFLocalizedString("explore-feed-preferences-global-cards-description", value: "Non-language specific cards", comment: "Description of global feed cards")
    let controlTag: Int = -2
    var isOn: Bool = SessionSingleton.sharedInstance().dataStore.feedContentController.areGlobalContentGroupKindsInFeed

    func updateIsOn(for displayType: ExploreFeedSettingsDisplayType) {
        guard displayType == .singleLanguage || displayType == .multipleLanguages else {
            return
        }
        isOn = SessionSingleton.sharedInstance().dataStore.feedContentController.areGlobalContentGroupKindsInFeed
    }
}

enum ExploreFeedSettingsDisplayType: Equatable {
    case singleLanguage
    case multipleLanguages
    case detail(WMFContentGroupKind)
}

class BaseExploreFeedSettingsViewController: UIViewController {
    @IBOutlet weak var tableView: UITableView!
    @objc var dataStore: MWKDataStore?
    var theme = Theme.standard

    var cellsToItemsThatNeedReloading = [WMFSettingsTableViewCell: ExploreFeedSettingsItem]()

    override var nibName: String? {
        return "BaseExploreFeedSettingsViewController"
    }

    open var displayType: ExploreFeedSettingsDisplayType = .singleLanguage

    override func viewDidLoad() {
        super.viewDidLoad()
        tableView.register(WMFSettingsTableViewCell.wmf_classNib(), forCellReuseIdentifier: WMFSettingsTableViewCell.identifier)
        tableView.register(WMFTableHeaderFooterLabelView.wmf_classNib(), forHeaderFooterViewReuseIdentifier: WMFTableHeaderFooterLabelView.identifier)
        tableView.contentInset = UIEdgeInsets(top: 10, left: 0, bottom: 0, right: 0)
        tableView.sectionFooterHeight = UITableViewAutomaticDimension
        tableView.estimatedSectionFooterHeight = 44
        apply(theme: theme)
        NotificationCenter.default.addObserver(self, selector: #selector(exploreFeedPreferencesDidSave(_:)), name: NSNotification.Name.WMFExploreFeedPreferencesDidSave, object: nil)
        NotificationCenter.default.addObserver(self, selector: #selector(newExploreFeedPreferencesWereRejected(_:)), name: NSNotification.Name.WMFNewExploreFeedPreferencesWereRejected, object: nil)
{'fraction_non_alphanumeric': 0.07320644216691069, 'fraction_numerical': 0.001054172767203514, 'mean_word_length': 3.6963696369636962, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '934202', 'n_tokens_mistral': 4571, 'n_tokens_neox': 4451, 'n_words': 1292}