//
//  YHHKImmigrationRecordsVC.swift
//  galaxy
//
//  Created by alexzzw on 2024/9/14.
//  Copyright © 2024 https://www.galaxy-immi.com. All rights reserved.
//

import UIKit
import JXSegmentedView

class YHHKImmigrationRecordsVC: YHBaseViewController {
    
    private lazy var controllerOne: YHHKRecordsSummaryVC = YHHKRecordsSummaryVC()
    private lazy var controllerTwo: YHHKRecordsContentVC = YHHKRecordsContentVC()
    private lazy var controllerThree: YHHKRecordsContentVC = YHHKRecordsContentVC()
    private lazy var controllerFour: YHHKRecordsContentVC = YHHKRecordsContentVC()
    
    private lazy var arrItemTitles = ["汇总", "主申", "配偶", "子女"]
    
    private lazy var segmentedView: JXSegmentedView = {
        let view = JXSegmentedView(frame: CGRect(x: 0, y: k_Height_safeAreaInsetsTop(), width: KScreenWidth, height: 53))
        let indicator = JXSegmentedIndicatorLineView()
        indicator.indicatorWidth = 16
        indicator.indicatorHeight = 2
        indicator.indicatorColor = UIColor.brandMainColor
        indicator.indicatorCornerRadius = 0
        view.indicators = [indicator]
        view.dataSource = segmentedDataSource
        view.delegate = self
        return view
    }()
    
    private lazy var segmentedDataSource: JXSegmentedDotDataSource = {
        let dataSource = JXSegmentedDotDataSource()
        dataSource.isTitleColorGradientEnabled = true
        dataSource.titles = arrItemTitles
        dataSource.titleNormalFont = UIFont.PFSC_M(ofSize: 14)
        dataSource.titleNormalColor = UIColor(hexString: "#000000")!
        dataSource.titleSelectedFont = UIFont.PFSC_M(ofSize: 16)
        dataSource.titleSelectedColor = .mainTextColor
        dataSource.isItemSpacingAverageEnabled = false
        dataSource.itemWidth = JXSegmentedViewAutomaticDimension
        dataSource.itemSpacing = 24
        dataSource.dotStates = [false, false, false, false]
        dataSource.dotSize = CGSize(width: 6, height: 6)
        return dataSource
    }()
    
    private lazy var listContainerView: JXSegmentedListContainerView = {
        return JXSegmentedListContainerView(dataSource: self, type: .scrollView)
    }()
    
    private lazy var arrItemVCs: [JXSegmentedListContainerViewListDelegate] = {
        return [controllerOne, controllerTwo, controllerThree, controllerFour]
    }()
    
    private lazy var addNewButton: UIButton = {
        let button = UIButton(type: .custom)
        button.titleLabel?.font = UIFont.PFSC_M(ofSize: 16)
        let buttonName = "新增在港记录"
        button.setTitle(buttonName, for: .normal)
        button.setTitle(buttonName, for: .highlighted)
        button.setTitleColor( UIColor(hex:0xffffff), for: .normal)
        button.setTitleColor( UIColor(hex:0xffffff), for: .highlighted)
        button.addTarget(self, action: #selector(clickAddNewButton), for: .touchUpInside)
        button.layer.cornerRadius = kCornerRadius3
        button.clipsToBounds = true
        button.backgroundColor = .brandMainColor
        return button
    }()
    
    private lazy var bottomView: UIView = {
        let view = UIView()
        view.backgroundColor = .white
        return view
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        setupUI()
    }
}

extension YHHKImmigrationRecordsVC {
    private func setupUI() {
        gk_navBarAlpha = 1
        gk_navTitle = "在港记录列表"
        
        view.backgroundColor = .white
        view.addSubview(segmentedView)
        view.addSubview(bottomView)
        bottomView.addSubview(addNewButton)
        view.addSubview(listContainerView)
        
        segmentedView.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.top.equalTo(k_Height_NavigationtBarAndStatuBar)
            make.height.equalTo(53)
        }
        
        bottomView.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.right.equalToSuperview()
            make.bottom.equalTo(view.safeAreaLayoutGuide.snp.bottom)
            make.height.equalTo(64)
        }
        
        addNewButton.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(kMargin)
            make.right.equalToSuperview().offset(-kMargin)
            make.centerY.equalToSuperview()
            make.height.equalTo(48)
        }
        
        listContainerView.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.top.equalTo(segmentedView.snp.bottom)
            make.bottom.equalTo(bottomView.snp.top)
        }
    }
    
    @objc private func clickAddNewButton() {
        //
    }
}

extension YHHKImmigrationRecordsVC: JXSegmentedViewDelegate {
    //
}

extension YHHKImmigrationRecordsVC: JXSegmentedListContainerViewDataSource
{
    func numberOfLists(in listContainerView: JXSegmentedListContainerView) -> Int {
        if let titleDataSource = segmentedView.dataSource as? JXSegmentedBaseDataSource {
            return titleDataSource.dataSource.count
        }
        return 0
    }
    
    func listContainerView(_ listContainerView: JXSegmentedListContainerView, initListAt index: Int) -> any JXSegmentedListContainerViewListDelegate {
        return arrItemVCs[index]
    }
    
    //
}
