package com.tofly.ghrq_route.module.trouble.ui.dialog;

import android.content.Context;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.FrameLayout;

import androidx.annotation.NonNull;

import com.google.android.material.bottomsheet.BottomSheetBehavior;
import com.google.android.material.bottomsheet.BottomSheetDialog;
import com.tofly.ghrq_route.R;
import com.tofly.ghrq_route.module.trouble.ui.view.BottomSheetTroubleDeviceSelect;
import com.tofly.ghrq_route.module.trouble.domain.DeviceAttributesBean;
import com.tofly.ghrq_route.module.trouble.domain.PipeAttributesBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Amu on 2017/6/19.
 */

public class TroubleDeviceSelectBottomDialog extends BottomSheetDialog {
    @BindView(R.id.layout_bottom_sheet_detail)
    BottomSheetTroubleDeviceSelect bottomSheetDetail;

    private Context mContext;

    private List<PipeAttributesBean> mPipeFeatures;

    private List<DeviceAttributesBean> mDeviceFeatures;

    private boolean mIsEditable = true;

    public TroubleDeviceSelectBottomDialog(@NonNull Context context, List<PipeAttributesBean> pipeFeatures, List<DeviceAttributesBean> deviceFeatures) {
        super(context);
        mContext = context;
        mPipeFeatures = pipeFeatures;
        mDeviceFeatures = deviceFeatures;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.dialog_trouble_device_select_bottom);
        ButterKnife.bind(this);

        Window dialogWindow = getWindow();
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        DisplayMetrics d = mContext.getResources().getDisplayMetrics(); // 获取屏幕宽、高用
        lp.width = (int) (d.widthPixels); // 高度设置为屏幕的0.6
        lp.height = (int) (d.heightPixels);
        dialogWindow.setAttributes(lp);

        initView();
        initData();
    }

    @Override
    public void show() {
        super.show();
        //设置高度
        FrameLayout bottomSheet = (FrameLayout) findViewById(R.id.design_bottom_sheet);
        ViewGroup.LayoutParams originLayoutParams = bottomSheet.getLayoutParams();
        originLayoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
        bottomSheet.setLayoutParams(originLayoutParams);
        BottomSheetBehavior mDialogBehavior = BottomSheetBehavior.from(bottomSheet);
        mDialogBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
    }

    private void initView(){
        bottomSheetDetail.initBottomSheetDetail(mPipeFeatures,  mDeviceFeatures);
    }

    private void initData(){

    }

    public void updateData(List<PipeAttributesBean> pipeFeatures, List<DeviceAttributesBean> deviceFeatures) {
        mPipeFeatures = pipeFeatures;
        mDeviceFeatures = deviceFeatures;
        bottomSheetDetail.initBottomSheetDetail(mPipeFeatures, mDeviceFeatures);
    }

    public List<PipeAttributesBean> getSelectedPipeFeatures() {
        return bottomSheetDetail.getSelectedPipeFeatures();
    }

    public String getPipeNote() {
        return bottomSheetDetail.getPipeNote();
    }

    public List<DeviceAttributesBean> getSelectedDeviceFeatures() {
        return bottomSheetDetail.getSelectedDeviceFeatures();
    }

    public String getDeviceNote() {
        return bottomSheetDetail.getDeviceNote();
    }
}
