package com.zxhl.cms.widget;

import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.net.Uri;
import android.provider.Settings;
import android.view.Gravity;
import android.view.View;
import android.widget.TextView;

import androidx.appcompat.widget.AppCompatImageView;
import androidx.appcompat.widget.AppCompatTextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.request.RequestOptions;
import com.zxhl.cms.R;
import com.zxhl.cms.net.model.chat.ChatMessageChargeOrNotEntity;

/**
 * @Description: java类作用描述
 * @Author: lidandan
 * @CreateDate: 2021/12/27 3:21 下午
 */
public class ChatDialogUtils {
    /**
     * 第一次充值弹窗
     *
     * @param activity
     * @return
     */
    public static Dialog showFirstReChargeDialog(Activity activity, ChatDialogCallBack dialogCallBack) {
        Dialog dialog = new Dialog(activity, com.zxhl.cms.R.style.CenterCompatDialogTheme);
        View dialogView = CenterDialog.INSTANCE.showBottomDialog(R.layout.chat_dialog_first_recharge_tip, activity, dialog, R.style.AnimBottom, Gravity.CENTER);
        dialog.setCanceledOnTouchOutside(true);
        dialogView.findViewById(R.id.chat_first_goto_recharge_tv).setOnClickListener(v -> {
            dialogCallBack.confirm();
            dialog.dismiss();
        });
        dialogView.findViewById(R.id.chat_recharge_close_iv).setOnClickListener(v -> {
            dialogCallBack.cancel();
            dialog.dismiss();
        });
        dialog.show();
        return dialog;
    }


    /**
     * 非会员弹窗提示
     *
     * @param context
     * @return
     */
    public static Dialog showMemberChargeTip(Activity context, ChatMessageChargeOrNotEntity result, String content, String tipContent, ChatDialogCallBackParams callBackParams) {
        if (context == null) {
            return null;
        }
        Dialog mDialog = new Dialog(context, R.style.CenterCompatDialogTheme);
        View mDialogView =
                CenterDialog.INSTANCE.showBottomDialog(
                        R.layout.chat_dialog_layout_not_member_tip,
                        context,
                        mDialog,
                        0,
                        Gravity.CENTER
                );
        mDialogView.findViewById(R.id.id_img_close).setOnClickListener(v -> {
            callBackParams.cancel();
            mDialog.dismiss();
        });
        ((TextView) mDialogView.findViewById(R.id.dialog_tip_content_tv)).setText(content);
        TextView chatDuiHuanTV = mDialogView.findViewById(R.id.chat_duihuan_tv);
        chatDuiHuanTV.setText(result.charge + tipContent);
        chatDuiHuanTV.setOnClickListener(v -> {
            callBackParams.confirm(0);
            mDialog.dismiss();
        });
        mDialogView.findViewById(R.id.chat_goto_charge_vip_tv).setOnClickListener(v -> {
            callBackParams.confirm(1);
            mDialog.dismiss();
        });
        mDialog.setCanceledOnTouchOutside(false);
        mDialog.setCancelable(false);
        mDialog.show();
        return mDialog;
    }

    /**
     * 提示会员充值
     *
     * @param context
     * @return
     */
    public static Dialog showMemberTrip(Activity context, ChatDialogCallBack callBack) {
        if (context == null) {
            return null;
        }
        Dialog mDialog = new Dialog(context, R.style.CenterCompatDialogTheme);
        View mDialogView =
                CenterDialog.INSTANCE.showBottomDialog(
                        R.layout.chat_dialog_layout_trip,
                        context,
                        mDialog,
                        0,
                        Gravity.CENTER
                );
        mDialogView.findViewById(R.id.chat_close_dialog_tv).setOnClickListener(v -> {
            callBack.cancel();
            mDialog.dismiss();
        });
        mDialogView.findViewById(R.id.chat_goto_charge_tv).setOnClickListener(v -> {
            callBack.confirm();
            mDialog.dismiss();
        });
        mDialog.setCanceledOnTouchOutside(false);
        mDialog.setCancelable(false);
        mDialog.show();
        return mDialog;
    }

    /**
     * 亲密度增加提示
     *
     * @param activity
     * @return
     */
    public static Dialog showMessageStarTipDialog(Activity activity, String recivierHeadUrl, String userHeadUrl, String tipTitle, String tipValue) {
        Dialog dialog = new Dialog(activity, com.zxhl.cms.R.style.CenterCompatDialogTheme);
        View dialogView = CenterDialog.INSTANCE.showBottomDialog(R.layout.chat_dialog_message_star_tip, activity, dialog, R.style.AnimBottom, Gravity.CENTER);
        dialog.setCanceledOnTouchOutside(true);
        dialogView.findViewById(R.id.chat_continue_message_tv).setOnClickListener(v -> {
            dialog.dismiss();
        });
        AppCompatImageView chatRecivierHeadIV = dialogView.findViewById(R.id.chat_recivier_head_iv);
        AppCompatImageView chatUserHeadIV = dialogView.findViewById(R.id.chat_user_head_iv);
        AppCompatTextView chatMessageStarTitleTV = dialogView.findViewById(R.id.chat_message_star_title_tv);
        AppCompatTextView chatMessageStarValueTV = dialogView.findViewById(R.id.chat_message_star_value_tv);
        Glide.with(activity).load(recivierHeadUrl).placeholder(R.drawable.icon_user_photo_default).apply(RequestOptions.bitmapTransform(new CircleCrop())).into(chatRecivierHeadIV);
        Glide.with(activity).load(userHeadUrl).placeholder(R.drawable.icon_user_photo_default).apply(RequestOptions.bitmapTransform(new CircleCrop())).into(chatUserHeadIV);
        chatMessageStarTitleTV.setText(tipTitle);
        chatMessageStarValueTV.setText(tipValue);
        dialog.show();
        return dialog;
    }

    /**
     * 权限提示
     */
    public static Dialog showPermissionDialog(final Activity activity, String message) {
        Dialog dialog = new Dialog(activity, com.zxhl.cms.R.style.CenterCompatDialogTheme);
        View dialogView = CenterDialog.INSTANCE.showBottomDialog(R.layout.chat_dialog_permission_tip, activity, dialog, R.style.AnimBottom, Gravity.CENTER);
        dialog.setCanceledOnTouchOutside(false);
        dialogView.findViewById(R.id.chat_dialog_cancle_tv).setOnClickListener(v -> {
            dialog.dismiss();
        });
        dialog.findViewById(R.id.chat_permission_setting_tv).setOnClickListener(v -> {
            dialog.dismiss();
            Uri packageURI = Uri.parse("package:" + activity.getPackageName());
            Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, packageURI);
            activity.startActivity(intent);
        });
        AppCompatTextView chatPermissionMessageTV = dialogView.findViewById(R.id.chat_message_tip_tv);
        chatPermissionMessageTV.setText(message);
        dialog.show();
        return dialog;
    }

    public interface ChatDialogCallBack {
        void confirm();

        void cancel();
    }

    public interface ChatDialogCallBackParams {
        void confirm(int type);

        void cancel();
    }
}
