//
//  CWLoadingView.swift
//  ColorfulWallpaper
//
//  Created by nkl on 2024/9/11.
//

import Foundation
import UIKit

class CWLoadingView: UIView {
    lazy var activityIndicator: UIActivityIndicatorView = {
        let activityIndicator = UIActivityIndicatorView(style: .medium)
        activityIndicator.color = .white
        return activityIndicator
    }()
        
    fileprivate var topOffset: CGFloat = 20


    override init(frame: CGRect) {
        super.init(frame: frame)
        addChildren()
        makeConstraints()
        startLoading()
        
    }

    public func startLoading() {
        activityIndicator.startAnimating()
    }

    public func stopLoading() {
        activityIndicator.stopAnimating()
    }

    private func addChildren() {
        addSubview(activityIndicator)
    }

    private func makeConstraints() {
        activityIndicator.snp.makeConstraints { make in
            make.width.height.equalTo(50)
            make.centerX.equalToSuperview()
            make.top.equalToSuperview().offset(self.topOffset)
        }
    }

    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

