//
//  UIView+Basic.swift
//  Pods
//
//  Created by 100Years on 2025/3/6.
//

// Frame
public extension UIView {
    
    
    @IBInspectable
    public var cornerRadius: CGFloat {
        set {
            clipsToBounds = true
            layer.cornerRadius = newValue
        }
        get {
            layer.cornerRadius
        }
    }
    
    @IBInspectable
    public var borderWidth: CGFloat {
        set {
            layer.borderWidth = newValue
        }
        get {
            layer.borderWidth
        }
    }
    
    @IBInspectable
    public var borderColor: UIColor? {
        set {
            layer.borderColor = newValue?.cgColor
        }
        get {
            if let cgColor = layer.borderColor {
                return UIColor(cgColor: cgColor)
            }
            return nil
        }
    }
    
    
    var x: CGFloat {
        set {
            frame.origin.x = newValue
        }
        get {
            return frame.origin.x
        }
    }
    
    var y: CGFloat {
        set {
            frame.origin.y = newValue
        }
        get {
            return frame.origin.y
        }
    }
    
    var width: CGFloat {
        set {
            frame.size.width = newValue
        }
        get {
            return frame.size.width
        }
    }
    
    var height: CGFloat {
        set {
            frame.size.height = newValue
        }
        get {
            return frame.size.height
        }
    }
    
    var size: CGSize {
        get { frame.size }
        set {
            var rect = frame
            rect.size = newValue
            frame = rect
        }
    }
    
    var centerX: CGFloat {
        set {
            let newCenter = CGPoint(x: newValue, y: center.y)
            center = newCenter
        }
        get {
            return center.x
        }
    }
    
    var centerY: CGFloat {
        set {
            let newCenter = CGPoint(x: center.x, y: newValue)
            center = newCenter
        }
        get {
            return center.y
        }
    }
    
    var bottom: CGFloat {
        get {
            return frame.origin.y + frame.size.height
        }
    }
    
}

public extension UIScreen {
    static let size = {
        UIScreen.main.bounds.size
    }()
    
    static var width: CGFloat {
        return size.width
    }
    
    static var height: CGFloat {
        return size.height
    }
}
