import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Ct as t,N as n,Or as r,Pr as i,Tn as a,di as o,fn as s,kt as c,o as l,ti as u}from"./lucide-icons-6JcOMNkr.js";import{t as d}from"./jsx-runtime-NZYk81nU.js";import{u as f}from"./esm-0y5H0J9W.js";import{t as p}from"./useCurrentUser-CgUH2vq7.js";import{t as m}from"./utils-CFLjoQCu.js";import{n as h}from"./chunk-62JRHF6Z-ByakpFgU.js";import{t as g}from"./useTranslation-DClBQ1v-.js";import{t as _}from"./button-DwJ7jtrK.js";import{t as v}from"./input-Dkzlj0L8.js";import{i as y,l as b,r as x,t as S}from"./dropdown-menu-BbdDfqao.js";import{n as C,r as w,t as T}from"./avatar-8iFLkhAN.js";import{t as E}from"./skeleton-C53mCyi9.js";import{t as ee}from"./genUserName-DLQrbfFW.js";import{$ as te,B as D,H as ne,W as re,et as ie,rt as ae,tt as oe}from"./EmbeddedNote-DrUd4Foc.js";import{n as se,r as ce,t as O}from"./collapsible-DeI_R02F.js";import{t as k}from"./sanitizeUrl-Bd1A9ELz.js";var A=e(o(),1),j=d();function le({items:e,maxVisible:t=12,thumbnailSize:n=48,showNames:r=!0,showEditButton:i,editPath:a=`/badges`,isLoading:o,gridCols:s=`grid-cols-4 sm:grid-cols-6`,className:l}){if(o)return(0,j.jsx)(`div`,{className:m(`grid gap-3`,s,l),children:Array.from({length:4}).map((e,t)=>(0,j.jsxs)(`div`,{className:`flex flex-col items-center gap-1.5`,children:[(0,j.jsx)(E,{className:`rounded-lg`,style:{width:n,height:n}}),r&&(0,j.jsx)(E,{className:`h-3 w-12`})]},t))});if(e.length===0)return null;let d=e.slice(0,t),p=Math.max(0,e.length-t);return(0,j.jsxs)(`div`,{className:m(`space-y-2`,l),children:[(0,j.jsxs)(`div`,{className:m(`grid gap-3`,s),children:[d.map(e=>{let t=`/${f.naddrEncode({kind:30009,pubkey:e.pubkey,identifier:e.identifier})}`;return(0,j.jsxs)(h,{to:t,className:`flex flex-col items-center gap-1.5 group`,title:e.badge?.description||e.badge?.name||e.identifier,onClick:e=>e.stopPropagation(),children:[e.badge?(0,j.jsx)(D,{badge:e.badge,size:n}):(0,j.jsx)(`div`,{className:`rounded-lg border border-border bg-background flex items-center justify-center`,style:{width:n,height:n},children:(0,j.jsx)(u,{className:`size-6 text-muted-foreground`})}),r&&(0,j.jsx)(`span`,{className:`text-[10px] text-muted-foreground text-center leading-tight line-clamp-2 max-w-[4.5rem] group-hover:text-foreground transition-colors`,children:e.badge?.name||e.identifier})]},e.aTag)}),p>0&&(0,j.jsx)(`div`,{className:`flex flex-col items-center justify-center gap-1.5`,children:(0,j.jsxs)(`div`,{className:`rounded-lg bg-muted flex items-center justify-center text-muted-foreground text-xs font-medium`,style:{width:n,height:n},children:[`+`,p]})})]}),i&&a&&(0,j.jsx)(`div`,{className:`flex justify-end`,children:(0,j.jsx)(_,{variant:`ghost`,size:`sm`,className:`h-7 text-xs gap-1 text-muted-foreground`,asChild:!0,children:(0,j.jsxs)(h,{to:a,children:[(0,j.jsx)(c,{className:`size-3`}),`Edit Badges`]})})})]})}function M(e){e.style.height=`auto`,e.style.height=`${e.scrollHeight}px`}var N=[`rounded-lg px-2`,`border-2 border-transparent`,`bg-muted/40`,`hover:bg-muted/60 hover:border-border`,`focus:bg-transparent focus:border-primary`,`transition-colors duration-150`,`placeholder:text-muted-foreground/40`,`outline-none`].join(` `);function P({value:e,placeholder:t,onChange:n,maxLength:r,className:i}){return(0,j.jsx)(`input`,{type:`text`,value:e,placeholder:t,maxLength:r,onChange:e=>n(e.target.value),className:m(N,`w-full min-w-0 py-0.5`,i)})}function ue({value:e,placeholder:t,onChange:n,className:r}){return(0,j.jsx)(`textarea`,{value:e,placeholder:t,onChange:e=>{n(e.target.value),M(e.target)},onFocus:e=>{M(e.target)},rows:1,className:m(N,`w-full min-w-0 py-1 resize-none overflow-hidden text-base md:text-sm text-muted-foreground leading-relaxed`,r)})}function F({trigger:e,hasImage:t,onUpload:n,onPasteUrl:r,onRemove:i}){let{t:o}=g();return(0,j.jsxs)(S,{children:[(0,j.jsx)(b,{asChild:!0,children:e}),(0,j.jsxs)(x,{align:`start`,sideOffset:6,children:[(0,j.jsxs)(y,{onClick:n,children:[(0,j.jsx)(a,{className:`size-4 mr-2`}),o(`profile.imageMenu.upload`)]}),r&&(0,j.jsxs)(y,{onClick:r,children:[(0,j.jsx)(s,{className:`size-4 mr-2`}),o(`profile.imageMenu.pasteUrl`)]}),t&&i&&(0,j.jsxs)(y,{onClick:i,className:`text-destructive focus:text-destructive`,children:[(0,j.jsx)(l,{className:`size-4 mr-2`}),o(`profile.imageMenu.remove`)]})]})]})}function I({className:e,pubkey:a,metadata:o,onChange:s,onPickImage:l,onPasteUrl:u,onRemoveAvatar:d,onRemoveBanner:f,showBanner:h=!0,showAvatar:y=!0,namePlaceholder:b,nameMaxLength:x,showNip05:S=!0,showBadges:E=!0,bioField:D=`about`,aboutPlaceholder:M=`Write a short bio…`,extraFields:I,onExtraFieldsChange:L}){let{t:R}=g(),z=!!s,[B,V]=(0,A.useState)(!1),[H,de]=(0,A.useState)(!1),{user:U}=p(),fe=!!a&&!!U&&a===U.pubkey,{refs:W,isLoading:G}=re(a),{badgeMap:pe,isLoading:K}=ne(W),q=o.name||o.display_name||ee(a),J=q[0]?.toUpperCase()??`?`,Y=e=>t=>s?.({[e]:t}),X=k(o.banner),Z=o.nip05,Q=Z?oe(Z):void 0,me=()=>L?.([...I??[],{label:``,value:``}]),he=e=>L?.((I??[]).filter((t,n)=>n!==e)),$=(e,t,n)=>L?.((I??[]).map((r,i)=>i===e?{...r,[t]:n}:r));return(0,j.jsxs)(`div`,{className:m(`bg-card border rounded-xl overflow-hidden`,e),children:[h&&(z&&(u||f)?(0,j.jsx)(F,{hasImage:!!o.banner,onUpload:()=>l?.(`banner`),onPasteUrl:u?()=>u(`banner`):void 0,onRemove:f,trigger:(0,j.jsxs)(`button`,{type:`button`,className:`relative block w-full h-36 bg-secondary cursor-pointer group outline-none`,style:X?{backgroundImage:`url("${X}")`,backgroundSize:`cover`,backgroundPosition:`center`}:void 0,children:[!o.banner&&(0,j.jsx)(`div`,{className:`absolute inset-0 bg-gradient-to-br from-accent/10 via-transparent to-primary/5`}),!o.banner&&(0,j.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,j.jsx)(t,{className:`size-6 text-muted-foreground`,strokeWidth:4})}),(0,j.jsx)(`div`,{className:`absolute inset-0 bg-black/0 group-hover:bg-black/30 transition-colors flex items-center justify-center`,children:(0,j.jsxs)(`span`,{className:`opacity-0 group-hover:opacity-100 transition-opacity flex items-center gap-1.5 text-white text-xs font-medium bg-black/50 rounded-full px-3 py-1.5 backdrop-blur-sm`,children:[(0,j.jsx)(c,{className:`size-3.5`}),` `,o.banner?`Change banner`:`Add banner`]})}),o.banner&&(0,j.jsx)(`div`,{className:`absolute bottom-2 right-2 size-7 rounded-full bg-background border border-border shadow-sm flex items-center justify-center transition-opacity`,children:(0,j.jsx)(c,{className:`size-3.5 text-muted-foreground`})})]})}):(0,j.jsxs)(`div`,{className:m(`relative h-36 bg-secondary`,z&&`cursor-pointer group`),style:X?{backgroundImage:`url("${X}")`,backgroundSize:`cover`,backgroundPosition:`center`}:void 0,onClick:()=>z&&l?.(`banner`),children:[!o.banner&&(0,j.jsx)(`div`,{className:`absolute inset-0 bg-gradient-to-br from-accent/10 via-transparent to-primary/5`}),z&&!o.banner&&(0,j.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,j.jsx)(t,{className:`size-6 text-muted-foreground`,strokeWidth:4})}),z&&(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(`div`,{className:`absolute inset-0 bg-black/0 group-hover:bg-black/30 transition-colors flex items-center justify-center`,children:(0,j.jsxs)(`span`,{className:`opacity-0 group-hover:opacity-100 transition-opacity flex items-center gap-1.5 text-white text-xs font-medium bg-black/50 rounded-full px-3 py-1.5 backdrop-blur-sm`,children:[(0,j.jsx)(c,{className:`size-3.5`}),` `,o.banner?`Change banner`:`Add banner`]})}),o.banner&&(0,j.jsx)(`div`,{className:`absolute bottom-2 right-2 size-7 rounded-full bg-background border border-border shadow-sm flex items-center justify-center transition-opacity`,children:(0,j.jsx)(c,{className:`size-3.5 text-muted-foreground`})})]})]})),(0,j.jsxs)(`div`,{className:m(`px-4 pb-4`,!y&&(h?`pt-3`:`pt-4`)),children:[y&&(0,j.jsx)(`div`,{className:m(`flex justify-between items-start mb-3`,h?`-mt-12`:`mt-3`),children:z?(0,j.jsx)(F,{hasImage:!!o.picture,onUpload:()=>l?.(`picture`),onPasteUrl:u?()=>u(`picture`):void 0,onRemove:d,trigger:(0,j.jsxs)(`button`,{type:`button`,className:`relative shrink-0 cursor-pointer group outline-none`,children:[(0,j.jsxs)(T,{className:`shadow-sm size-24 border-4 border-background`,children:[(0,j.jsx)(w,{src:o.picture,alt:q,className:`object-cover`}),(0,j.jsx)(C,{className:`bg-primary/20 text-primary text-2xl font-bold`,children:o.picture?J:(0,j.jsx)(t,{className:`size-8 text-muted-foreground`,strokeWidth:4})})]}),(0,j.jsx)(`div`,{className:`absolute inset-0 bg-black/0 group-hover:bg-black/45 transition-colors flex items-center justify-center rounded-full`,children:(0,j.jsx)(c,{className:`size-6 text-white opacity-0 group-hover:opacity-100 transition-opacity drop-shadow`})}),o.picture&&(0,j.jsx)(`div`,{className:`absolute bottom-0 right-0 size-7 rounded-full bg-background border border-border shadow-sm flex items-center justify-center transition-opacity`,children:(0,j.jsx)(c,{className:`size-3.5 text-muted-foreground`})})]})}):(0,j.jsx)(`div`,{className:`relative shrink-0`,children:(0,j.jsxs)(T,{className:`shadow-sm size-24 border-4 border-background`,children:[(0,j.jsx)(w,{src:o.picture,alt:q,className:`object-cover`}),(0,j.jsx)(C,{className:`bg-primary/20 text-primary text-2xl font-bold`,children:J})]})})}),z?(0,j.jsx)(P,{value:o.name??``,placeholder:b??R(`profile.namePlaceholder`),maxLength:x,onChange:Y(`name`),className:`text-xl font-bold`}):(0,j.jsx)(`h2`,{className:`text-xl font-bold truncate`,children:q}),S&&(z||Z)&&(0,j.jsxs)(`div`,{className:`flex items-center gap-1 mt-2 min-w-0 text-sm text-muted-foreground ml-2`,children:[(0,j.jsx)(r,{className:`size-3.5 text-primary shrink-0`}),z&&B?(0,j.jsx)(`input`,{type:`text`,value:Z??``,placeholder:`you@domain.com`,autoFocus:!0,onChange:e=>Y(`nip05`)(e.target.value),onBlur:()=>V(!1),size:Math.max((Z?.length??0)+1,4),className:m(N,`py-0.5 h-6 text-base md:text-sm text-muted-foreground border-primary bg-transparent`)}):(0,j.jsxs)(`span`,{className:m(`inline-flex items-center gap-1 min-w-0`,z&&m(N,`py-0.5 h-6 cursor-text`)),onClick:()=>z&&V(!0),children:[(0,j.jsx)(`span`,{className:`shrink min-w-0 overflow-hidden text-ellipsis whitespace-nowrap`,children:Z?ie(Z):z?`you@domain.com`:``}),Q&&(0,j.jsx)(te,{url:`https://${Q}`,size:14,className:`shrink-0`})]})]}),D!==`none`&&(0,j.jsx)(`div`,{className:`mt-2`,children:D===`website`?z?(0,j.jsx)(P,{value:o.website??``,placeholder:R(`profile.websitePlaceholder`),onChange:Y(`website`),className:`text-sm`}):o.website?(0,j.jsx)(`p`,{className:`text-sm text-muted-foreground leading-relaxed truncate`,children:o.website}):null:z?(0,j.jsx)(ue,{value:o.about??``,placeholder:M,onChange:Y(`about`)}):o.about?(0,j.jsx)(`p`,{className:`text-sm text-muted-foreground leading-relaxed whitespace-pre-wrap`,children:(0,j.jsx)(ae,{children:o.about})}):null}),I!==void 0&&(0,j.jsxs)(O,{open:H,onOpenChange:de,className:`mt-3`,children:[(0,j.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,j.jsx)(ce,{asChild:!0,children:(0,j.jsxs)(_,{type:`button`,variant:`ghost`,className:`w-full justify-between px-0 h-auto hover:bg-transparent text-sm font-medium text-muted-foreground`,children:[`Profile Fields`,(0,j.jsx)(i,{className:`size-4 transition-transform duration-200 [[data-state=open]_&]:rotate-180`,strokeWidth:4})]})})}),(0,j.jsxs)(se,{className:`space-y-2 pt-2`,children:[(0,j.jsxs)(`div`,{className:`grid grid-cols-[1fr,2fr] gap-2 items-center`,children:[(0,j.jsx)(`span`,{className:`text-sm text-muted-foreground px-1`,children:`Website`}),(0,j.jsx)(v,{placeholder:`https://yourwebsite.com`,value:o.website??``,onChange:e=>Y(`website`)(e.target.value),className:`h-8 text-base md:text-sm`})]}),I.map((e,t)=>(0,j.jsxs)(`div`,{className:`grid grid-cols-[1fr,2fr,auto] gap-2 items-center`,children:[(0,j.jsx)(v,{placeholder:`Label`,value:e.label,onChange:e=>$(t,`label`,e.target.value),className:`h-8 text-base md:text-sm`}),(0,j.jsx)(v,{placeholder:`Value or URL`,value:e.value,onChange:e=>$(t,`value`,e.target.value),className:`h-8 text-base md:text-sm`}),(0,j.jsx)(_,{type:`button`,variant:`ghost`,size:`icon`,onClick:()=>he(t),className:`h-8 w-8 text-destructive hover:text-destructive`,children:(0,j.jsx)(n,{className:`size-3.5`})})]},t)),(0,j.jsxs)(_,{type:`button`,variant:`outline`,size:`sm`,onClick:me,className:`w-full h-8 text-xs`,children:[(0,j.jsx)(t,{className:`size-3 mr-1`,strokeWidth:4}),` Add Field`]})]})]})]}),E&&(W.length>0||G)&&(0,j.jsx)(`div`,{className:`px-4 pb-3`,children:(0,j.jsx)(le,{items:W.map(e=>({aTag:e.aTag,pubkey:e.pubkey,identifier:e.identifier,badge:pe.get(e.aTag)})),maxVisible:8,thumbnailSize:44,showEditButton:fe,isLoading:G||K,gridCols:`grid-cols-4 sm:grid-cols-5`})})]})}export{M as n,I as t};