package com.yidian.shenghuoquan.newscontent.widget

import android.content.Context
import android.graphics.Color
import android.util.AttributeSet
import android.view.View
import com.yidian.nightmode.widget.YdConstraintLayout
import com.yidian.shenghuoquan.newscontent.R
import com.yidian.shenghuoquan.newscontent.databinding.ViewLifeAccountAuthProcessBinding

/**
 * author: yinjiacheng
 * date: 5/27/21 6:49 PM
 * description: 生活号认证流程
 */
class LifeAccountAuthProcessView @JvmOverloads constructor(
    context: Context,
    attrs: AttributeSet? = null,
    defStyle: Int = 0
) : YdConstraintLayout(context, attrs, defStyle) {

    companion object {
        /**
         * 企业资质
         */
        const val PROCESS_ENTERPRISE_QUALIFICATION = 0

        /**
         * 经营者
         */
        const val PROCESS_ENTERPRISE_MANAGER = 1

        /**
         * 平台审核
         */
        const val PROCESS_PLATFORM_AUDIT = 2
    }

    private val viewBinding = ViewLifeAccountAuthProcessBinding.bind(
        View.inflate(
            getContext(),
            R.layout.view_life_account_auth_process,
            this
        )
    )

    /**
     * 当前进度
     */
    var curProcess: Int = 0

    /**
     * 设置当前流程
     */
    fun setProcess(process: Int) {
        curProcess = process
        when (process) {
            PROCESS_ENTERPRISE_QUALIFICATION -> {
                resetUI()
                viewBinding.tvProcessNumEnterpriseQualification.setBackgroundResource(R.drawable.bg_life_account_auth_process_ongoing)
                viewBinding.tvProcessNumEnterpriseQualification.setTextColor(Color.WHITE)
                viewBinding.tvProcessNameEnterpriseQualification.setTextColor(Color.parseColor("#FF1852F1"))
            }
            PROCESS_ENTERPRISE_MANAGER -> {
                resetUI()
                viewBinding.viewProcessEnterpriseQualification.setBackgroundColor(Color.parseColor("#FF1852F1"))

                viewBinding.tvProcessNumEnterpriseQualification.setBackgroundResource(R.drawable.bg_life_account_auth_process_finish)
                viewBinding.tvProcessNumEnterpriseQualification.setTextColor(Color.parseColor("#FF1852F1"))
                viewBinding.tvProcessNameEnterpriseQualification.setTextColor(Color.parseColor("#FF1852F1"))

                viewBinding.tvProcessNumEnterpriseManager.setBackgroundResource(R.drawable.bg_life_account_auth_process_ongoing)
                viewBinding.tvProcessNumEnterpriseManager.setTextColor(Color.WHITE)
                viewBinding.tvProcessNameEnterpriseManager.setTextColor(Color.parseColor("#FF1852F1"))
            }

            PROCESS_PLATFORM_AUDIT -> {
                resetUI()
                viewBinding.viewProcessEnterpriseManager.setBackgroundColor(Color.parseColor("#FF1852F1"))

                viewBinding.tvProcessNumEnterpriseQualification.setBackgroundResource(R.drawable.bg_life_account_auth_process_finish)
                viewBinding.tvProcessNumEnterpriseQualification.setTextColor(Color.parseColor("#FF1852F1"))
                viewBinding.tvProcessNameEnterpriseQualification.setTextColor(Color.parseColor("#FF1852F1"))

                viewBinding.tvProcessNumEnterpriseManager.setBackgroundResource(R.drawable.bg_life_account_auth_process_finish)
                viewBinding.tvProcessNumEnterpriseManager.setTextColor((Color.parseColor("#FF1852F1")))
                viewBinding.tvProcessNameEnterpriseManager.setTextColor((Color.parseColor("#FF1852F1")))

                viewBinding.tvProcessNumEnterpriseManager.setBackgroundResource(R.drawable.bg_life_account_auth_process_ongoing)
                viewBinding.tvProcessNumEnterpriseManager.setTextColor((Color.WHITE))
                viewBinding.tvProcessNameEnterpriseManager.setTextColor((Color.parseColor("#FF1852F1")))
            }
        }
    }

    private fun resetUI() {
        viewBinding.viewProcessEnterpriseQualification.setBackgroundColor(Color.parseColor("#FFF3F4F6"))
        viewBinding.viewProcessEnterpriseManager.setBackgroundColor(Color.parseColor("#FFF3F4F6"))

        viewBinding.tvProcessNumEnterpriseQualification.setBackgroundResource(R.drawable.bg_life_account_auth_process_initial)
        viewBinding.tvProcessNumEnterpriseQualification.setTextColor(Color.parseColor("#61000000"))
        viewBinding.tvProcessNameEnterpriseQualification.setTextColor(Color.parseColor("#61000000"))

        viewBinding.tvProcessNumEnterpriseManager.setBackgroundResource(R.drawable.bg_life_account_auth_process_initial)
        viewBinding.tvProcessNumEnterpriseManager.setTextColor(Color.parseColor("#61000000"))
        viewBinding.tvProcessNameEnterpriseManager.setTextColor(Color.parseColor("#61000000"))

        viewBinding.tvProcessNumPlatformAudit.setBackgroundResource(R.drawable.bg_life_account_auth_process_initial)
        viewBinding.tvProcessNumPlatformAudit.setTextColor(Color.parseColor("#61000000"))
        viewBinding.tvProcessNamePlatformAudit.setTextColor(Color.parseColor("#61000000"))
    }

}