import UIKit
import SwiftUI

extension UISegmentedControl {
    open override func didMoveToSuperview() {
        super.didMoveToSuperview()

        self.setContentHuggingPriority(.defaultLow, for: .vertical)
        applyGlobalStyle()
    }

    /// Removes default system blue style on iOS 26+ and applies a light gray tint to selected segment
    private func applyGlobalStyle() {
        if #available(iOS 26.0, *) {
            selectedSegmentTintColor = UIColor.gray.withAlphaComponent(0.2)
            
            DispatchQueue.main.async {
                for subview in self.subviews {
                    if subview is UIImageView && subview != self.subviews.last {
                        subview.alpha = 0
                    }
                }
            }
        }
    }
}
