(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,47430,e=>{"use strict";var t,r,a=e.i(36792),s=e.i(82772),l=e.i(92879),n=e.i(9991),d=e.i(10743),i=e.i(42864),c=e.i(26922),o=e.i(27706);let h=(0,o.default)("TriangleAlert",[["path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3",key:"wmoenq"}],["path",{d:"M12 9v4",key:"juzpu7"}],["path",{d:"M12 17h.01",key:"p32p05"}]]),u=(0,o.default)("FileText",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M10 9H8",key:"b1mrlr"}],["path",{d:"M16 13H8",key:"t4e002"}],["path",{d:"M16 17H8",key:"z1uh3a"}]]),f=(0,o.default)("Database",[["ellipse",{cx:"12",cy:"5",rx:"9",ry:"3",key:"msslwz"}],["path",{d:"M3 5V19A9 3 0 0 0 21 19V5",key:"1wlel7"}],["path",{d:"M3 12A9 3 0 0 0 21 12",key:"mv7ke4"}]]);var p=e.i(21446),x=e.i(34346);let m=(e,t)=>{let r=t.prototype;Object.setPrototypeOf?Object.setPrototypeOf(e,r):(void 0).__proto__=r};class g extends Error{constructor(e){super(e),m(this,new.target)}}class N extends g{constructor(e){super(e),this.message=e,m(this,new.target)}}class b extends N{}class j extends N{constructor(e,t){super(e),this.illegalCode=t,m(this,new.target)}}class v extends N{constructor(e,t){super(e),this.charset=t,m(this,new.target)}}class y extends N{constructor(e,t,r){super(e),this.lineNumber=t,this.line=r,m(this,new.target)}}class w extends N{constructor(e,t){super(e),this.lineNumber=t,m(this,new.target)}}class E extends w{constructor(e,t,r,a){super(e,t),this.lineNumber=t,this.currentLevel=r,this.level=a,m(this,new.target)}}class C extends w{constructor(e,t,r){super(e,t),this.lineNumber=t,this.kind=r,m(this,new.target)}}class I extends w{constructor(e,t){super(e,t),m(this,new.target)}}class S extends N{constructor(e){super(e),m(this,new.target)}}class A extends N{constructor(e){super(e),m(this,new.target)}}class T extends A{constructor(e,t,r,a){super(e),this.lineNumber=t,this.lineNumberOriginalDefinition=r,this.pointer=a,m(this,new.target)}}let $="A-Za-z0-9",O=`[${$}][${$} ]*`,R=`@#(?:${O})@`,M=`[${$}-_]+`,D=`[^\\x00-\\x08\\x0A-\\x1F\\r\\n@]|@`,U=`(?:${D})*`,F=`${R}|${U}|${R}[ ]${U}`,k=`@${M}@`,L=`${k}`,H=`${L}|(?:${F})`,P=`[${$}]+|_[${$}_]+`,B=`\\r\\n?|\\n`,_=`([1-9][0-9]+|[0-9])(?: (${k}))? (${P})(?: (${H}))?(${B}|$)`;class G{constructor(e,t){this.input=e,this.strict=t,this.rGedcomLines=RegExp(`^${_}`,"gym"),this.linesRead=0,this.charactersRead=0}[Symbol.iterator](){return this}next(){let e=this.rGedcomLines.exec(this.input);if(null!==e&&(0!==e[5].length||this.charactersRead+e[0].length===this.input.length))return this.charactersRead+=e[0].length,this.linesRead++,{done:!1,value:e};{null!==e&&(this.charactersRead+=e[0].length);let t=this.charactersRead===this.input.length;if(this.strict&&!t){let e=this.input.substring(this.charactersRead,Math.min(this.charactersRead+256,this.input.length)).split(/[\r\n]+/,1)[0];throw new y(`Invalid format for line ${this.linesRead+1}: "${e}"`,this.linesRead+1,e)}return{done:!0,value:null}}}}let W=(e,t=!0)=>new G(e,t),V=(e,t=!1,r=null)=>{r&&r(0);let a=0,s=0,l=-1,n=[{tag:null,pointer:null,value:null,indexSource:-1,indexRelative:0,children:[]}];for(let d of e){let[e,i,c,o,h]=d,u=h?h.replace(/@@/g,"@"):h;s+=e.length;let f=parseInt(i),p=f<=l,x=f===l+1;if(f<0||!p&&!x)throw new E(`Illegal nesting level at line ${a+1} (current is ${l}, got ${f})`,a+1,l,f);let m=l-f+1;for(let e=0;e0)throw new I(`Record must be a top-level definition at line ${a+1}`,a+1);n.push(e),l=f}else{if(c)throw new C(`Illegal continuation format at line ${a+1}`,a+1,"CONT");if(!g)throw new C(`Continuation with no parent at line ${a+1}`,a+1,"CONT");null==g.value&&(g.value=""),g.value+="\n"+(null!=u?u:""),l=f-1}else{if(c)throw new C(`Illegal concatenation format at line ${a+1}`,a+1,"CONC");if(!g)throw new C(`Concatenation with no parent at line ${a+1}`,a+1,"CONC");null==g.value&&(g.value=""),g.value+=null!=u?u:"",l=f-1}a++,r&&a%5e4==0&&r(s)}return r&&r(s),n[0]},J=[239,187,191],z=[254,255],q=z.slice().reverse(),X=[0,0,254,255],Y=X.slice().reverse(),K="utf-8",Z="utf-16be",Q="utf-16le",ee=(e,t,r)=>{r&&r(0);let a="",s=new Uint8Array(e);for(let e=0;e{let r;t&&t(0);let a=new Uint8Array(e),s=e=>{if(a.length({charset:e,bom:t})).find(({bom:e})=>s(e));if([X,Y].some(e=>s(e)))throw new v("Unsupported charset detected from BOM: 'utf-32'","utf-32");let n=void 0!==l?l.charset:null,d=void 0!==l?a.slice(l.bom.length):a,i=null!==n?n:K;if(i===K)r=((e,t)=>{let r="",a=new Uint8Array(e),s=0;for(let e,t=a.length;s251&&e<254&&s+5247&&e<252&&s+4239&&e<248&&s+3223&&e<240&&s+2191&&e<224&&s+1{let r={};e.children.forEach((e,t)=>{null!==e.tag&&(void 0===r[e.tag]&&(r[e.tag]=[]),r[e.tag].push(t))}),Object.defineProperty(e,"_index",{enumerable:t,configurable:!0,writable:!0}),e._index={byTag:r}},ea=e=>{let t={};e.children.forEach((r,a)=>{if(null!==r.tag&&null!==r.pointer){if(void 0===t[r.tag]&&(t[r.tag]={}),void 0!==t[r.tag][r.pointer])throw new T(`Duplicate pointer: ${r.pointer}`,r.indexSource+1,e.children[t[r.tag][r.pointer]].indexSource,r.pointer);t[r.tag][r.pointer]=a}}),e._index.byTagPointer=t};function es(e){let t=new Date(e);return`${t.getDate()} ${["JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC"][t.getMonth()]} ${t.getFullYear()}`}function el(e){let t=e.trim().split(" ");if(3===t.length){let e=parseInt(t[0]),r={JAN:0,FEB:1,MAR:2,APR:3,MAY:4,JUN:5,JUL:6,AUG:7,SEP:8,OCT:9,NOV:10,DEC:11}[t[1].toUpperCase()],a=parseInt(t[2]);if(!isNaN(e)&&void 0!==r&&!isNaN(a))return new Date(a,r,e).toISOString().split("T")[0]}return 1!==t.length||isNaN(parseInt(t[0]))?new Date().toISOString().split("T")[0]:`${t[0]}-01-01`}var en=e.i(43840),ed=e.i(90672),ei=e.i(50314);let ec=(0,o.default)("History",[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}],["path",{d:"M12 7v5l4 2",key:"1fdv2h"}]]);var eo=e.i(34072);let eh=(0,o.default)("RefreshCw",[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]]),eu=(0,o.default)("Image",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2",key:"1m3agn"}],["circle",{cx:"9",cy:"9",r:"2",key:"af1f0g"}],["path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21",key:"1xmnt7"}]]);var ef=e.i(51788),ep=e.i(58051),ex=e.i(86467),em=e.i(87830),eg=e.i(75212);let eN={CREATE:"创建",UPDATE:"更新",DELETE:"删除",IMPORT:"导入",EXPORT:"导出"},eb={CREATE:"bg-green-500",UPDATE:"bg-blue-500",DELETE:"bg-red-500",IMPORT:"bg-purple-500",EXPORT:"bg-orange-500"},ej={MEMBER:"成员",PHOTO:"照片",STORY:"故事",SETTINGS:"设置"},ev={MEMBER:p.User,PHOTO:eu,STORY:u,SETTINGS:ef.Settings};function ey(){let{currentTree:e}=(0,l.useFamily)(),{data:t}=(0,em.useSession)(),{showAlert:r,showConfirm:s,showPrompt:i}=(0,eg.useDialog)(),[c,o]=(0,x.useState)([]),[h,f]=(0,x.useState)([]),[p,m]=(0,x.useState)(!1),[g,N]=(0,x.useState)(null),[b,j]=(0,x.useState)("all"),[v,y]=(0,x.useState)(!1);(0,x.useEffect)(()=>{fetch("/api/trees").then(e=>e.json()).then(e=>{e.trees&&f(e.trees)}).catch(e=>console.error("加载家族树列表失败:",e))},[]),(0,x.useEffect)(()=>{e?.id&&j(e.id)},[e?.id]);let w=async()=>{m(!0),N(null);try{let e="";e="all"===b?"/api/user/activity-logs?limit=100":`/api/trees/${b}/activity-logs?limit=100`;let t=await fetch(e);if(!t.ok)throw Error("获取日志失败");let r=await t.json();o(r.logs||[])}catch(e){console.error("加载日志失败:",e),N(e instanceof Error?e.message:"加载失败")}finally{m(!1)}};(0,x.useEffect)(()=>{w()},[b]);let E=async()=>{if("all"===b)return void await r("请先选择一个具体的家族树再清空日志","提示");let e=h.find(e=>e.id===b);if(!e)return void await r("未找到选中的家族树","错误");let t=`⚠️ 警告:即将清空"${e.name}"的所有操作日志! 此操作将永久删除该家族树的所有历史记录,且不可恢复。 确定要继续吗?`;if(await s(t,"清空操作日志","destructive")){if(await i(`请输入家族树名称"${e.name}"以确认清空操作: (此操作不可撤销)`,"","确认清空")!==e.name)return void await r("名称不匹配,操作已取消","操作已取消");y(!0);try{let e=await fetch(`/api/trees/${b}/activity-logs`,{method:"DELETE"});if(!e.ok){let t=await e.json();throw Error(t.error||"清空失败")}let t=await e.json();await r(t.message||"操作日志已清空","成功"),await w()}catch(e){console.error("清空日志失败:",e),await r("清空失败:"+(e instanceof Error?e.message:"未知错误"),"错误")}finally{y(!1)}}};return(0,a.jsx)("div",{className:"space-y-6",children:(0,a.jsxs)(d.Card,{children:[(0,a.jsx)(d.CardHeader,{children:(0,a.jsxs)("div",{className:"flex flex-col md:flex-row md:items-center justify-between gap-4",children:[(0,a.jsxs)("div",{children:[(0,a.jsxs)(d.CardTitle,{className:"flex items-center gap-2",children:[(0,a.jsx)(ec,{className:"h-5 w-5"}),"操作日志"]}),(0,a.jsx)(d.CardDescription,{children:"查看家族树的变更记录"})]}),(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)(n.Button,{variant:"outline",size:"icon",onClick:w,disabled:p||v,className:"h-9 w-9",title:"刷新日志",children:(0,a.jsx)(eh,{className:`h-4 w-4 ${p?"animate-spin":""}`})}),(()=>{if("all"===b)return!1;let e=h.find(e=>e.id===b);return!!e&&(e.ownerId===t?.user?.id||"OWNER"===e.currentUserRole)})()&&(0,a.jsxs)(n.Button,{variant:"destructive",size:"sm",onClick:E,disabled:p||v,className:"gap-2",title:"清空当前家族树的操作日志(仅所有者可用)",children:[(0,a.jsx)(eo.Trash2,{className:"h-4 w-4"}),v?"清空中...":"清空日志"]}),(0,a.jsx)("div",{className:"w-[200px]",children:(0,a.jsxs)(ei.Select,{value:b,onValueChange:j,children:[(0,a.jsx)(ei.SelectTrigger,{children:(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)(ep.Filter,{className:"h-4 w-4 text-muted-foreground"}),(0,a.jsx)(ei.SelectValue,{placeholder:"筛选家族树"})]})}),(0,a.jsxs)(ei.SelectContent,{children:[(0,a.jsx)(ei.SelectItem,{value:"all",children:"所有家族树"}),h.map(e=>(0,a.jsx)(ei.SelectItem,{value:e.id,children:e.name},e.id))]})]})})]})]})}),(0,a.jsx)(d.CardContent,{children:(0,a.jsx)(en.ScrollArea,{className:"h-[400px] pr-4",children:g?(0,a.jsxs)("div",{className:"text-center py-8 text-destructive",children:["加载失败: ",g]}):p&&0===c.length?(0,a.jsx)("div",{className:"text-center py-8 text-muted-foreground",children:"加载中..."}):0===c.length?(0,a.jsx)("div",{className:"text-center py-8 text-muted-foreground",children:"暂无操作记录"}):(0,a.jsx)("div",{className:"space-y-3",children:c.map(e=>{let t=ev[e.entityType]||u;return(0,a.jsxs)("div",{className:"flex items-start gap-3 p-3 bg-muted/50 rounded-lg hover:bg-muted transition-colors",children:[(0,a.jsx)("div",{className:`p-2 rounded-full ${eb[e.action]} bg-opacity-10`,children:(0,a.jsx)(t,{className:`h-4 w-4 ${eb[e.action].replace("bg-","text-")}`})}),(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2 mb-1 flex-wrap",children:[(0,a.jsx)(ed.Badge,{variant:"outline",className:"text-xs",children:eN[e.action]||e.action}),(0,a.jsx)(ed.Badge,{variant:"secondary",className:"text-xs",children:ej[e.entityType]||e.entityType}),"all"===b&&e.tree&&(0,a.jsx)(ed.Badge,{variant:"outline",className:"text-xs bg-blue-50 text-blue-700 border-blue-200",children:e.tree.name}),e.entityName&&(0,a.jsx)("span",{className:"text-sm font-medium truncate",children:e.entityName})]}),(0,a.jsxs)("div",{className:"flex items-center justify-between",children:[(0,a.jsx)("p",{className:"text-xs text-muted-foreground",children:e.user?.name||e.user?.email||"未知用户"}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground",children:(0,ex.format)(new Date(e.timestamp),"yyyy-MM-dd HH:mm:ss")})]}),e.changes&&Object.keys(e.changes).length>0&&(0,a.jsxs)("details",{className:"mt-2",children:[(0,a.jsx)("summary",{className:"text-xs text-muted-foreground cursor-pointer hover:text-foreground",children:"查看变更详情"}),(0,a.jsx)("pre",{className:"text-xs mt-1 p-2 bg-background rounded overflow-x-auto",children:JSON.stringify(e.changes,null,2)})]})]})]},e.id)})})})})]})})}var ew=x;class eE extends ew.default.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,t){console.error("ErrorBoundary 捕获错误:",e,t)}render(){return this.state.hasError?this.props.fallback||(0,a.jsxs)("div",{className:"p-4 border border-destructive rounded-lg bg-destructive/10",children:[(0,a.jsx)("h3",{className:"text-lg font-bold text-destructive mb-2",children:"组件加载失败"}),(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:this.state.error?.message||"未知错误"}),(0,a.jsx)("button",{className:"mt-4 px-4 py-2 bg-primary text-primary-foreground rounded",onClick:()=>this.setState({hasError:!1}),children:"重试"})]}):this.props.children}}var eC=e.i(59786),eI=e.i(77627),eS=e.i(75985),eA=e.i(12039);let eT=(0,o.default)("Lock",[["rect",{width:"18",height:"11",x:"3",y:"11",rx:"2",ry:"2",key:"1w4ew1"}],["path",{d:"M7 11V7a5 5 0 0 1 10 0v4",key:"fwvmzm"}]]),e$=(0,o.default)("CircleCheck",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]);function eO(){let[e,t]=(0,x.useState)(""),[r,s]=(0,x.useState)(""),[l,i]=(0,x.useState)(""),[c,o]=(0,x.useState)(!1),[h,u]=(0,x.useState)(""),[f,p]=(0,x.useState)(!1),m=async a=>{a.preventDefault(),u(""),p(!1),o(!0);try{let a=await fetch("/api/user/change-password",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({currentPassword:e,newPassword:r,confirmPassword:l})}),n=await a.json();if(!a.ok)return void u(n.error||"修改密码失败");p(!0),t(""),s(""),i(""),setTimeout(()=>p(!1),3e3)}catch(e){u("修改密码失败,请稍后重试")}finally{o(!1)}};return(0,a.jsxs)(d.Card,{children:[(0,a.jsxs)(d.CardHeader,{children:[(0,a.jsxs)(d.CardTitle,{className:"flex items-center gap-2",children:[(0,a.jsx)(eT,{className:"h-5 w-5"})," 修改密码"]}),(0,a.jsx)(d.CardDescription,{children:"更改您的登录密码"})]}),(0,a.jsx)(d.CardContent,{children:(0,a.jsxs)("form",{onSubmit:m,className:"space-y-4",children:[h&&(0,a.jsx)(eA.Alert,{variant:"destructive",children:(0,a.jsx)(eA.AlertDescription,{children:h})}),f&&(0,a.jsxs)(eA.Alert,{className:"bg-green-50 border-green-200",children:[(0,a.jsx)(e$,{className:"h-4 w-4 text-green-600"}),(0,a.jsx)(eA.AlertDescription,{className:"text-green-800",children:"密码修改成功!"})]}),(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(eS.Label,{htmlFor:"currentPassword",children:"当前密码"}),(0,a.jsx)(eI.Input,{id:"currentPassword",type:"password",placeholder:"输入当前密码",value:e,onChange:e=>t(e.target.value),required:!0,disabled:c})]}),(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(eS.Label,{htmlFor:"newPassword",children:"新密码"}),(0,a.jsx)(eI.Input,{id:"newPassword",type:"password",placeholder:"至少6个字符",value:r,onChange:e=>s(e.target.value),required:!0,disabled:c,minLength:6})]}),(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(eS.Label,{htmlFor:"confirmPassword",children:"确认新密码"}),(0,a.jsx)(eI.Input,{id:"confirmPassword",type:"password",placeholder:"再次输入新密码",value:l,onChange:e=>i(e.target.value),required:!0,disabled:c})]}),(0,a.jsx)(n.Button,{type:"submit",disabled:c,className:"w-full",children:c?"修改中...":"修改密码"})]})})]})}function eR(){let{treeData:e,loadData:t,resetData:r}=(0,l.useFamily)(),{data:o}=(0,em.useSession)(),{showAlert:m,showConfirm:g}=(0,eg.useDialog)(),[N,y]=(0,x.useState)(""),[w,E]=(0,x.useState)(""),[C,I]=(0,x.useState)(null),A=(0,x.useRef)(null),T=(0,x.useRef)(null);(0,x.useEffect)(()=>{o?.user?.id&&fetch("/api/user/profile").then(e=>e.json()).then(e=>{e.user&&I(e.user)}).catch(e=>console.error("获取用户资料失败:",e))},[o?.user?.id]);let $=e=>({OWNER:"所有者",EDITOR:"编辑者",VIEWER:"查看者"})[e]||e,O=e=>({OWNER:"bg-purple-100 text-purple-700 border-purple-200",EDITOR:"bg-blue-100 text-blue-700 border-blue-200",VIEWER:"bg-gray-100 text-gray-700 border-gray-200"})[e]||"bg-gray-100 text-gray-700";return(0,a.jsxs)("div",{className:"min-h-screen bg-background flex flex-col font-sans",children:[(0,a.jsx)(s.SiteHeader,{}),(0,a.jsxs)("main",{className:"container mx-auto py-8 px-4 md:px-6 flex-1 max-w-6xl",children:[(0,a.jsx)("h1",{className:"text-3xl font-serif font-bold mb-8",children:"系统设置 (Settings)"}),(0,a.jsxs)("div",{className:"space-y-6",children:[o&&(0,a.jsxs)("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[(0,a.jsxs)(d.Card,{children:[(0,a.jsxs)(d.CardHeader,{children:[(0,a.jsxs)(d.CardTitle,{className:"flex items-center gap-2",children:[(0,a.jsx)(p.User,{className:"h-5 w-5"})," 系统设置"]}),(0,a.jsx)(d.CardDescription,{children:"您的账号信息和角色"})]}),(0,a.jsxs)(d.CardContent,{className:"space-y-4",children:[(0,a.jsxs)("div",{className:"flex items-center gap-4",children:[(0,a.jsx)(eC.Avatar,{className:"h-16 w-16 border-2 border-border",children:(0,a.jsx)(eC.AvatarFallback,{className:"text-2xl",children:o?.user?.name?o.user.name.charAt(0).toUpperCase():o?.user?.email?o.user.email.charAt(0).toUpperCase():"U"})}),(0,a.jsxs)("div",{className:"flex-1",children:[(0,a.jsx)("h3",{className:"text-lg font-semibold",children:o.user?.name||"用户"}),(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:o.user?.email}),(0,a.jsxs)("p",{className:"text-xs text-muted-foreground mt-1",children:["用户 ID: ",o.user?.id]})]})]}),C&&(C.ownedTreesCount>0||C.collaborations.length>0)&&(0,a.jsxs)("div",{className:"space-y-3 pt-3 border-t",children:[(0,a.jsx)("p",{className:"text-sm font-medium",children:"我的家族树"}),(0,a.jsxs)("div",{className:"space-y-2",children:[C.ownedTreesCount>0&&(0,a.jsxs)("div",{className:"text-sm text-muted-foreground",children:[(0,a.jsx)("span",{className:`inline-flex items-center px-2 py-1 rounded-full border text-xs ${O("OWNER")}`,children:$("OWNER")}),(0,a.jsxs)("span",{className:"ml-2",children:[C.ownedTreesCount," 个家族树"]})]}),C.collaborations.length>0&&(0,a.jsx)("div",{className:"space-y-2",children:C.collaborations.map(e=>(0,a.jsxs)("div",{className:"flex items-center justify-between text-sm p-2 rounded-md bg-muted/50",children:[(0,a.jsx)("span",{className:"text-muted-foreground truncate flex-1",children:e.treeName}),(0,a.jsx)("span",{className:`text-xs px-2 py-1 rounded-full border ${O(e.role)}`,children:$(e.role)})]},e.treeId))})]})]}),(0,a.jsxs)("div",{className:"pt-3 border-t",children:[(0,a.jsxs)("p",{className:"text-sm font-medium text-destructive mb-2 flex items-center gap-2",children:[(0,a.jsx)(h,{className:"h-4 w-4"})," 危险区域"]}),(0,a.jsx)(n.Button,{variant:"destructive",size:"sm",className:"w-full",onClick:async()=>{await g("确定要重置吗?所有更改将丢失。","重置数据","destructive")&&(await r(),await m("数据已重置为演示状态。","成功"))},children:"重置所有数据"})]})]})]}),(0,a.jsx)(eO,{})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[(0,a.jsxs)(d.Card,{children:[(0,a.jsxs)(d.CardHeader,{children:[(0,a.jsxs)(d.CardTitle,{className:"flex items-center gap-2",children:[(0,a.jsx)(f,{className:"h-5 w-5"})," 数据管理 (Data Management)"]}),(0,a.jsx)(d.CardDescription,{children:"备份和恢复家族树数据。"})]}),(0,a.jsxs)(d.CardContent,{className:"space-y-6",children:[(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsxs)("h3",{className:"text-sm font-medium flex items-center gap-2",children:[(0,a.jsx)(i.Download,{className:"h-4 w-4"})," 数据备份"]}),(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:"将家族数据导出为 JSON 文件进行本地保存。"}),(0,a.jsx)(n.Button,{onClick:()=>{let t=new Blob([JSON.stringify(e,null,2)],{type:"application/json"}),r=URL.createObjectURL(t),a=document.createElement("a");a.href=r,a.download=`family_tree_backup_${new Date().toISOString().split("T")[0]}.json`,document.body.appendChild(a),a.click(),document.body.removeChild(a)},children:"导出数据 (Export JSON)"})]}),(0,a.jsx)("div",{className:"border-t"}),(0,a.jsxs)("div",{className:"space-y-4",children:[(0,a.jsxs)("div",{children:[(0,a.jsxs)("h3",{className:"text-sm font-medium flex items-center gap-2",children:[(0,a.jsx)(c.Upload,{className:"h-4 w-4"})," 数据恢复"]}),(0,a.jsx)("p",{className:"text-sm text-muted-foreground mt-1",children:"从 JSON 备份文件恢复数据。这将覆盖当前数据。"})]}),(0,a.jsxs)("div",{className:"flex items-center gap-4",children:[(0,a.jsx)("input",{type:"file",ref:A,className:"hidden",accept:".json",onChange:async e=>{let r=e.target.files?.[0];if(!r)return;if(!await g("恢复数据将覆盖当前所有数据,确定继续吗?","恢复数据","destructive")){A.current&&(A.current.value="");return}let a=new FileReader;a.onload=async e=>{try{let r=e.target?.result,a=JSON.parse(r);await t(a),y("导入成功!"),A.current&&(A.current.value="")}catch(e){console.error(e),y("错误:无法解析 JSON 文件")}},a.readAsText(r)}}),(0,a.jsx)(n.Button,{variant:"outline",onClick:()=>A.current?.click(),children:"选择备份文件..."}),(0,a.jsx)("span",{className:"text-sm text-muted-foreground",children:N})]})]})]})]}),(0,a.jsxs)(d.Card,{children:[(0,a.jsxs)(d.CardHeader,{children:[(0,a.jsxs)(d.CardTitle,{className:"flex items-center gap-2",children:[(0,a.jsx)(u,{className:"h-5 w-5"})," GEDCOM 格式"]}),(0,a.jsx)(d.CardDescription,{children:"导入/导出标准 GEDCOM 格式,兼容其他家谱软件(如 Ancestry、MyHeritage)。"})]}),(0,a.jsx)(d.CardContent,{className:"space-y-4",children:(0,a.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,a.jsxs)(n.Button,{variant:"outline",className:"justify-start",onClick:()=>{let t,r,a,s=new Blob([((t=[]).push("0 HEAD"),t.push("1 SOUR Chinese Family Tree"),t.push("2 VERS 1.0"),t.push("2 NAME 华夏谱"),t.push("1 DEST ANY"),t.push("1 DATE "+new Date().toISOString().split("T")[0].replace(/-/g," ")),t.push("1 CHAR UTF-8"),t.push("1 GEDC"),t.push("2 VERS 5.5.1"),t.push("2 FORM LINEAGE-LINKED"),(r=Object.values(e.members)).forEach(e=>{if(t.push(`0 @I${e.id}@ INDI`),t.push(`1 NAME ${e.fullName}`),t.push(`2 GIVN ${e.givenName}`),t.push(`2 SURN ${e.surname}`),e.courtesyName&&t.push(`2 _AKA ${e.courtesyName}`),"MALE"===e.gender?t.push("1 SEX M"):"FEMALE"===e.gender&&t.push("1 SEX F"),e.birthDate&&(t.push("1 BIRT"),t.push(`2 DATE ${es(e.birthDate)}`),e.birthPlace&&t.push(`2 PLAC ${e.birthPlace}`)),e.deathDate&&(t.push("1 DEAT"),t.push(`2 DATE ${es(e.deathDate)}`),e.burialPlace&&t.push(`2 PLAC ${e.burialPlace}`)),e.ancestralHome&&(t.push("1 RESI"),t.push(`2 PLAC ${e.ancestralHome}`)),e.bio&&t.push("1 NOTE "+e.bio.replace(/\n/g,"\n1 CONT ")),e.fatherId||e.motherId){let r=`F${e.fatherId||e.motherId}_${e.id}`;t.push(`1 FAMC @${r}@`)}e.spouseIds.length>0&&e.spouseIds.forEach(r=>{let a=`F${e.id}_${r}`;t.push(`1 FAMS @${a}@`)})}),a=new Set,r.forEach(e=>{if(e.fatherId||e.motherId){let s=`F${e.fatherId||e.motherId}_${e.id}`;a.has(s)||(t.push(`0 @${s}@ FAM`),e.fatherId&&t.push(`1 HUSB @I${e.fatherId}@`),e.motherId&&t.push(`1 WIFE @I${e.motherId}@`),r.filter(t=>t.fatherId===e.fatherId&&t.motherId===e.motherId).forEach(e=>{t.push(`1 CHIL @I${e.id}@`)}),a.add(s))}e.spouseIds.length>0&&e.spouseIds.forEach(r=>{let s="MALE"===e.gender?`F${e.id}_${r}`:`F${r}_${e.id}`;a.has(s)||(t.push(`0 @${s}@ FAM`),"MALE"===e.gender?(t.push(`1 HUSB @I${e.id}@`),t.push(`1 WIFE @I${r}@`)):(t.push(`1 HUSB @I${r}@`),t.push(`1 WIFE @I${e.id}@`)),e.childrenIds.forEach(e=>{t.push(`1 CHIL @I${e}@`)}),a.add(s))})}),t.push("0 TRLR"),t.join("\n"))],{type:"text/plain;charset=utf-8"}),l=URL.createObjectURL(s),n=document.createElement("a");n.href=l,n.download=`family_tree_${new Date().toISOString().split("T")[0]}.ged`,document.body.appendChild(n),n.click(),document.body.removeChild(n)},children:[(0,a.jsx)(i.Download,{className:"mr-2 h-4 w-4"}),"导出 GEDCOM"]}),(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("input",{type:"file",ref:T,className:"hidden",accept:".ged,.gedcom",onChange:e=>{let r=e.target.files?.[0];if(!r)return;let a=new FileReader;a.onload=async e=>{try{var r;let a,s,l,n,d,i=(r=e.target?.result,s=((e,t={})=>{let r;(e=>{let t="0 HEAD",r=[];for(let e=0;e{if(a.byteLength[0,e]);if(!s(z.concat(e.flat()))&&!s(q.concat(e.map(e=>e.slice().reverse()).flat()))){let e=r.map(e=>[0,0,0,e]);if(!s(X.concat(e.flat()))&&!s(Y.concat(e.map(e=>e.slice().reverse()).flat())))throw new b("Probably not a Gedcom file")}}})(e);let a=null==t.forcedCharset?(e=>{let{sourceEncoding:t,sourceProvider:r,sourceProviderVersion:a,fileHasBOM:s}=((e,t=5e3,r=200)=>{let{output:a,bomCharset:s}=et(e.slice(0,t)),l=W(a,!1),n=0,d=[];for(let e of l){if(n>=r)break;d.push(e),n+=1}let i=V(d).children.filter(e=>"HEAD"===e.tag),c=i.flatMap(e=>e.children.filter(e=>"CHAR"===e.tag||"CHARACTER"===e.tag)),o=c.length>0?c[0].value:null,h=i.flatMap(e=>e.children.filter(e=>"SOUR"===e.tag)),u=h.length>0?h[0].value:null,f=h.flatMap(e=>e.children.filter(e=>"VERS"===e.tag));return{sourceEncoding:o,sourceProvider:u,sourceProviderVersion:f.length>0?f[0].value:null,fileHasBOM:null!==s}})(e);function l(){if("UTF-8"===t)return"UTF-8";if("ANSEL"===t)return"ANSEL";if("ASCII"===t)return"Cp1252";if("ANSI"===t)return"Cp1252";if("UNICODE"===t)return"UTF-16be";else if("WINDOWS"===t||"IBM WINDOWS"===t)return"Cp1252";else if("MACINTOSH"===t)return"Macintosh";else if("IBMPC"===t)return"Cp850";else if("MSDOS"===t)return"Cp850";else if("UNIX"===t)return"Cp1252";else if("UTF8"===t)return"UTF-8";else if("windows-1250"===t)return"Cp1252";else return"UTF-8"}if(s)return"UTF-8";if("GeneWeb"===r)if("ASCII"===t)return"Cp1252";else if("UTF-8"===t)return"UTF-8";else return l();if(null!=r&&r.startsWith("HEREDIS"))if("ANSI"===t)return"Cp1252";else return l();if("GENEATIQUE"===r)if("ANSEL"===t)return"ANSEL";else return l();if("Gramps"!==r)return l();if("UTF-8"===t)return"UTF-8";else return l()})(e):t.forcedCharset,s=t.progressCallback,l=e.byteLength,n=s?e=>s(0,e/l):void 0;if("UTF-8"===a||"UTF-16be"===a||"UTF-16le"===a)r=((e,t)=>{let{output:r}=et(e,t);return r})(e,n);else if("Cp1252"===a)r=((e,t)=>{t&&t(0);let r=new Uint8Array(e),a="",s=0;for(;s?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~€�‚ƒ„…†‡ˆ‰Š‹Œ�Ž��‘’“”•–—˜™š›œ�žŸ ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ".charAt(r[s]),t&&s%2e5==0&&t(s);return t&&t(s),a})(e,n);else if("ANSEL"===a)r=((e,t,r)=>{t&&t(0);let a=(e,t,r)=>{let a=new Map;for(let s=0;s=224&&e<=255||e>=215&&e<=217)){let t=256*e+c,a=l.get(t);if(void 0!==a)c=n[i],i++,d.push(String.fromCharCode(a));else if(r)throw new j(`Illegal ANSEL character code: ${t}`,t);else c=n[i],i++,d.push("�")}else{let t=s.get(e),r=String.fromCharCode(void 0!==t?t:65533);d.push(r)}t&&i%2e5==0&&t(i)}return t&&t(i),d.join("")})(e,n,!!t.doStrictDecoding);else if("Macintosh"===a)r=((e,t)=>{t&&t(0);let r=new Uint8Array(e),a="",s=0;for(;s?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®©™´¨≠ÆØ∞±≤≥¥µ∂∑∏π∫ªºΩæø¿¡¬√ƒ≈∆«»… ÀÃÕŒœ–—“”‘’÷◊ÿŸ⁄€‹›fifl‡·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙıˆ˜¯˘˙˚¸˝˛ˇ".charAt(r[s]),t&&s%2e5==0&&t(0);return t&&t(s),a})(e,n);else if("Cp850"===a)r=((e,t)=>{t&&t(0);let r=new Uint8Array(e),a="",s=0;for(;ss(1,e/d):null);return(e=>{let t=e.children,r=t[0];if("HEAD"!==r.tag)throw new S(`First node is not a header (got ${r.tag})`);let a=t[t.length-1];if("TRLR"!==a.tag)throw new S(`Last node is not a trailer (got ${a.tag})`)})(i),t.noIndex||((e,t=!1,r=!1,a=null)=>{a&&a();let s=0,l=[[e,0]];for(;l.length>0;){let[e,t]=l[l.length-1];if(t0&&l[l.length-1][1]++,er(e,!r),0===l.length&&ea(e)}s++,a&&s%5e4==0&&a()}t||((e,t=null)=>{let r=(e,t,r)=>{let a=e[t];return null!=a?a:r},a=e._index,s=r(a.byTagPointer,"FAM",{}),l={},n={};Object.values(s).forEach((a,s)=>{let d=e.children[a],i=d._index;for(let e of["HUSB","WIFE"])for(let t of r(i.byTag,e,[])){let e=d.children[t].value;null!==e&&(void 0!==l[e]?l[e].push(a):l[e]=[a])}for(let e of r(i.byTag,"CHIL",[])){let t=d.children[e].value;null!==t&&(void 0!==n[t]?n[t].push(a):n[t]=[a])}t&&s%5e3==0&&t()}),a.asSpouse=l,a.asChild=n})(e,a),a&&a()})(i,!!t.noBackwardsReferencesIndex,!!t.doHideIndex,s?()=>s(2,null):null),t.doFreeze&&(s&&s(3,0),(e=>{let t=[e];for(;t.length>0;){let e=[];t.forEach(t=>{null==t||"object"!=typeof t||Object.isFrozen(t)||(Object.freeze(t),Object.getOwnPropertyNames(t).forEach(r=>e.push(t[r])))}),t=e}})(i),s&&s(3,1)),i})(r),l={},(n=Array.isArray(s)?s:s.tree||[]).forEach(e=>{if("INDI"===e.tag){let t,r,a,s,n,d,i,c=e.pointer.replace("@I","").replace("@",""),o="",h="",u="",f="OTHER";e.tree.forEach(e=>{"NAME"===e.tag&&(o=e.data.replace(/\//g,"").trim(),e.tree?.forEach(e=>{"GIVN"===e.tag&&(h=e.data),"SURN"===e.tag&&(u=e.data),"_AKA"===e.tag&&(t=e.data)})),"SEX"===e.tag&&(f="M"===e.data?"MALE":"F"===e.data?"FEMALE":"OTHER"),"BIRT"===e.tag&&e.tree?.forEach(e=>{"DATE"===e.tag&&(r=el(e.data)),"PLAC"===e.tag&&(s=e.data)}),"DEAT"===e.tag&&e.tree?.forEach(e=>{"DATE"===e.tag&&(a=el(e.data)),"PLAC"===e.tag&&(n=e.data)}),"RESI"===e.tag&&e.tree?.forEach(e=>{"PLAC"===e.tag&&(d=e.data)}),"NOTE"===e.tag&&(i=e.data)}),l[c]={id:c,surname:u||"未知",givenName:h||o,fullName:o||`${u}${h}`,gender:f,generation:1,courtesyName:t,birthDate:r,deathDate:a,birthPlace:s,burialPlace:n,ancestralHome:d,bio:i,spouseIds:[],childrenIds:[],createdAt:new Date().toISOString(),updatedAt:new Date().toISOString()}}}),n.forEach(e=>{if("FAM"===e.tag){let t,r,a=[];e.tree.forEach(e=>{"HUSB"===e.tag&&(t=e.data.replace("@I","").replace("@","")),"WIFE"===e.tag&&(r=e.data.replace("@I","").replace("@","")),"CHIL"===e.tag&&a.push(e.data.replace("@I","").replace("@",""))}),t&&r&&(l[t]&&!l[t].spouseIds.includes(r)&&l[t].spouseIds.push(r),l[r]&&!l[r].spouseIds.includes(t)&&l[r].spouseIds.push(t)),a.forEach(e=>{l[e]&&(t&&(l[e].fatherId=t,l[t]&&!l[t].childrenIds.includes(e)&&l[t].childrenIds.push(e)),r&&(l[e].motherId=r,l[r]&&!l[r].childrenIds.includes(e)&&l[r].childrenIds.push(e)))})}}),d=(e,t=new Set)=>{if(t.has(e))return 1;t.add(e);let r=l[e];if(!r||!r.fatherId&&!r.motherId)return 1;let a=r.fatherId?d(r.fatherId,t):0;return Math.max(a,r.motherId?d(r.motherId,t):0)+1},Object.keys(l).forEach(e=>{l[e].generation=d(e)}),a=Object.keys(l).find(e=>1===l[e].generation),{members:l,rootId:a});await t(i),E("导入成功!"),T.current&&(T.current.value="")}catch(e){console.error(e),E("错误:无法解析文件")}},a.readAsText(r)}}),(0,a.jsxs)(n.Button,{variant:"outline",className:"justify-start",onClick:()=>T.current?.click(),children:[(0,a.jsx)(c.Upload,{className:"mr-2 h-4 w-4"}),"导入 GEDCOM"]}),w&&(0,a.jsx)("span",{className:"text-sm text-muted-foreground",children:w})]})]})})]})]}),(0,a.jsx)(eE,{children:(0,a.jsx)(ey,{})})]})]})]})}e.s(["default",()=>eR],47430)}]);