package com.phlx.anchorcollect.ui.fragment.list;

import android.view.View;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableField;

import com.phlx.anchorcollect.Configs;
import com.phlx.anchorcollect.R;
import com.phlx.anchorcollect.entity.GenTableColumn;
import com.phlx.anchorcollect.ui.fragment.vm.BasicsCollectVM;
import com.phlx.anchorcollect.ui.fragment.vm.BreedingRecordVM;
import com.phlx.anchorcollect.ui.fragment.vm.PerformanceVM;

import cn.hutool.core.util.IdUtil;
import me.goldze.mvvmhabit.base.BaseViewModel;
import me.goldze.mvvmhabit.base.ItemViewModel;
import me.goldze.mvvmhabit.binding.command.BindingAction;
import me.goldze.mvvmhabit.binding.command.BindingCommand;
import me.goldze.mvvmhabit.utils.StringUtils;
import me.goldze.mvvmhabit.utils.ToastUtils;

public class CollectGridItem extends ItemViewModel<BaseViewModel> {

    public ObservableField<GenTableColumn> entity = new ObservableField<>();

    public ObservableField<Integer> titleGrayColor = new ObservableField<>(View.VISIBLE);
    public ObservableField<Integer> titleBlueColor = new ObservableField<>(View.GONE);

    private  String fragmentType;

    public CollectGridItem(@NonNull BaseViewModel viewModel, GenTableColumn entity, String fragmentType) {
        super(viewModel);
        this.entity.set(entity);
        this.fragmentType = fragmentType;

        initView();
    }

    private void initView(){

        if("1".equals(entity.get().getIsEdit())){
            titleGrayColor.set(View.GONE);
            titleBlueColor.set(View.VISIBLE);
        }else {
            titleGrayColor.set(View.VISIBLE);
            titleBlueColor.set(View.GONE);
        }

    }

    public BindingCommand onItemClickCommand = new BindingCommand(new BindingAction() {
        @Override
        public void call() {

            switch (fragmentType){
                case Configs.BASE_ARCHIVES:
                    ((BasicsCollectVM)viewModel).onItemClick(entity.get());
                    break;
                case Configs.SIGN_MEASURE:
                    ((PerformanceVM)viewModel).onItemClick(entity.get());
                    break;
                case Configs.WEIGHTING_MANAGE:

                    break;
                case Configs.TREATMENT_RECORD:

                    break;
                case Configs.IMMUN_RECORD:

                    break;
                case Configs.BREEDING_RECORD:
                    ((BreedingRecordVM)viewModel).onItemClick(entity.get());
                    break;
                case Configs.BREEDING_RECORD_DETAIL:
                    ((BreedingRecordVM)viewModel).onItemClick(entity.get());
                    break;
            }
        }
    });
}
