package com.cooleshow.student.widgets.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.cooleshow.student.R;
import com.rong.io.live.LiveRoomMsgConstants;

import androidx.annotation.NonNull;
import androidx.constraintlayout.widget.ConstraintLayout;

/**
 * Author by pq, Date on 2022/8/11.
 */
public class LiveRoomMicManagerDialog extends Dialog implements View.OnClickListener {

    private LinearLayout mLlApply;
    private TextView mTvApplyMic;
    private TextView mTvCancel;
    private ConstraintLayout mCsApplying;
    private TextView mTvCancelApply;
    private ImageView mIvOwnerAvatar;
    private ImageView mIvTeacherAvatar;
    private LinearLayout mLlCloseMic;
    private TextView mTvCloseMic;
    private TextView mTvCancel2;

    public LiveRoomMicManagerDialog(@NonNull Context context) {
        super(context, R.style.MyBottomDialogStyle);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_live_room_mic_manager_layout);
        Window window = getWindow();
        //设置dialog在屏幕底部
        window.setGravity(Gravity.BOTTOM);
        //设置dialog弹出时的动画效果，从屏幕底部向上弹出
        window.setWindowAnimations(com.cooleshow.base.R.style.BottomAnimation);
        window.getDecorView().setPadding(0, 0, 0, 0);
        //获得window窗口的属性
        WindowManager.LayoutParams lp = window.getAttributes();
        //设置窗口宽度为充满全屏
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        //设置窗口高度为包裹内容
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        lp.horizontalMargin = 0;
        lp.verticalMargin = 0;
        //将设置好的属性set回去
        window.setAttributes(lp);

        mLlApply = findViewById(R.id.ll_apply);
        mTvApplyMic = findViewById(R.id.tv_apply_mic);
        mTvCancel = findViewById(R.id.tv_cancel);
        mCsApplying = findViewById(R.id.cs_applying);
        mTvCancelApply = findViewById(R.id.tv_cancel_apply);
        mIvOwnerAvatar = findViewById(R.id.iv_owner_avatar);
        mIvTeacherAvatar = findViewById(R.id.iv_teacher_avatar);
        mLlCloseMic = findViewById(R.id.ll_close_mic);
        mTvCloseMic = findViewById(R.id.tv_close_mic);
        mTvCancel2 = findViewById(R.id.tv_cancel2);
        initListener();
    }

    private void initListener() {
        mTvApplyMic.setOnClickListener(this);
        mTvCancel.setOnClickListener(this);
        mTvCancelApply.setOnClickListener(this);
        mTvCloseMic.setOnClickListener(this);
        mTvCancel2.setOnClickListener(this);
    }

    public void setMicStatus(int micStatus) {
        if (mLlApply != null) {
            mLlApply.setVisibility(micStatus == LiveRoomMsgConstants.MIC_STATUS_NORMAL ? View.VISIBLE : View.GONE);
        }
        if (mCsApplying != null) {
            mCsApplying.setVisibility(micStatus == LiveRoomMsgConstants.MIC_STATUS_CONNECTING ? View.VISIBLE : View.GONE);
        }
        if (mLlCloseMic != null) {
            mLlCloseMic.setVisibility(micStatus == LiveRoomMsgConstants.MIC_STATUS_CONNECT_SUCCESS ? View.VISIBLE : View.GONE);
        }
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.tv_cancel || id == R.id.tv_cancel2) {
            dismiss();
            return;
        }
        if (id == R.id.tv_cancel_apply) {
            //取消申请
        }
        if (id == R.id.tv_apply_mic) {
            //申请连麦
        }
        if (id == R.id.tv_close_mic) {
            //关闭连麦
        }
    }
}
