package com.cooleshow.teacher.ui.live;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.cooleshow.base.router.RouterPath;
import com.cooleshow.base.ui.activity.BaseMVPActivity;
import com.cooleshow.base.utils.ToastUtils;
import com.cooleshow.base.utils.helper.QMUIStatusBarHelper;
import com.cooleshow.teacher.R;
import com.cooleshow.teacher.contract.CreateLiveContract;
import com.cooleshow.teacher.databinding.ActivityCreateLiveBinding;
import com.cooleshow.teacher.presenter.live.CreateLivePresenter;

import androidx.annotation.Nullable;

/**
 * 创建日期：2022/5/20 14:45
 *
 * @author Ryan
 * 类说明：
 */
@Route(path = RouterPath.LiveCenter.TEACHER_MINE_CREATE_COURSE)
public class CreateLiveActivity extends BaseMVPActivity<ActivityCreateLiveBinding, CreateLivePresenter> implements CreateLiveContract.CreateLiveView, View.OnClickListener {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        QMUIStatusBarHelper.setStatusBarLightMode(this);
    }

    @Override
    protected void initView() {
        initMidTitleToolBar(viewBinding.toolbarInclude.toolbar, "创建直播");
        viewBinding.tvConfirm.setOnClickListener(this);
    }

    @Override
    protected ActivityCreateLiveBinding getLayoutView() {
        return ActivityCreateLiveBinding.inflate(getLayoutInflater());
    }

    @Override
    protected CreateLivePresenter createPresenter() {
        return new CreateLivePresenter();
    }

    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.tv_confirm) {
            //创建直播间
            String liveTitle = viewBinding.etTitle.getText().toString().trim();
            if (TextUtils.isEmpty(liveTitle)) {
                ToastUtils.showShort("请输入直播间标题");
                return;
            }
            String liveContent = viewBinding.etContent.getText().toString().trim();
            if (TextUtils.isEmpty(liveContent)) {
                ToastUtils.showShort("请输入直播间内容");
                return;
            }
            presenter.createTempLive(liveContent, liveTitle);
        }
    }

    /**
     * 创建直播间成功,返回直播间id
     *
     * @param roomId
     */
    @Override
    public void onCreateLiveSuccess(String roomId) {
        ToastUtils.showShort("创建成功");
        LiveRoomActivity.start(this, roomId);
        finish();
    }
}
