package com.tofly.ghrq_route.module.emergencyHandle.ui;

import static com.tofly.ghrq_route.base.ui.BaseUi.getDialogHeight;

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

import com.gaoyuan.weixinrecord.example.Record;
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.emergencyHandle.domain.EmergencyHandleData;
import com.tofly.ghrq_route.module.emergencyHandle.domain.ScheduleExecuteBean;
import com.tofly.ghrq_route.module.emergencyHandle.ui.view.EmergencyAssignHandleInfoModuleLayout;
import com.tofly.ghrq_route.common.util.file.FileViewUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

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

public class EmergencyAssignHandleDetailBottomDialog extends BottomSheetDialog {
    @BindView(R.id.layout_module_assign_handle_info)
    EmergencyAssignHandleInfoModuleLayout assignHandleInfoModule;

    private Context mContext;

    private EmergencyHandleData mHandleData;

    private ScheduleExecuteBean mExecuteBean;

    private FileViewUtil fileViewUtil;

    private List<Record> mRecords;

    private boolean mIsEditable = true;

    public EmergencyAssignHandleDetailBottomDialog(Context context, EmergencyHandleData handleData, ScheduleExecuteBean executeBean) {
        super(context);
        mContext = context;
        mHandleData = handleData;
        mExecuteBean = executeBean;
        fileViewUtil = new FileViewUtil(context);
        mRecords = new ArrayList<>();
    }

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

        setContentView(R.layout.item_emerge_assign_handle_detail);
        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 = findViewById(R.id.design_bottom_sheet);
        ViewGroup.LayoutParams originLayoutParams = bottomSheet.getLayoutParams();
        originLayoutParams.height = getDialogHeight(mContext);
        bottomSheet.setLayoutParams(originLayoutParams);
        BottomSheetBehavior mDialogBehavior = BottomSheetBehavior.from(bottomSheet);
        mDialogBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
    }

    public void setExecuteBean(ScheduleExecuteBean executeBean) {
        mExecuteBean = executeBean;
        initView();
    }

    private void initView() {
        assignHandleInfoModule.initEmergencyInfo(mHandleData, mExecuteBean);
    }

    private void initData() {

    }

    @OnClick({R.id.btn_header_close})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_header_close:
                dismiss();
                break;
        }
    }
}
