import{q as g,C as q,H as ne,I as ee,J as H,K as ie,L as ae,_ as re,G as le,u as ce,c as f,a as t,i as l,d as F,k as E,t as h,F as R,r as O,v as I,x as U,m as ue,D as de,p as fe,o as d,j as P,b as X,w as z,e as pe,l as ve}from"./2JCroH3R.js";import{u as me}from"./Ba751Df4.js";import{i as _e}from"./CbPNayBJ.js";import"./DrJDeGiv.js";const he=(()=>{const e=function(){};return e.prototype=Object.create(null),e})();function ye(e,a){if(typeof e!="string")throw new TypeError("argument str must be a string");const s=new he,n=a||{},v=n.decode||ge;let u=0;for(;u{const a=decodeURIComponent(e),s=ne(a);return typeof s=="number"&&(!Number.isFinite(s)||String(s)!==a)?a:s},encode:e=>encodeURIComponent(typeof e=="string"?e:JSON.stringify(e))},M=globalThis.cookieStore;function Q(e,a){const s={...we,...a};s.filter??=p=>p===e;const n=Z(s)||{};let v;s.maxAge!==void 0?v=s.maxAge*1e3:s.expires&&(v=s.expires.getTime()-Date.now());const u=v!==void 0&&v<=0,c=u||n[e]===void 0||n[e]===null,r=S(u?void 0:n[e]??s.default?.()),m=v&&!u?Ae(r,v,s.watch&&s.watch!=="shallow"):g(r);{let p=null;try{!M&&typeof BroadcastChannel<"u"&&(p=new BroadcastChannel(`nuxt:cookies:${e}`))}catch{}const T=(y=!1)=>{!y&&(s.readonly||_e(m.value,n[e]))||(Se(e,m.value,s),n[e]=S(m.value),p?.postMessage({value:s.encode(m.value)}))},b=y=>{const k=y.refresh?Z(s)?.[e]:s.decode(y.value);C=!0,m.value=k,n[e]=S(k),ae(()=>{C=!1})};let C=!1;const j=!!ee();if(j&&H(()=>{C=!0,T(),p?.close()}),M){const y=k=>{const $=k.changed.find(x=>x.name===e),A=k.deleted.find(x=>x.name===e);$&&b({value:$.value}),A&&b({value:null})};M.addEventListener("change",y),j&&H(()=>M.removeEventListener("change",y))}else p&&(p.onmessage=({data:y})=>b(y));s.watch&&q(m,()=>{C||T()},{deep:s.watch!=="shallow"}),c&&T(c)}return m}function Z(e={}){return ye(document.cookie,e)}function Ce(e,a,s={}){return a==null?Y(e,a,{...s,maxAge:-1}):Y(e,a,s)}function Se(e,a,s={}){document.cookie=Ce(e,a,s)}const W=2147483647;function Ae(e,a,s){let n,v,u=0;const c=s?g(e):{value:e};return ee()&&H(()=>{v?.(),clearTimeout(n)}),ie((r,m)=>{s&&(v=q(c,m));function p(){const b=a-u,C=b{if(u+=C,u{c(),v.value&&(await u(),s.value&&(r.value=s.value,k.value={nickname:r.value.nickname||"",avatar:r.value.avatar||""},K()))}),q(v,async _=>{_?(await u(),s.value&&(r.value=s.value,k.value={nickname:r.value.nickname||"",avatar:r.value.avatar||""},K())):(r.value=null,C.value=[],j.value=[],y.value=[])});async function K(){if(!r.value)return;const _=Q("auth_token");if(!_.value)return;const o={Authorization:`Bearer ${_.value}`};try{const[D,i]=await Promise.allSettled([$fetch(`${a.public.apiBase}/api/user/posts/mine`,{headers:o}),$fetch(`${a.public.apiBase}/api/user/favorites`,{headers:o})]);if(D.status==="fulfilled"){const w=D.value,N=w&&w.code!==void 0?w.data:w;C.value=N?.list||[],b[0].count=N?.total||0}if(i.status==="fulfilled"){const w=i.value,N=w&&w.code!==void 0?w.data:w;j.value=Array.isArray(N)?N:[],b[1].count=Array.isArray(N)?N.length:0}y.value=[],b[2].count=0}catch{}}async function J(){if(L.value="",!A.value.phone||!A.value.password){L.value="请填写手机号和密码";return}x.value=!0;try{await n({username:A.value.phone,password:A.value.password}),m.value=!1}catch(_){L.value=_?.data?.message||_?.message||"登录失败,请重试"}finally{x.value=!1}}async function te(){$.value=!0;try{const _=Q("auth_token"),o=await $fetch(`${a.public.apiBase}/api/user/profile/update`,{method:"POST",headers:{Authorization:`Bearer ${_.value}`},body:k.value}),D=o&&o.code!==void 0?o.data:o;await u(),s.value&&(r.value=s.value)}catch{}finally{$.value=!1}}function G(_){return _?String(_).replace(/(\d{3})\d{4}(\d{4})/,"$1****$2"):"未绑定"}function V(_){return _?new Date(_).toLocaleDateString("zh-CN"):"-"}function oe(_){return{draft:"草稿",published:"已发布",rejected:"未通过"}[_]||_}function se(_){return{draft:"tag-warning",published:"tag-success",rejected:"tag-danger"}[_]||"tag-info"}return ce({title:"个人中心 - 智享生活",meta:[{name:"description",content:"管理您的个人信息、发布内容和收藏"},{name:"robots",content:"noindex"}]}),(_,o)=>{const D=pe;return d(),f("div",Ee,[t("div",Te,[l(r)?(d(),f("div",$e,[t("aside",De,[t("div",Ne,[t("div",Le,[l(r).avatar?(d(),f("img",{key:0,src:l(r).avatar,alt:l(r).nickname,onError:o[1]||(o[1]=i=>T.value=!0)},null,40,Re)):E("",!0),!l(r).avatar||l(T)?(d(),f("span",Oe,h((l(r).nickname||l(r).username||"?").charAt(0)),1)):E("",!0)]),t("h2",Ie,h(l(r).nickname||"未设置昵称"),1),t("p",Ue,h(G(l(r).phone)),1),t("span",Pe,h(l(r).role==="admin"?"管理员":"普通用户"),1)]),t("nav",Be,[(d(),f(R,null,O(b,i=>t("button",{key:i.key,class:P(["profile-nav__item",{active:l(p)===i.key}]),onClick:w=>p.value=i.key},[t("i",{class:P(i.icon)},null,2),t("span",null,h(i.label),1),i.count?(d(),f("span",Ve,h(i.count),1)):E("",!0)],10,Me)),64))])]),t("main",Fe,[l(p)==="posts"?(d(),f("section",ze,[o[15]||(o[15]=t("h2",{class:"profile-section__title"},"我的发布",-1)),l(C)?.length?(d(),f("div",He,[(d(!0),f(R,null,O(l(C),i=>(d(),f("div",{key:i.id,class:"post-item card"},[t("div",qe,[t("h3",null,h(i.title),1),t("p",null,h(i.summary),1),t("div",Ke,[t("span",{class:P(["tag",se(i.status)])},h(oe(i.status)),3),t("span",null,h(V(i.createdAt)),1)])]),t("div",Je,[X(D,{to:`/products/${i.id}`,class:"btn btn-sm btn-ghost"},{default:z(()=>[...o[12]||(o[12]=[F(" 查看 ",-1)])]),_:1},8,["to"]),o[13]||(o[13]=t("button",{class:"btn btn-sm btn-ghost",style:{color:"var(--color-danger)"}}," 删除 ",-1))])]))),128))])):(d(),f("div",Ge,[...o[14]||(o[14]=[t("i",{class:"fa-solid fa-file-circle-plus"},null,-1),t("p",null,"暂无发布内容",-1)])]))])):E("",!0),l(p)==="favorites"?(d(),f("section",Xe,[o[17]||(o[17]=t("h2",{class:"profile-section__title"},"我的收藏",-1)),l(j)?.length?(d(),f("div",Ye,[(d(!0),f(R,null,O(l(j),i=>(d(),ve(D,{key:i.id,to:`/products/${i.id}`,class:"favorite-item card"},{default:z(()=>[t("div",Qe,[t("img",{src:i.image||"/images/placeholder.png",alt:i.name},null,8,Ze)]),t("div",We,[t("h3",null,h(i.name),1),t("span",et,"¥"+h(Number(i.price??0).toFixed(2)),1),t("span",tt,"收藏于 "+h(V(i.favoritedAt)),1)])]),_:2},1032,["to"]))),128))])):(d(),f("div",ot,[...o[16]||(o[16]=[t("i",{class:"fa-regular fa-heart"},null,-1),t("p",null,"暂无收藏内容",-1)])]))])):E("",!0),l(p)==="reviews"?(d(),f("section",st,[o[19]||(o[19]=t("h2",{class:"profile-section__title"},"我的评价",-1)),l(y)?.length?(d(),f("div",nt,[(d(!0),f(R,null,O(l(y),i=>(d(),f("div",{key:i.id,class:"review-item card"},[t("div",it,[t("div",at,[(d(),f(R,null,O(5,w=>t("i",{key:w,class:P(["fa-solid fa-star rating-star",{active:w<=i.rating}])},null,2)),64))]),t("span",rt,h(V(i.createdAt)),1)]),t("p",lt,h(i.content),1),X(D,{to:`/stores/${i.storeId}`,class:"review-item__target"},{default:z(()=>[F(" 门店: "+h(i.storeName),1)]),_:2},1032,["to"])]))),128))])):(d(),f("div",ct,[...o[18]||(o[18]=[t("i",{class:"fa-regular fa-comment"},null,-1),t("p",null,"暂无评价",-1)])]))])):E("",!0),l(p)==="settings"?(d(),f("section",ut,[o[23]||(o[23]=t("h2",{class:"profile-section__title"},"账号设置",-1)),t("div",dt,[t("div",ft,[o[20]||(o[20]=t("label",null,"昵称",-1)),I(t("input",{"onUpdate:modelValue":o[2]||(o[2]=i=>l(k).nickname=i),type:"text",class:"form-input",placeholder:"请输入昵称"},null,512),[[U,l(k).nickname]])]),t("div",pt,[o[21]||(o[21]=t("label",null,"手机号",-1)),t("input",{value:G(l(r).phone),type:"text",class:"form-input",disabled:""},null,8,vt)]),t("div",mt,[o[22]||(o[22]=t("label",null,"头像URL",-1)),I(t("input",{"onUpdate:modelValue":o[3]||(o[3]=i=>l(k).avatar=i),type:"text",class:"form-input",placeholder:"输入头像图片URL"},null,512),[[U,l(k).avatar]])]),t("div",_t,[t("button",{class:"btn btn-primary",disabled:l($),onClick:te},h(l($)?"保存中...":"保存设置"),9,ht)])])])):E("",!0)])])):(d(),f("div",xe,[t("div",je,[o[9]||(o[9]=t("i",{class:"fa-solid fa-user-lock auth-prompt__icon"},null,-1)),o[10]||(o[10]=t("h2",null,"请先登录",-1)),o[11]||(o[11]=t("p",null,"登录后可查看个人中心",-1)),t("button",{class:"btn btn-primary btn-lg",onClick:o[0]||(o[0]=i=>m.value=!0)},[...o[8]||(o[8]=[t("i",{class:"fa-solid fa-right-to-bracket"},null,-1),F(" 立即登录 ",-1)])])])])),l(m)?(d(),f("div",{key:2,class:"modal-backdrop",onClick:o[7]||(o[7]=ue(i=>m.value=!1,["self"]))},[t("div",yt,[o[26]||(o[26]=t("h3",{class:"modal__title"},"登录",-1)),t("div",gt,[o[24]||(o[24]=t("label",null,"手机号",-1)),I(t("input",{"onUpdate:modelValue":o[4]||(o[4]=i=>l(A).phone=i),type:"tel",class:"form-input",placeholder:"请输入手机号"},null,512),[[U,l(A).phone]])]),t("div",bt,[o[25]||(o[25]=t("label",null,"密码",-1)),I(t("input",{"onUpdate:modelValue":o[5]||(o[5]=i=>l(A).password=i),type:"password",class:"form-input",placeholder:"请输入密码",onKeyup:de(J,["enter"])},null,544),[[U,l(A).password]])]),l(L)?(d(),f("div",kt,h(l(L)),1)):E("",!0),t("div",wt,[t("button",{class:"btn btn-ghost",onClick:o[6]||(o[6]=i=>m.value=!1)},"取消"),t("button",{class:"btn btn-primary",disabled:l(x),onClick:J},h(l(x)?"登录中...":"登录"),9,Ct)])])])):E("",!0)])])}}},jt=re(St,[["__scopeId","data-v-b69da949"]]);export{jt as default};