package com.bonait.bnframework.modules.home.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bonait.bnframework.R;
import com.bonait.bnframework.common.base.BaseFragment;
import com.bonait.bnframework.common.utils.DisplayManager;
import com.bonait.bnframework.databinding.FragmentSilosSettingBinding;
import com.bonait.bnframework.event.SilosClickEvent;
import com.orhanobut.logger.Logger;

import org.greenrobot.eventbus.EventBus;

import butterknife.ButterKnife;

/**
 * @author: liup
 * @description: 料仓图
 * @date: 2024/6/14 14:57.
 */
public class SilosSettingFragment extends BaseFragment {
    private FragmentSilosSettingBinding viewBinding;
    private int type = 1;//1左侧 2右侧 3顶部 4背部

    public static SilosSettingFragment newInstance(int type){
        SilosSettingFragment fragment = new SilosSettingFragment();
        fragment.type = type;
        return fragment;
    };
    @Override
    protected View onCreateView() {
        viewBinding = FragmentSilosSettingBinding.inflate(getLayoutInflater());
//        if(viewBinding.includeDeviceLeft.title1.getTextSize()>28||viewBinding.includeDeviceLeft.title1.getTextSize()<24){
            DisplayManager.scaleViewGroup(viewBinding.getRoot());
//        }
        return viewBinding.getRoot();
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        Logger.d("我的fragment创建");
        initView();
    }

    private void initView(){
        switch (type){
            case 1:
                viewBinding.includeDeviceLeft.getRoot().setVisibility(View.VISIBLE);
                initLeftView();
                break;
            case 2:
                viewBinding.includeDeviceRight.getRoot().setVisibility(View.VISIBLE);
                initRightView();
                break;
            case 3:
                viewBinding.includeDeviceTop.getRoot().setVisibility(View.VISIBLE);
                initTopView();
                break;
            case 4:
                viewBinding.includeDeviceBack.getRoot().setVisibility(View.VISIBLE);
                initBackView();
                break;
        }
    }

    private void initLeftView(){
        viewBinding.includeDeviceLeft.channel1.setOnClickListener(v->{
            EventBus.getDefault().post(new SilosClickEvent("通道1"));
        });
        viewBinding.includeDeviceLeft.channel2.setOnClickListener(v->{
            EventBus.getDefault().post(new SilosClickEvent("通道2"));
        });
    }

    private void initRightView(){
        viewBinding.includeDeviceRight.channel3.setOnClickListener(v->{
            EventBus.getDefault().post(new SilosClickEvent("通道3"));
        });
        viewBinding.includeDeviceRight.channel4.setOnClickListener(v->{
            EventBus.getDefault().post(new SilosClickEvent("通道4"));
        });
        viewBinding.includeDeviceRight.channel5.setOnClickListener(v->{
            EventBus.getDefault().post(new SilosClickEvent("通道5"));
        });
    }

    private void initTopView(){
        viewBinding.includeDeviceTop.channel6.setOnClickListener(v->{
            EventBus.getDefault().post(new SilosClickEvent("通道6"));
        });
        viewBinding.includeDeviceTop.channel7.setOnClickListener(v->{
            EventBus.getDefault().post(new SilosClickEvent("通道7"));
        });
        viewBinding.includeDeviceTop.channel8.setOnClickListener(v->{
            EventBus.getDefault().post(new SilosClickEvent("通道8"));
        });
        viewBinding.includeDeviceTop.channel9.setOnClickListener(v->{
            EventBus.getDefault().post(new SilosClickEvent("通道9"));
        });
        viewBinding.includeDeviceTop.channel10.setOnClickListener(v->{
            EventBus.getDefault().post(new SilosClickEvent("通道10"));
        });
        viewBinding.includeDeviceTop.channel11.setOnClickListener(v->{
            EventBus.getDefault().post(new SilosClickEvent("通道11"));
        });
    }

    private void initBackView(){
        viewBinding.includeDeviceBack.channel12.setOnClickListener(v->{
            EventBus.getDefault().post(new SilosClickEvent("通道12"));
        });
        viewBinding.includeDeviceBack.channel13.setOnClickListener(v->{
            EventBus.getDefault().post(new SilosClickEvent("通道13"));
        });
        viewBinding.includeDeviceBack.channel14.setOnClickListener(v->{
            EventBus.getDefault().post(new SilosClickEvent("通道14"));
        });
        viewBinding.includeDeviceBack.channel15.setOnClickListener(v->{
            EventBus.getDefault().post(new SilosClickEvent("通道15"));
        });
        viewBinding.includeDeviceBack.channel16.setOnClickListener(v->{
            EventBus.getDefault().post(new SilosClickEvent("通道16"));
        });
        viewBinding.includeDeviceBack.channel17.setOnClickListener(v->{
            EventBus.getDefault().post(new SilosClickEvent("通道17"));
        });
        viewBinding.includeDeviceBack.channel18.setOnClickListener(v->{
            EventBus.getDefault().post(new SilosClickEvent("通道18"));
        });
        viewBinding.includeDeviceBack.channel19.setOnClickListener(v->{
            EventBus.getDefault().post(new SilosClickEvent("通道19"));
        });
        viewBinding.includeDeviceBack.channel20.setOnClickListener(v->{
            EventBus.getDefault().post(new SilosClickEvent("通道20"));
        });
        viewBinding.includeDeviceBack.channel21.setOnClickListener(v->{
            EventBus.getDefault().post(new SilosClickEvent("通道21"));
        });
    }



}
