package com.remax.visualnovel.extension

import android.view.View
import androidx.core.view.isVisible
import com.remax.visualnovel.widget.ui.SwitchView

/**
 * Created by HJW on 2023/11/13
 */

/**
 * 批量操作此页面 Switch
 * @receiver SwitchView
 * @param switchChecked Boolean 开关是否打开  null表示不操作
 * @param switchLayouts ViewGroup? SwitchView的相关父布局
 * @param switchIsVisible Boolean SwitchView的父布局是否隐藏
 * @param switchCheckedCallback Function0<Unit> 开关切换callback
 */
internal fun SwitchView.setSwitchShowAndChecked(
    switchChecked: Boolean? = null,
    switchLayouts: List<View>? = null,
    switchIsVisible: Boolean = false,
    switchCheckedCallback: (checked: Boolean) -> Unit
) {
    switchLayouts?.forEach {
        it.isVisible = switchIsVisible
    }
    switchChecked?.let {
        isChecked = it
    }
    setPressChanged {
        switchCheckedCallback(isChecked)
    }
}