/**
 * 抢单前检查（仅点击抢单时调用）
 */
import request from './request.js';

/** 检查是否有待处理罚款（待缴纳 / 申诉中） */
export async function checkPenaltyForGrab() {
  try {
    const res = await request({ url: '/yonghu/cffktjhq', method: 'POST' });
    if (res?.data?.code === 0) {
      const fk = res.data.data?.fakuan || {};
      const pending = Number(fk.daijiaona || 0) + Number(fk.shensuzhong || 0);
      if (pending > 0) {
        return {
          blocked: true,
          msg: '您有未缴纳或申诉中的罚单，请先处理后再抢单',
          url: '/pages/penalty/penalty/penalty',
        };
      }
    }
  } catch (e) {
    console.error('checkPenaltyForGrab failed', e);
  }
  return { blocked: false };
}
