<commit_before>////
///  StreamFooterCellPresenter.swift
//

import Foundation


enum InteractionVisibility {
    case enabled
    case selectedAndEnabled
    case selectedAndDisabled
    case disabled
    case hidden

    var isVisible: Bool { return self != .hidden }
    var isEnabled: Bool { return self == .enabled || self == .selectedAndEnabled }
    var isSelected: Bool { return self == .selectedAndDisabled || self == .selectedAndEnabled }
}


struct StreamFooterCellPresenter {

    static func configure(
        _ cell: UICollectionViewCell,
        streamCellItem: StreamCellItem,
        streamKind: StreamKind,
        indexPath: IndexPath,
        currentUser: User?)
    {
        guard
            let cell = cell as? StreamFooterCell,
            let post = streamCellItem.jsonable as? Post
        else { return }

        configureDisplayCounts(cell, post: post, streamKind: streamKind)
        configureToolBarItems(cell, post: post, currentUser: currentUser, streamKind: streamKind)
        configureCommentControl(cell, post: post, streamCellItem: streamCellItem, streamKind: streamKind, currentUser: currentUser)
    }

    fileprivate static func configureToolBarItems(
        _ cell: StreamFooterCell,
        post: Post,
        currentUser: User?,
        streamKind: StreamKind)
    {
        let ownPost = (currentUser?.id == post.authorId || (post.repostAuthor?.id != nil && currentUser?.id == post.repostAuthor?.id))

        let repostingEnabled = post.author?.hasRepostingEnabled ?? true
        var repostVisibility: InteractionVisibility = .enabled
        if post.reposted { repostVisibility = .disabled }
        else if !repostingEnabled { repostVisibility = .hidden }
        else if ownPost { repostVisibility = .disabled }

        let commentingEnabled = post.author?.hasCommentingEnabled ?? true
        let commentVisibility: InteractionVisibility = commentingEnabled ? .enabled : .hidden

        let sharingEnabled = post.author?.hasSharingEnabled ?? true
        let shareVisibility: InteractionVisibility = sharingEnabled ? .enabled : .hidden

        let lovingEnabled = post.author?.hasLovesEnabled ?? true
        var loveVisibility: InteractionVisibility = .enabled
        if post.loved { loveVisibility = .selectedAndEnabled }
        if !lovingEnabled { loveVisibility = .hidden }

        cell.updateToolbarItems(
            streamKind: streamKind,
            repostVisibility: repostVisibility,
            commentVisibility: commentVisibility,
            shareVisibility: shareVisibility,
            loveVisibility: loveVisibility
        )
    }

    fileprivate static func configureCommentControl(
        _ cell: StreamFooterCell,
        post: Post,
        streamCellItem: StreamCellItem,
        streamKind: StreamKind,
        currentUser: User?)
    {
        if streamKind.isDetail && currentUser == nil {
            if let count = post.commentsCount, count > 0 {
                cell.commentsOpened = true
                cell.commentsControl.isSelected = true
            }
        }
        else if streamKind.isDetail {
            cell.commentsOpened = true
            cell.commentsControl.isSelected = true
        }
        else {
            let isLoading = streamCellItem.state == .loading
            let isExpanded = streamCellItem.state == .expanded

            if isLoading {
                // this should be set via a custom accessor or method,
                // me thinks.<commit_msg>ensure recycled cells are reset<commit_after>////
///  StreamFooterCellPresenter.swift
//

import Foundation


enum InteractionVisibility {
    case enabled
    case selectedAndEnabled
    case selectedAndDisabled
    case disabled
    case hidden

    var isVisible: Bool { return self != .hidden }
    var isEnabled: Bool { return self == .enabled || self == .selectedAndEnabled }
    var isSelected: Bool { return self == .selectedAndDisabled || self == .selectedAndEnabled }
}


struct StreamFooterCellPresenter {

    static func configure(
        _ cell: UICollectionViewCell,
        streamCellItem: StreamCellItem,
        streamKind: StreamKind,
        indexPath: IndexPath,
        currentUser: User?)
    {
        guard
            let cell = cell as? StreamFooterCell,
            let post = streamCellItem.jsonable as? Post
        else { return }

        configureDisplayCounts(cell, post: post, streamKind: streamKind)
        configureToolBarItems(cell, post: post, currentUser: currentUser, streamKind: streamKind)
        configureCommentControl(cell, post: post, streamCellItem: streamCellItem, streamKind: streamKind, currentUser: currentUser)
    }

    fileprivate static func configureToolBarItems(
        _ cell: StreamFooterCell,
        post: Post,
        currentUser: User?,
        streamKind: StreamKind)
    {
        let ownPost = (currentUser?.id == post.authorId || (post.repostAuthor?.id != nil && currentUser?.id == post.repostAuthor?.id))

        let repostingEnabled = post.author?.hasRepostingEnabled ?? true
        var repostVisibility: InteractionVisibility = .enabled
        if post.reposted { repostVisibility = .disabled }
        else if !repostingEnabled { repostVisibility = .hidden }
        else if ownPost { repostVisibility = .disabled }

        let commentingEnabled = post.author?.hasCommentingEnabled ?? true
        let commentVisibility: InteractionVisibility = commentingEnabled ? .enabled : .hidden

        let sharingEnabled = post.author?.hasSharingEnabled ?? true
        let shareVisibility: InteractionVisibility = sharingEnabled ? .enabled : .hidden

        let lovingEnabled = post.author?.hasLovesEnabled ?? true
        var loveVisibility: InteractionVisibility = .enabled
        if post.loved { loveVisibility = .selectedAndEnabled }
        if !lovingEnabled { loveVisibility = .hidden }

        cell.updateToolbarItems(
            streamKind: streamKind,
            repostVisibility: repostVisibility,
            commentVisibility: commentVisibility,
            shareVisibility: shareVisibility,
            loveVisibility: loveVisibility
        )
    }

    fileprivate static func configureCommentControl(
        _ cell: StreamFooterCell,
        post: Post,
        streamCellItem: StreamCellItem,
        streamKind: StreamKind,
        currentUser: User?)
    {
        if streamKind.isDetail && currentUser == nil {
            let count = post.commentsCount ?? 0
            let open = count > 0
            cell.commentsOpened = open
            cell.commentsControl.isSelected = open
        }
        else if streamKind.isDetail {
            cell.commentsOpened = true
            cell.commentsControl.isSelected = true
        }
        else {
            let isLoading = streamCellItem.state == .loading
            let isExpanded = streamCellItem.state == .expanded

            if isLoading {
                // this should be set via a custom accessor or method,
                // me thinks.
{'fraction_non_alphanumeric': 0.07540137614678899, 'fraction_numerical': 0.00043004587155963305, 'mean_word_length': 2.42513500245459, 'pattern_counts': {'":': 0, '<': 3, '<?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': '376762', 'n_tokens_mistral': 1739, 'n_tokens_neox': 1686, 'n_words': 473}