//
//  NaviAlphaHandle.swift

//
//  Created by Leon on 2025/7/20.
//

import UIKit

struct NaviAlphaHandle {
    static func changeNaviTitleAlpha(scrollView: UIScrollView, titleLabel: UILabel?) {
        guard let label = titleLabel else{
            return
        }
        let offsetY = scrollView.contentOffset.y
        if offsetY >= 0 && offsetY <= 60 {
            label.alpha = offsetY / 60.0
        } else if offsetY < 0 {
            label.alpha = 0
        } else {
            label.alpha = 1
        }
    }
    
    static func changeNaviTitleAlpha(scrollView: UIScrollView, alphaViews: [UIView?]) {
        let offsetY = scrollView.contentOffset.y
        if offsetY >= 0 && offsetY <= 60 {
            for view in alphaViews {
                if let v = view{
                    v.alpha = offsetY / 60.0
                }
            }
        } else if offsetY < 0 {
            for view in alphaViews {
                if let v = view{
                    v.alpha = 0
                }
            }
        } else {
            for view in alphaViews {
                if let v = view{
                    v.alpha = 1
                }
            }
        }
    }
    
    static func changeNaviViewsAlpha(scrollView: UIScrollView, alphaViews: [UIView?], oppositeViews: [UIView?]) {
        let offsetY = scrollView.contentOffset.y
        if offsetY >= 0 && offsetY <= 60 {
            for view in alphaViews {
                if let v = view{
                    v.alpha = offsetY / 60.0
                }
            }
            for view in oppositeViews {
                if let v = view{
                    v.alpha = 1 - offsetY / 60.0
                }
            }
        } else if offsetY < 0 {
            for view in alphaViews {
                if let v = view{
                    v.alpha = 0
                }
            }
            for view in oppositeViews {
                if let v = view{
                    v.alpha = 1
                }
            }
        } else {
            for view in alphaViews {
                if let v = view{
                    v.alpha = 1
                }
            }
            for view in oppositeViews {
                if let v = view{
                    v.alpha = 0
                }
            }
        }
    }
}
