package com.yidianling.im.session.viewholder;

import android.annotation.SuppressLint;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.core.content.ContextCompat;

import com.netease.nimlib.sdk.msg.attachment.MsgAttachment;
import com.ydl.webview.H5Params;
import com.ydl.webview.NewH5Activity;
import com.yidianling.im.R;
import com.yidianling.im.session.extension.CustomAttachConsultSubScript;
import com.yidianling.im.session.extension.CustomAttachmentConfirmOrder;
import com.yidianling.nimbase.common.ui.recyclerview.adapter.BaseMultiItemFetchLoadAdapter;
import com.yidianling.uikit.business.session.viewholder.MsgViewHolderBase;

public class MsgViewHolderConfirmOrder extends MsgViewHolderBase {

    private TextView tv_title, tv_date, tv_type;
    private View lin_root;
    private ImageView img_icon;

    public String url;//跳转url
    public int flag;//0 未确认 1已确认

    public MsgViewHolderConfirmOrder(BaseMultiItemFetchLoadAdapter adapter) {
        super(adapter);
    }

    @Override
    protected int getContentResId() {
        return R.layout.im_ui_message_custom_confirm_order;
    }

    @Override
    protected void inflateContentView() {
        tv_title = view.findViewById(R.id.tv_title);
        tv_date = view.findViewById(R.id.tv_date);
        tv_type = view.findViewById(R.id.tv_type);
        lin_root = view.findViewById(R.id.lin_root);
        img_icon = view.findViewById(R.id.img_icon);

        if (isReceivedMessage()){
            setAvatarRightInVisibity();
            lin_root.setBackgroundResource(R.drawable.im_bg_radius_no_topleft_white_8);
        }else {
            setAvatarLeftInVisibity();
            lin_root.setBackgroundResource(R.drawable.im_bg_radius_no_topright_white_8);
        }
    }

    @SuppressLint("SetTextI18n")
    @Override
    protected void bindContentView() {
        if (isReceivedMessage()){
            setAvatarRightInVisibity();
        }else {
            setAvatarLeftInVisibity();
        }

        MsgAttachment attachment = message.getAttachment();
        if (attachment instanceof CustomAttachmentConfirmOrder) {
            tv_title.setText(((CustomAttachmentConfirmOrder) attachment).title);
            tv_date.setText("咨询时间:"+((CustomAttachmentConfirmOrder) attachment).bookingtime);
            tv_type.setText("服务方式:"+((CustomAttachmentConfirmOrder) attachment).servicetype);
        }
        hideItemBg();
    }
    @Override
    protected void onItemClick() {
        if (TextUtils.isEmpty(url)){
            return;
        }
        NewH5Activity.start(context,new H5Params(url,null));
    }
}
