﻿// 提现记录页面
const { useState, useEffect } = React;

var WD_STATUS = { 0: { l: '待审核', c: '#d46b08', b: '#fff7e6' }, 1: { l: '已通过', c: '#389e0d', b: '#f6ffed' }, 2: { l: '已拒绝', c: '#cf1322', b: '#fff1f0' }, 3: { l: '已取消', c: '#999', b: '#f5f5f5' } };
var ACC_TYPE_MAP = { alipay: '支付宝', wechat: '微信', bank: '银行卡' };

function WithdrawRecordsPage() {
  var _l = useState([]); var list = _l[0], setList = _l[1];
  var _p = useState(1); var page = _p[0], setPage = _p[1];
  var _t = useState(0); var total = _t[0], setTotal = _t[1];
  var _ld = useState(true); var ld = _ld[0], sld = _ld[1];
  var pageSize = 20;

  function fetch(p) {
    sld(true);
    NK.Api.Wallet.withdraws(p || 1, pageSize).then(function(r) {
      if (r && r.code === 0) {
        setList(p > 1 ? function(prev) { return prev.concat(r.data.list); } : r.data.list);
        setTotal(r.data.total);
        setPage(p || 1);
      }
    }).finally(function() { sld(false); });
  }

  useEffect(function() { if (NK.Store.isLoggedIn()) fetch(1); }, []);

  var h = React.createElement;
function svgArrL(c){return h('svg',{width:20,height:20,viewBox:'0 0 24 24',fill:'none',stroke:c||'#334155',strokeWidth:1.875,strokeLinecap:'round',strokeLinejoin:'round'},h('path',{d:'M15 18l-6-6 6-6'}));}

  var fmt = function(n) { return '\u00A5' + (Number(n) || 0).toFixed(2); };
  var fmtTime = function(t) { return t ? new Date(t).toLocaleString('zh-CN') : ''; };

  if (!NK.Store.isLoggedIn()) return h('div',{className:'detail-page'},h('div',{className:'empty-state',style:{paddingTop:80}},h('div',{className:'eicon'},'\uD83D\uDD12'),h('div',null,'请先登录')));

  return h('div',{className:'detail-page'},
    h('div',{className:'back-header'},h('div',{className:'bbtn',onClick:function(){NK.Store.navigate('wallet')}},svgArrL()),h('div',{className:'btitle'},'提现记录')),
    list.length === 0 && !ld ? h('div',{className:'empty-state',style:{paddingTop:60}},h('div',{className:'eicon'},'\uD83D\uDCB3'),h('div',null,'暂无提现记录')) :
    h('div',{style:{padding:12}},
      list.map(function(item) {
        var st = WD_STATUS[item.status] || { l: '未知', c: '#999', b: '#f5f5f5' };
        return h('div',{key:item.id,className:'pub3-card',style:{marginBottom:8}},
          h('div',{style:{display:'flex',justifyContent:'space-between',alignItems:'center',marginBottom:8}},
            h('span',{style:{fontSize:18,fontWeight:700,color:'#333'}},fmt(item.amount)),
            h('span',{style:{padding:'3px 10px',borderRadius:10,fontSize:11,fontWeight:600,background:st.b,color:st.c}},st.l)
          ),
          h('div',{style:{fontSize:13,color:'#666',marginBottom:4}},ACC_TYPE_MAP[item.accountType] || item.accountType, ' · ', item.accountName, ' · ', (item.accountNo||'').substring(0,4)+'****'),
          h('div',{style:{fontSize:12,color:'#999'}},'申请: ', fmtTime(item.createTime)),
          item.processedAt ? h('div',{style:{fontSize:12,color:'#999'}},'处理: ', fmtTime(item.processedAt)) : null,
          item.rejectReason ? h('div',{style:{fontSize:12,color:'#cf1322',marginTop:4}},'拒绝原因: ', item.rejectReason) : null
        );
      }),
      ld && h('div',{style:{textAlign:'center',padding:16,color:'#999'}},'加载中...'),
      list.length > 0 && list.length < total ? h('div',{style:{textAlign:'center',padding:'8px 0'}},h('button',{onClick:function(){fetch(page+1)},className:'pub3-add-btn'},'加载更多')) : null
    )
  );
}
window.NK = window.NK || {}; NK.WithdrawRecordsPage = WithdrawRecordsPage;