package com.cooleshow.student.ui.course;

import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
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.StringUtils;
import com.cooleshow.base.utils.ToastUtil;
import com.cooleshow.base.utils.ToastUtils;
import com.cooleshow.base.utils.UiUtils;
import com.cooleshow.base.utils.helper.QMUIStatusBarHelper;
import com.cooleshow.base.widgets.RatingBar;
import com.cooleshow.student.R;
import com.cooleshow.student.contract.EvaluateTeacherContract;
import com.cooleshow.student.databinding.ActivityEvaluateTeacherBinding;
import com.cooleshow.student.presenter.course.EvaluateTeacherPresenter;

import androidx.annotation.Nullable;

/**
 * 创建日期：2022/5/31 11:20
 *
 * @author Ryan
 * 类说明：
 */
@Route(path = RouterPath.CourseCenter.SPARRING_EVALUATE_TEACHER)
public class EvaluateTeacherActivity extends BaseMVPActivity<ActivityEvaluateTeacherBinding, EvaluateTeacherPresenter> implements EvaluateTeacherContract.EvaluateTeacherView, View.OnClickListener {
    private String mCourseId;
    private String mCourseGroupId;
    private float ratingCount;

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tv_confirm:
                if (UiUtils.isFastClick()) {
                    return;
                }
                String inputContent = viewBinding.etInput.getText().toString().trim();
                if (TextUtils.isEmpty(inputContent)) {
                    ToastUtil.getInstance().showShort("请输入您对本次课程老师的评价");
                    break;
                }
                String result = StringUtils.replaceSpace(inputContent);
                presenter.submitSparringCourseComment(result, mCourseId, mCourseGroupId, ratingCount);
                break;
        }
    }

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

    @Override
    protected void initView() {
        initMidTitleToolBar(viewBinding.toolbarInclude.toolbar, "评价老师");
        mCourseId = getIntent().getStringExtra("course_id");
        mCourseGroupId = getIntent().getStringExtra("course_group_id");
        if (TextUtils.isEmpty(mCourseId)
                || TextUtils.isEmpty(mCourseGroupId)) {
            finish();
            return;
        }


        viewBinding.tvConfirm.setOnClickListener(this);
        viewBinding.ratingBar.setOnRatingChangeListener(new RatingBar.OnRatingChangeListener() {
            @Override
            public void onRatingChange(float ratingCount) {
                EvaluateTeacherActivity.this.ratingCount = ratingCount;
            }
        });
        viewBinding.etInput.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                viewBinding.tvNumber.setText(charSequence.toString().length() + "/200");
            }

            @Override
            public void afterTextChanged(Editable editable) {

            }
        });
    }

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

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

    @Override
    public void submitSparringCourseTeacherCommentSuccess() {
        finish();
    }
}
