package com.sxyz.rfid.ui.out.adapter;

import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;

import com.blankj.utilcode.util.StringUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnLoadMoreListener;
import com.chad.library.adapter.base.module.LoadMoreModule;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.sxyz.rfid.R;
import com.sxyz.rfid.presenter.model.OutboundModel;

import java.util.List;

/**
 * 出库适配器
 *
 * @author chunyuanwu
 * @version 1.0.0
 * @date 2025年12月27日 16:40
 */
public class OutBoundAdapter extends BaseQuickAdapter<OutboundModel.RowsBean, BaseViewHolder> implements LoadMoreModule {

    public OutBoundAdapter(int layoutResId, List<OutboundModel.RowsBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder baseViewHolder, OutboundModel.RowsBean dataBean) {
        //出库单号
        baseViewHolder.setText(R.id.outbound_number, !StringUtils.isEmpty(dataBean.getOrderNo()) ? dataBean.getOrderNo() : "-");
        //仓库名称
        baseViewHolder.setText(R.id.txt_warehouse, !StringUtils.isEmpty(dataBean.getWarehouse().getWarehouseName()) ? dataBean.getWarehouse().getWarehouseName() : "-");
        //客户
        baseViewHolder.setText(R.id.txt_customer_type, !StringUtils.isEmpty(dataBean.getCustomerUser().getCustomerName()) ? dataBean.getCustomerUser().getCustomerName() : "-");
        //数量/金额
        baseViewHolder.setText(R.id.txt_number_money, dataBean.getTotalQuantity() + "个 / ￥" + dataBean.getTotalAmount() + "元");
        //出库类型
        switch (dataBean.getOrderType()) {
            case "0":
                baseViewHolder.setText(R.id.txt_outbound_type, "计划出库");
                break;
            case "1":
                baseViewHolder.setText(R.id.txt_outbound_type, "紧急调拨");
                break;
            case "2":
                baseViewHolder.setText(R.id.txt_outbound_type, "报废出库");
                break;
            default:
                baseViewHolder.setText(R.id.txt_outbound_type, "-");
                break;
        }
        //状态
        TextView outboundStatus = baseViewHolder.getView(R.id.outbound_status);
        switch (dataBean.getOrderStatus()) {
            case "0":
                outboundStatus.setText("未出库");
                outboundStatus.setBackground(ContextCompat.getDrawable(getContext(), R.drawable.status_gray_bg));
                outboundStatus.setTextColor(ContextCompat.getColor(getContext(), R.color.c_6666));
                break;
            case "1":
                outboundStatus.setText("拣货中");
                outboundStatus.setBackground(ContextCompat.getDrawable(getContext(), R.drawable.status_red_bg));
                outboundStatus.setTextColor(ContextCompat.getColor(getContext(), R.color.red));
                break;
            case "2":
                outboundStatus.setText("已出库");
                outboundStatus.setBackground(ContextCompat.getDrawable(getContext(), R.drawable.status_green_bg));
                outboundStatus.setTextColor(ContextCompat.getColor(getContext(), R.color.green));
                break;
            default:
                outboundStatus.setText("-");
                outboundStatus.setBackground(ContextCompat.getDrawable(getContext(), R.drawable.status_gray_bg));
                outboundStatus.setTextColor(ContextCompat.getColor(getContext(), R.color.c_6666));
                break;
        }
        //复制按钮
        baseViewHolder.getView(R.id.btn_copy).setOnClickListener(v -> {
            if (mItemClickListener != null) {
                mItemClickListener.onCopyClick(baseViewHolder.getLayoutPosition(), dataBean);
            }
        });
        //详情按钮
        baseViewHolder.getView(R.id.detail_button).setOnClickListener(v -> {
            if (mItemClickListener != null) {
                mItemClickListener.onItemClick(baseViewHolder.getLayoutPosition(), dataBean);
            }
        });
        //出库按钮
        baseViewHolder.getView(R.id.outbound_button).setOnClickListener(v -> {
            if (mItemClickListener != null) {
                mItemClickListener.onOutboundClick(baseViewHolder.getLayoutPosition(), dataBean);
            }
        });
    }

    public interface OnItemClickListener {
        void onItemClick(int position, OutboundModel.RowsBean item);

        void onOutboundClick(int position, OutboundModel.RowsBean item);

        void onCopyClick(int position, OutboundModel.RowsBean item);
    }

    private OnItemClickListener mItemClickListener;

    public void setOnItemClickListener(OnItemClickListener mItemClickListener) {
        this.mItemClickListener = mItemClickListener;
    }
}