package com.sxyz.rfid.ui.review;

import android.os.Bundle;

import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.blankj.utilcode.util.StringUtils;
import com.sxyz.rfid.R;
import com.sxyz.rfid.base.BaseActivity;
import com.sxyz.rfid.databinding.ActivityReviewDetailBinding;
import com.sxyz.rfid.presenter.IReviewPresenter;
import com.sxyz.rfid.presenter.imp.ReviewPresenterImpl;
import com.sxyz.rfid.presenter.model.ReviewDetailListModel;
import com.sxyz.rfid.presenter.model.ReviewDetailModel;
import com.sxyz.rfid.presenter.model.ReviewModel;
import com.sxyz.rfid.presenter.model.ReviewResultModel;
import com.sxyz.rfid.presenter.model.ReviewRfidTaskCheckModel;
import com.sxyz.rfid.presenter.view.IReviewView;
import com.sxyz.rfid.ui.review.adapter.ReviewDetailAdapter;
import com.sxyz.rfid.utils.StringUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * 主要功能:  盘点详情 、 任务基础信息、任务明细信息
 *
 * @Description: 盘点详情 、 任务基础信息、任务明细信息
 * @Project: rfid-app
 * @Package: com.sxyz.rfid.ui.review
 * @author: chunyuanwu
 * @date: 2025年12月29日 18:18
 * @version: 1.0.0
 */
public class ReviewDetailActivity extends BaseActivity<ActivityReviewDetailBinding> implements IReviewView {
    private ReviewModel.RowsBean item;
    private ReviewDetailAdapter mAdapter;
    private List<ReviewDetailListModel.RowsBean> list = new ArrayList<>();
    private IReviewPresenter mPresenter;

    @Override
    public void initParms(Bundle mBundle) {
        item = (ReviewModel.RowsBean) mBundle.getSerializable("item");
    }

    @Override
    protected ActivityReviewDetailBinding getViewBinding() {
        return ActivityReviewDetailBinding.inflate(getLayoutInflater());
    }

    @Override
    protected void initView() {
        initToolBar("出库详情");
        mPresenter = new ReviewPresenterImpl(this);
        mPresenter.doReviewDetailList(this, item.getTaskId());
        mBinding.rvOutboundDetails.setLayoutManager(new LinearLayoutManager(mActivity));
        mAdapter = new ReviewDetailAdapter(R.layout.item_review_detail, list);
        mBinding.rvOutboundDetails.setAdapter(mAdapter);
    }

    @Override
    protected void setListener() {
        //复制按钮点击事件
        mBinding.tvTaskNo.setOnClickListener(v -> {
            StringUtil.copyToClipboard(this, item.getTaskNo());
        });

        //出库明细点击事件
        mAdapter.setOnItemClickListener(new ReviewDetailAdapter.OnItemClickListener() {
            @Override
            public void onCopy1ItemClick(int position, ReviewDetailListModel.RowsBean item) {
                StringUtil.copyToClipboard(mActivity, item.getBatchNo());
            }

            @Override
            public void onCopy2ItemClick(int position, ReviewDetailListModel.RowsBean item) {
                StringUtil.copyToClipboard(mActivity, item.getRfidTag());
            }
        });
    }

    @Override
    protected void initData() {
        //任务编号
        mBinding.tvTaskNo.setText(item.getTaskNo());
        switch (item.getTaskStatus()) {
            case "0":
                mBinding.tvTaskStatus.setText("未完成");
                mBinding.tvTaskStatus.setBackground(ContextCompat.getDrawable(this, R.drawable.status_red_bg));
                mBinding.tvTaskStatus.setTextColor(ContextCompat.getColor(this, R.color.red));
                break;
            case "1":
                mBinding.tvTaskStatus.setText("进行中");
                mBinding.tvTaskStatus.setBackground(ContextCompat.getDrawable(this, R.drawable.status_org_bg));
                mBinding.tvTaskStatus.setTextColor(ContextCompat.getColor(this, R.color.text_orange3));
                break;
            case "2":
                mBinding.tvTaskStatus.setText("已完成");
                mBinding.tvTaskStatus.setBackground(ContextCompat.getDrawable(this, R.drawable.status_green_bg));
                mBinding.tvTaskStatus.setTextColor(ContextCompat.getColor(this, R.color.green));
                break;
            case "3":
                mBinding.tvTaskStatus.setText("已结束");
                mBinding.tvTaskStatus.setBackground(ContextCompat.getDrawable(this, R.drawable.status_gray_bg));
                mBinding.tvTaskStatus.setTextColor(ContextCompat.getColor(this, R.color.c_6666));
                break;
            default:
                mBinding.tvTaskStatus.setText("-");
                mBinding.tvTaskStatus.setBackground(ContextCompat.getDrawable(this, R.drawable.status_gray_bg));
                mBinding.tvTaskStatus.setTextColor(ContextCompat.getColor(this, R.color.c_6666));
                break;
        }
        //任务名称
        mBinding.tvTaskName.setText(!StringUtils.isEmpty(item.getTaskName()) ? item.getTaskName() : "-");
        //仓库名称
        mBinding.txtWarehouseName.setText(!StringUtils.isEmpty(item.getWarehouseName()) ? item.getWarehouseName() : "-");
        //已盘数
        mBinding.txtReviewNumber.setText(item.getCountedItems() + "");
        //总盘点数
        mBinding.txtTotalNumber.setText(item.getTotalItems() + "");
        //出库人
        mBinding.txtRemark.setText(!StringUtils.isEmpty(item.getRemark()) ? item.getRemark() : "-");
    }


    @Override
    public void reviewSuccess(ReviewModel model) {

    }

    @Override
    public void reviewLoadMoreSuccess(ReviewModel model) {

    }

    @Override
    public void reviewDetailSuccess(ReviewDetailModel model) {

    }

    @Override
    public void reviewDetailListSuccess(ReviewDetailListModel model) {
        list.clear();
        mAdapter.setList(model.getRows());
    }

    @Override
    public void reviewResultSuccess(ReviewResultModel model) {

    }

    @Override
    public void deleteReviewTaskSuccess() {

    }

    @Override
    public void reviewScanTaskCheckSuccess(ReviewRfidTaskCheckModel model) {

    }

    @Override
    public void reviewRfidTaskCheckSuccess(ReviewRfidTaskCheckModel model) {

    }

    @Override
    public void stopReviewTaskSuccess() {

    }
}
