NewPaywallView.swift 7.35 KB
//
//  NewPaywallView.swift
//  Pro-Seecurity-VPN
//
//  Created by Volodymyr Kolomyltsev on 12/22/23.
//

import Foundation
import UIKit
import SnapKit

class OnboardingView: UIView {
    
    private let stackView: UIStackView = {
        let obj = UIStackView()
        obj.axis = .horizontal
        obj.distribution = .fillEqually
        obj.spacing = 15.sizeW
        return obj
    }()
    
    let closeButton: UIButton = {
        let obj = UIButton()
        obj.setImage(UIImage(systemName: "xmark"), for: .normal)
        obj.contentMode = .scaleToFill
        obj.tintColor = .white
        
        return obj
    }()
    
    let backgroundImageView: UIImageView = {
        let obj = UIImageView()
        let imageBackground = UIImage(named: "newPaywalBackground")
        obj.image = imageBackground
        return obj
    }()
    
    let scrollView: UIScrollView = {
        let obj = UIScrollView()
        obj.isScrollEnabled = true
        obj.showsHorizontalScrollIndicator = false
        obj.showsVerticalScrollIndicator = false
        obj.contentInsetAdjustmentBehavior = .always
        obj.isPagingEnabled = true
        obj.contentInset = .zero
        return obj
    }()
    
    private let snapPhotoPage: PageView = {
        let obj = PageView()
        obj.model = .snapPhotoSlide
        return obj
    }()
    
    private let submitPhotoPage: PageView = {
        let obj = PageView()
        obj.model = .submitPhotoSlide
        return obj
    }()
    
    private let getRewardsPhotoPage: PageView = {
        let obj = PageView()
        obj.model = .getRewardsSlide
        return obj
    }()
    
    let pageControl: UIPageControl = {
        let obj = UIPageControl()
        obj.numberOfPages = 3
        obj.currentPage = 0
        obj.clipsToBounds = true
        return obj
    }()
    
    let infoLabel: UILabel = {
       let obj = UILabel()
        obj.text = "3 дня бесплатной пробной версии, затем $9,99 в неделю"
        obj.font = .systemFont(ofSize: 12.sizeW, weight: .regular)
        obj.numberOfLines = 2
        obj.textAlignment = .center
        return obj
    }()
    
    private let buttonsStackView: UIStackView = {
        let obj = UIStackView()
        obj.axis = .horizontal
        obj.alignment = .center
        obj.distribution = .fillEqually
        obj.spacing = 6.sizeW
        return obj
    }()

    let restoreButton: UIButton = {
        let obj = UIButton()
        obj.setTitle("Restore", for: .normal)
        obj.setTitleColor(.white, for: .normal)
        obj.setTitleColor(.white, for: .highlighted)
        obj.titleLabel?.font = UIFont.systemFont(ofSize: 12.sizeW, weight: .regular)
        obj.titleLabel?.lineBreakMode = .byWordWrapping
        return obj
    }()
    
    let privacyButton: UIButton = {
        let obj = UIButton()
        obj.setTitle("Privacy", for: .normal)
        obj.setTitleColor(.white, for: .normal)
        obj.setTitleColor(.white, for: .highlighted)
        obj.titleLabel?.font = UIFont.systemFont(ofSize: 12.sizeW, weight: .regular)
        obj.titleLabel?.lineBreakMode = .byWordWrapping
        return obj
    }()

    
    let termsButton: UIButton = {
        let obj = UIButton()
        obj.setTitle("Terms", for: .normal)
        obj.setTitleColor(.white, for: .normal)
        obj.setTitleColor(.white, for: .highlighted)
        obj.titleLabel?.font = UIFont.systemFont(ofSize: 12.sizeW, weight: .regular)
        obj.titleLabel?.lineBreakMode = .byWordWrapping
        return obj
    }()
    
    let activateButton: UIButton = {
       let obj = UIButton()
        obj.backgroundColor = UIColor(red: 15/255, green: 125/255, blue: 255/255, alpha: 1)
        obj.layer.cornerRadius = 6.sizeH
        obj.titleLabel?.font = UIFont.systemFont(ofSize: 16.sizeW, weight: .bold)
        obj.setTitle("Activate Now", for: .normal)
        return obj
    }()
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setup()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
//        scrollView.contentInset.left = 10.sizeW
        scrollView.contentSize = CGSize(width: scrollView.bounds.width*3, height: scrollView.bounds.height)
    }
    
    private func setup() {
//        backgroundColor = .red
        addSubview(backgroundImageView)
        addSubview(scrollView)
        addSubview(pageControl)
        
        addSubview(infoLabel)
        addSubview(activateButton)
        addSubview(buttonsStackView)
        addSubview(closeButton)
        
        buttonsStackView.addArrangedSubview(privacyButton)
        buttonsStackView.addArrangedSubview(termsButton)
        buttonsStackView.addArrangedSubview(restoreButton)
        
        scrollView.addSubview(snapPhotoPage)
        scrollView.addSubview(submitPhotoPage)
        scrollView.addSubview(getRewardsPhotoPage)
        
//        scrollView.backgroundColor = .black
                
        pageControl.transform = CGAffineTransform(scaleX: 1.5, y: 1.5)
        
        closeButton.snp.makeConstraints { make in
            make.top.equalTo(safeAreaLayoutGuide.snp.top).offset(16.sizeH)
            make.leading.equalToSuperview().inset(16.sizeW)
            make.height.equalTo(24.sizeH)
        }
        
        backgroundImageView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        
        scrollView.snp.makeConstraints { make in
            make.top.equalTo(closeButton.snp.bottom).inset(-16.sizeH)
            make.trailing.leading.equalToSuperview()
            make.bottom.equalTo(pageControl.snp.top).offset(-16.sizeH)
        }
     
        pageControl.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.bottom.equalTo(activateButton.snp.top).offset(-60.sizeH)
            make.height.equalTo(16.sizeH)
        }
        
        snapPhotoPage.snp.makeConstraints { make in
            make.width.equalToSuperview()
            make.top.equalToSuperview()
            make.bottom.equalToSuperview()
            make.leading.equalToSuperview()
        }

        submitPhotoPage.snp.makeConstraints { make in
            make.width.equalToSuperview()
            make.top.equalToSuperview()
            make.bottom.equalToSuperview() 
            make.leading.equalTo(snapPhotoPage.snp.trailing)
        }

        getRewardsPhotoPage.snp.makeConstraints { make in
            make.width.equalToSuperview()
            make.top.equalToSuperview()
            make.bottom.equalToSuperview()
            make.leading.equalTo(submitPhotoPage.snp.trailing)
            make.trailing.equalToSuperview()
        }
        
        activateButton.snp.makeConstraints { make in
            make.leading.trailing.equalToSuperview().inset(16)
            make.height.equalTo(51.sizeH)
            make.bottom.equalTo(infoLabel.snp.top).offset(-24.sizeH)
        }
        
        infoLabel.snp.makeConstraints { make in
            make.leading.trailing.equalToSuperview().inset(16)
            make.height.equalTo(16.sizeH)
            make.bottom.equalTo(buttonsStackView.snp.top).offset(-43.sizeH)
        }
        
        buttonsStackView.snp.makeConstraints { make in
            make.bottom.equalTo(safeAreaLayoutGuide.snp.bottom).offset(-51.sizeH)
            make.leading.trailing.equalToSuperview().inset(16)
        }
    }
}