package com.dahe.mylibrary.cuspop;

import android.content.Context;
import android.text.TextUtils;
import android.util.Log;
import android.widget.EditText;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.dahe.mylibrary.R;
import com.dahe.mylibrary.utils.ToastUtils;
import com.lxj.xpopup.core.CenterPopupView;
import com.lxj.xpopup.util.KeyboardUtils;

/**
 * Description: 自定义局部阴影弹窗
 * Create by dance, at 2018/12/21
 */
public class InputPopupView extends CenterPopupView {
    private Context ctx;


    public InputPopupView(@NonNull Context context) {
        super(context);
        this.ctx = context;
    }

    @Override
    protected int getImplLayoutId() {
        return R.layout.my_confim_popup_input;
    }


    @Override
    protected void onCreate() {
        super.onCreate();
        EditText etInput = findViewById(R.id.et_input);
        TextView tvCancel = findViewById(R.id.tv_cancel);
        TextView tvConfirm = findViewById(R.id.tv_confirm);
        if (listener != null) {
            tvConfirm.setOnClickListener(view -> {
                if (TextUtils.isEmpty(etInput.getText().toString().trim())){
                    KeyboardUtils.hideSoftInput(tvConfirm);
                    ToastUtils.showToast(ctx,"请填写取消原因");
                    return;
                }
                listener.okClick(etInput.getText().toString());
                dismiss();
            });
        }

        tvCancel.setOnClickListener(v -> dismiss());

    }

    @Override
    protected void onShow() {
        super.onShow();
        Log.e("tag", "CustomPartShadowPopupView onShow");
    }

    @Override
    protected void onDismiss() {
        super.onDismiss();
        Log.e("tag", "CustomPartShadowPopupView onDismiss");
    }


    private OnOkListener listener;

    public InputPopupView setOnOkListener(OnOkListener listener) {
        this.listener = listener;
        return this;
    }

    public interface OnOkListener {
        void okClick(String item);
    }
}
