package cn.forevermc.launcher.view.components;

import cn.forevermc.launcher.view.components.control.MCList;
import javafx.beans.binding.Bindings;
import javafx.beans.property.BooleanProperty;
import javafx.geometry.Insets;

/**
 * 列表面板，基于内容面板的列表视图
 *
 * @author 夜雨
 * @since 2022-11-23 17:41
 */
public abstract class AbstractListPane<T> extends AbstractContentPane {

	private static final Insets PADDING_SCROLL = new Insets(0, 0, 0, 32);
	private static final Insets PADDING_SCROLL_R = new Insets(0, 0, 0, 0);

	protected final MCList<T> list;

	public AbstractListPane() {
		list = new MCList<>();

		content.paddingProperty().bind(Bindings.when(list.showingVScrollBarProperty()).then(PADDING_SCROLL).otherwise(PADDING_SCROLL_R));
		content.maxWidthProperty().bind(Bindings.when(list.showingVScrollBarProperty()).then(690D).otherwise(640));
		setContentPane(list);
	}

	@Override
	protected void onHide() {
		list.getItems().clear();
	}

	/** @return true 为正在加载 */
	public boolean isLoading() {
		return list.isLoading();
	}

	/** @return 正在加载属性 */
	public BooleanProperty loadingProperty() {
		return list.loadingProperty();
	}

	/** @param isLoading true 为正在加载 */
	public void setLoading(boolean isLoading) {
		list.setLoading(isLoading);
	}
}