import{r as i,u as P,i as M,j as a,d as C}from"./react.6693569e.js";import{u as V,r as W,s as h,l as k,a as w}from"./index.b5b1089a.js";/* empty css               *//* empty css              */import{C as $}from"./Cover.fc91526c.js";import{f as q}from"./antd.5e666edb.js";import{g as F,a as H,b as J,G as K,C as Q,B as X}from"./Form.e3c93add.js";import{AppContext as Y}from"./App.b28509be.js";import{F as I,B as T,m as v}from"./antd.ef9542dc.js";/* empty css              *//* empty css               */import"./regular.2d81b23f.js";import"./index.c566a457.js";/* empty css               */import"./uno.aa306f28.js";import"./RSA.0dbe6c53.js";const Z="_complementInfo_azu4r_1",ee="_board_azu4r_8",te="_board__title_azu4r_20",se="_backToLoin_azu4r_31",oe="_board__content_azu4r_37",re="_board__bottom_azu4r_41",ne="_form_azu4r_47",ae="_fields_azu4r_56",u={complementInfo:Z,board:ee,board__title:te,backToLoin:se,board__content:oe,board__bottom:re,form:ne,fields:ae},{validateMessages:ce}=q,ie={labelCol:{span:4},wrapperCol:{span:18}};function S(r,l,d=[]){const _=r.find(p=>p.key===l);return _?(d.unshift(l),S(r,_.parent_key,d)):d}async function le(r){const l=await w.currentUserApi.getUserWhenComplementInfo();return r&&(l.type=S(r,l.type)),l}const ke=()=>{const{T:r}=V(),{setLoading:l}=i.exports.useContext(Y),d=P(),_=M(),[p]=I.useForm(),[g,N]=i.exports.useState([]),[O,x]=i.exports.useState({}),[z,G]=i.exports.useState([]),[L,j]=i.exports.useState([]),[m,E]=i.exports.useState({email:"",customField:{}});i.exports.useEffect(()=>{(async()=>{const{stand:e}=k.parse(d.search.slice(1));if(!e){const{waiting_approvals:n}=await w.currentUserApi.getCheckComplementInfo();if(n&&n.length>0)return _.replace(`/complement-approval?redirect_uri=${encodeURIComponent(window.location.href)}`)}l(!0);const s=await F();x(s);const o=await H();N(o.filter(n=>n.enabled&&n.required.length));const c=o.find(n=>n.key==="name");if(c!=null&&c.enabled){const n=await w.parametersApi.getSensitives();G(n.filter(y=>y.rule_for_user===1).map(y=>y.key))}const f=o.find(n=>n.key==="type");let b;if(f!=null&&f.enabled){const{original:n,tree:y}=await J();b=n,j(y)}const U=await le(b);E(U),l(!1),v.warn(r("complementInfo.warn"))})()},[]),i.exports.useEffect(()=>{W(()=>{var t;return(t=h.currentUserStore.currentUser)==null?void 0:t.type},async()=>{const t=await F();x(t)})},[]);const[R,A]=i.exports.useState({});i.exports.useEffect(()=>{p.resetFields();const t={...m,...m.customField},e=Object.keys(m).filter(o=>o.startsWith("__GROUP__")),s={};e.forEach(o=>{var f,b;const c=(b=(f=g[o])==null?void 0:f.extra)!=null&&b.mutiple?m[o].map(U=>({value:U.id,label:U.name})):m[o][0]?[{value:m[o][0].id,label:m[o][0].name}]:[];t[o]=c,s[o]=c.length>0}),A(s),p.setFieldsValue(t)},[p,m,g]);const B=(t,{customFields:e,sensitives:s,userTypes:o,disabled:c})=>{switch(t.scope){case"userbase":return a(X,{field:t,sensitives:s,userTypes:o},t.key);case"userdefine":return a(Q,{field:t,customField:e[t.key]},t.key);case"usergroup":return a(K,{field:t,disabled:c,form:p},t.key);default:return null}},D=t=>{const e=t[0];if(!e||!e.value||e.name[0]!=="type"||e.value[0]==="student"&&e.value[0].length<2)return;const s=e.value[0];h.currentUserStore.setCurrentUserType(s)};return a($,{children:a("div",{className:u.complementInfo,children:C("div",{className:u.board,children:[C("div",{className:u.board__title,children:[a("span",{children:r("complementInfo.title")}),a(T,{className:u.backToLoin,type:"link",onClick:()=>_.push("/logout"),children:r("complementInfo.logout")})]}),a("div",{className:u.board__content,children:C(I,{className:u.form,...ie,colon:!1,form:p,validateMessages:ce,onFieldsChange:D,onFinish:async t=>{try{const e=Object.assign({customField:{},create_group:[]},t);e.type=e.type&&e.type.slice().pop(),g.forEach(s=>{const o=s.key;s.scope==="userdefine"?(e.customField[o]=e[o],delete e[o]):o.indexOf("__GROUP__")===0&&(e[o]=e[o]?e[o].map(c=>c.value):[])}),Object.keys(e).forEach(s=>{s.indexOf("__JOIN__GROUP__")===0&&(e.create_group.push({...e[s],parent_id:e[s].parent_id.split("-").pop()}),delete e[s])}),e.create_group.length===0&&delete e.create_group,await h.currentUserStore.setCurrentUser(e),await h.authStore.completeInfo(),v.success(r("complementInfo.success")),setTimeout(()=>{const{redirect_uri:s}=k.parse(d.search.slice(1));window.location.href=decodeURIComponent(decodeURIComponent(s))||h.configStore.baseUrl},1e3)}catch(e){console.error(e);let s=r("complementInfo.error.basic");switch(e==null?void 0:e.message){case"email already exists":s=r("complementInfo.error.email");break;case"ref_no duplicated":s=r("complementInfo.error.refNo");break;case"wrong phone number":s=r("complementInfo.error.phone");break}v.error(s)}},children:[a("div",{className:u.fields,children:g.sort((t,e)=>t.index-e.index).map(t=>B(t,{customFields:O,sensitives:z,userTypes:L,disabled:R[t.key]}))}),a(I.Item,{children:a(T,{type:"primary",htmlType:"submit",style:{width:"110px"},children:r("complementInfo.submit")})})]})})]})})})};export{ke as default};
