import{i as e,t}from"./react-B8IZ02wI.js";import{t as n}from"./button-DqbiydrF.js";import{t as r}from"./select-CDwQ-YxO.js";import{t as i}from"./card-R6qklktc.js";import{t as a}from"./typography-Chzsf8_A.js";import{t as o}from"./upload-CFPSOK3x.js";import{t as s}from"./DownloadOutlined-EB2n7dTj.js";import{y as c}from"./authStore-BvQBJ9ky.js";import{Sn as l,at as u,ct as d,gt as f,n as p,st as m,tt as h}from"./index-Bg7bo8aA.js";var g=e(t(),1),_=p(),v={devices:`devices`,sim:`simCards`,accounts:`accounts`,users:`users`},y={devices:`设备`,sim:`SIM卡`,accounts:`社媒账号`,users:`员工`},b={devices:`/templates/设备导入模板.csv`,sim:`/templates/SIM卡导入模板.csv`,accounts:`/templates/账号导入模板.csv`,users:`/templates/员工导入模板.csv`},x={devices:{tip:`导入前请确保关联员工（使用人手机号）已存在。`,unique:`唯一键：IMEI1`,note:`可通过「使用人手机号」关联员工`},sim:{tip:`建议先完成员工导入，再导入号码资产。`,unique:`唯一键：手机号码`,note:`支持开卡实名人、身份证号等字段`},accounts:{tip:`需先存在对应 SIM 卡（绑定手机号）。`,unique:`唯一键：平台 + 平台账号ID`,note:`个人号/企业号扩展字段按模板列填写`},users:{tip:`员工通常最先导入，供后续资产关联使用人。`,unique:`唯一键：手机号 / 用户名`,note:`角色可多选，逗号分隔`}};function S({open:e,assetType:t,onClose:p,onSuccess:S}){let[C,w]=(0,g.useState)(`ABORT`),[T,E]=(0,g.useState)(!1),[D,O]=(0,g.useState)(null),k=x[t];(0,g.useEffect)(()=>{e&&(w(`ABORT`),O(null),E(!1))},[e,t]);let A={accept:`.csv,.xlsx`,showUploadList:!1,disabled:T,className:`import-upload`,customRequest:async e=>{let n=e.file;E(!0),O(null);try{let r=c[v[t]],i=await r(n,C),a=i.data;O(a);let o=[`新增 ${a.created} 条`];a.skipped&&o.push(`跳过 ${a.skipped} 条`),a.errors?.length&&o.push(`${a.errors.length} 条错误`),d.success(`导入完成：${o.join(`，`)}`),e.onSuccess?.(i),(a.created>0||(a.skipped??0)>0)&&S?.()}catch(t){d.error(t instanceof Error?t.message:`导入失败`),e.onError?.(t instanceof Error?t:Error(`导入失败`))}finally{E(!1)}}};return(0,_.jsxs)(m,{title:`批量导入${y[t]}`,open:e,onCancel:p,footer:null,width:640,destroyOnHidden:!0,children:[(0,_.jsx)(l,{type:`info`,showIcon:!0,style:{marginBottom:16},title:k.tip,description:(0,_.jsxs)(`span`,{children:[`推荐导入顺序：员工 → 设备 → 号码 → 账号。`,k.unique,k.note?` · ${k.note}`:``]})}),(0,_.jsxs)(`div`,{style:{display:`flex`,gap:12,marginBottom:16,flexWrap:`wrap`,alignItems:`flex-end`},children:[(0,_.jsxs)(`div`,{style:{flex:`1 1 180px`},children:[(0,_.jsx)(a.Text,{type:`secondary`,style:{display:`block`,marginBottom:4,fontSize:12},children:`冲突处理`}),(0,_.jsx)(r,{style:{width:`100%`},value:C,onChange:w,options:[{value:`ABORT`,label:`停止并报告（默认）`},{value:`SKIP`,label:`跳过重复`}]})]}),(0,_.jsx)(n,{type:`link`,icon:(0,_.jsx)(s,{}),href:b[t],download:!0,children:`下载导入模板`})]}),(0,_.jsx)(i,{size:`small`,style:{marginBottom:16,background:`#f9fafb`},children:(0,_.jsxs)(f,{wrap:!0,size:[16,8],children:[(0,_.jsxs)(`span`,{children:[(0,_.jsx)(a.Text,{type:`secondary`,children:`唯一性：`}),` `,k.unique]}),k.note&&(0,_.jsxs)(`span`,{children:[(0,_.jsx)(a.Text,{type:`secondary`,children:`说明：`}),` `,k.note]})]})}),(0,_.jsxs)(o.Dragger,{...A,children:[(0,_.jsx)(`p`,{className:`ant-upload-drag-icon`,children:(0,_.jsx)(h,{style:{fontSize:48,color:`#0d9488`}})}),(0,_.jsx)(`p`,{className:`ant-upload-text`,children:`将 Excel / CSV 文件拖拽到此处，或点击上传`}),(0,_.jsx)(`p`,{className:`ant-upload-hint`,children:`支持 .xlsx、.csv（UTF-8 BOM）`})]}),D&&(0,_.jsx)(l,{style:{marginTop:16},type:D.errors?.length?`warning`:`success`,showIcon:!0,title:`最近一次导入结果`,description:(0,_.jsxs)(`div`,{children:[(0,_.jsxs)(f,{wrap:!0,children:[(0,_.jsxs)(u,{color:`success`,children:[`新增 `,D.created]}),D.skipped!=null&&D.skipped>0&&(0,_.jsxs)(u,{children:[`跳过 `,D.skipped]})]}),D.errors&&D.errors.length>0&&(0,_.jsx)(`ul`,{style:{margin:`8px 0 0`,paddingLeft:18,fontSize:12},children:D.errors.map(e=>(0,_.jsx)(`li`,{children:e},e))})]})}),(0,_.jsx)(a.Paragraph,{type:`secondary`,style:{marginTop:16,marginBottom:0,fontSize:13},children:`导入前请确保列名与模板一致。敏感字段（密码、身份证号）导入后将自动加密存储。`})]})}export{S as t};