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

import android.view.View;

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


import com.phlx.anchorcollect_p.Configs;
import com.phlx.anchorcollect_p.entity.GenTableColumn;
import com.phlx.anchorcollect_p.ui.fragment.vm.BasicsCollectVM;
import com.phlx.anchorcollect_p.ui.fragment.vm.BreedingRecordVM;
import com.phlx.anchorcollect_p.ui.fragment.vm.ImmunRecordVM;
import com.phlx.anchorcollect_p.ui.fragment.vm.MedicalRecordVM;
import com.phlx.anchorcollect_p.ui.fragment.vm.PerformanceVM;
import com.phlx.anchorcollect_p.ui.fragment.vm.WeightManVM;

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;

public class CollectGridItem extends ItemViewModel<BaseViewModel> {

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

    public ObservableField<Integer> titleGrayVisiable = new ObservableField<>(View.VISIBLE);
    public ObservableField<Integer> titleBlueVisiable = 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() {

//        switch (fragmentType) {
//            case Configs.BASE_ARCHIVES:
//            case Configs.WEIGHTING_MANAGE:
//
//                if ("1".equals(entity.get().getIsEdit())) {
//                    titleGrayVisiable.set(View.GONE);
//                    titleBlueVisiable.set(View.VISIBLE);
//                } else {
//                    titleGrayVisiable.set(View.VISIBLE);
//                    titleBlueVisiable.set(View.GONE);
//                }
//                break;
//            default:
                if ("1".equals(entity.get().getIsInsert())) {
                    titleGrayVisiable.set(View.GONE);
                    titleBlueVisiable.set(View.VISIBLE);
                } else {
                    titleGrayVisiable.set(View.VISIBLE);
                    titleBlueVisiable.set(View.GONE);
                }
//                break;
//        }
    }

    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:
                    ((WeightManVM) viewModel).onItemClick(entity.get());
                    break;
                case Configs.TREATMENT_RECORD:
                    ((MedicalRecordVM) viewModel).onItemClick(entity.get());
                    break;
                case Configs.IMMUN_RECORD:
                    ((ImmunRecordVM) viewModel).onItemClick(entity.get());
                    break;
                case Configs.BREEDING_RECORD:
                    ((BreedingRecordVM) viewModel).onItemClick(entity.get());
                    break;
                case Configs.BREEDING_RECORD_DETAIL:
                    ((BreedingRecordVM) viewModel).onItemClick(entity.get());
                    break;
            }
        }
    });
}
