(function(L,s,k,n,o,Q,ne){"use strict";const Me="[ServerDrawer]";function Qe(e){const t=s.findByProps("useIsMobileQuestDockRendered");if(!t?.useIsMobileQuestDockRendered)return console.log(Me,"WARN: useIsMobileQuestDockRendered not found"),!1;const r=t.useIsMobileQuestDockRendered;return t.useIsMobileQuestDockRendered=function(...i){return r.apply(this,i),!0},e.push(function(){t.useIsMobileQuestDockRendered=r}),!0}const Te="[ServerDrawer]";function Ve(e){const t=s.findByProps("useIsMobileQuestDockRenderedBase");if(!t?.useIsMobileQuestDockRenderedBase)return console.log(Te,"WARN: useIsMobileQuestDockRenderedBase not found"),!1;const r=t.useIsMobileQuestDockRenderedBase;return t.useIsMobileQuestDockRenderedBase=function(...i){return r.apply(this,i),!0},e.push(function(){t.useIsMobileQuestDockRenderedBase=r}),!0}const Fe="[ServerDrawer]";function Ge(e){const t=s.findByProps("useMobileQuestDock");if(!t.useMobileQuestDock)return console.log(Fe,"WARN: useMobileQuestDock not found"),!1;const r=t.useMobileQuestDock;return t.useMobileQuestDock=function(...i){return r.apply(this,i)||{id:"server-drawer",config:{quest_content_type:0,assets:{questBarHeroVideo:null,questBarHero:null},features:[]},userStatus:{enrolledAt:"2099-01-01",claimedAt:null},benefits:{rewards:[]},guildId:"0",tasks:[]}},e.push(function(){t.useMobileQuestDock=r}),!0}const He="[ServerDrawer]";function We(e){const t=s.findByProps("getQuestAsset");if(!t?.getQuestAsset)return console.log(He,"WARN: getQuestAsset not found"),!1;const r=t.getQuestAsset;return t.getQuestAsset=function(...i){try{return r.apply(this,i)}catch{return{url:null,isAnimated:!1}}},e.push(function(){t.getQuestAsset=r}),!0}const Le=s.findByStoreName("GuildStore"),Oe=s.findByProps("colors","unsafe_rawColors")?.colors;function oe({id:e,size:t=48}){const r=Le?.getGuild(e);if(!r)return null;const i=t>=40?16:8;return r.icon?n.createElement(o.Image,{source:{uri:`https://cdn.discordapp.com/icons/${r.id}/${r.icon}.png?size=${t*2}`},style:{width:t,height:t,borderRadius:i}}):n.createElement(o.View,{style:[re.fallback,{width:t,height:t,borderRadius:i,backgroundColor:Oe?.BG_ACCENT??"#5865f2"}]},n.createElement(o.Text,{style:[re.letter,{fontSize:Math.max(10,t*.4)}]},r.name?.split(" ").map(function(l){return l[0]}).join("").slice(0,2).toUpperCase()||"?"))}const re=o.StyleSheet.create({fallback:{alignItems:"center",justifyContent:"center"},letter:{color:"#fff",fontWeight:"700"}}),se=s.findByProps("TextStyleSheet")?.TextStyleSheet,_e=s.findByStoreName("ThemeStore"),ie=s.findByProps("colors","unsafe_rawColors"),je=ie?.internal??ie?.meta,le=s.findByProps("triggerHapticFeedback","HapticFeedbackTypes");function T(e){const t=_e?.theme;return e&&je?.resolveSemanticColor(t,e)||"#000000"}const w=12,O=12,ue=42,_=220,ae=4,P=16,V=20,de={tension:200,friction:20};function ze({visible:e,items:t,title:r,anchorX:i,anchorY:l,onClose:d}){const{width:c,height:S}=o.Dimensions.get("window"),E=(r?O+20+ae:0)+t.length*ue;let g=i,f=l+48+10;g+_>c-w&&(g=c-_-w),gS-w&&(f=l-E-10),f0?n.createElement(o.View,{style:I.outline},n.createElement(o.View,{style:I.badge},n.createElement(o.Text,{style:I.text},t>99?"99+":String(t)))):r?n.createElement(o.View,{style:I.dotOutline},n.createElement(o.View,{style:I.dot})):null}function pe({node:e,onPick:t}){const r=n.useRef(null),i=n.useRef(new o.Animated.Value(1)).current,l=function(){return o.Animated.spring(i,{toValue:.85,useNativeDriver:!0}).start()},d=function(){return o.Animated.spring(i,{toValue:1,useNativeDriver:!0}).start()},[c,S]=n.useState({visible:!1,items:[],title:"",x:0,y:0}),E=n.useCallback(function(){const C=e.id,u=Ue?.getGuild?.(C),h=s.find(function(p){return p?.default?.name==="getGuildsBarGuildMenuItems"})?.default??s.find(function(p){return typeof p?.default=="function"&&p.default.length<=2&&/guild/i.test(p.default.name??"")})?.default;if(!u||!h)return;const v=qe?.getGuildsTree?.()?.version,R=h(C,v);if(!R?.length)return;const B=r.current;B?.measure&&B.measure(function(p,N,$,A,M,m){S({visible:!0,items:R.map(function(y){return{label:y.label??y.title??"Unknown",action:y.action,danger:y.variant==="destructive",iconSource:y.iconSource,IconComponent:y.IconComponent}}),title:u.name,x:M,y:m})})},[e.id]),g=n.useCallback(function(){fe?.triggerHapticFeedback?.(fe.HapticFeedbackTypes.IMPACT_MEDIUM),E()},[E]),f=e.id;return n.createElement(n.Fragment,null,n.createElement(o.Pressable,{onPressIn:l,onPressOut:d,onPress:function(){return t(f)},onLongPress:g,delayLongPress:500},n.createElement(o.View,{ref:r,style:ge.outer,collapsable:!1},n.createElement(o.Animated.View,{style:[ge.icon,{transform:[{scale:i}]}]},n.createElement(oe,{id:f})),n.createElement(Ke,{guildId:f}))),n.createElement(ze,{visible:c.visible,items:c.items,title:c.title,anchorX:c.x,anchorY:c.y,onClose:function(){return S(function(C){return{...C,visible:!1}})}}))}const ge=o.StyleSheet.create({outer:{width:F,height:F},icon:{width:F,height:F,borderRadius:16,overflow:"hidden"}}),I=o.StyleSheet.create({outline:{position:"absolute",bottom:-3,right:-3,minWidth:23,minHeight:23,borderRadius:12,backgroundColor:"#1a1a2e",alignItems:"center",justifyContent:"center"},badge:{minWidth:19,height:19,borderRadius:9,backgroundColor:"#ed4245",alignItems:"center",justifyContent:"center",paddingHorizontal:5},text:{color:"#fff",fontSize:10,fontWeight:"700",lineHeight:19},dotOutline:{position:"absolute",bottom:-2,right:-2,width:14,height:14,borderRadius:7,backgroundColor:"#1a1a2e",alignItems:"center",justifyContent:"center"},dot:{width:10,height:10,borderRadius:5,backgroundColor:"#ed4245"}}),Xe=s.findByProps("useStateFromStores");s.findByProps("colors","unsafe_rawColors")?.colors;const he=s.findByStoreName("ExpandedGuildFolderStore");function Ye(e){return Xe?.useStateFromStores?.([he],function(){const t=he?.getExpandedFolders?.();return t instanceof Set?t.has(e):!1},[e])??!1}const Je=s.findByProps("toggleGuildFolderExpand"),Ze=s.findByProps("useStateFromStores"),me=s.findByStoreName("GuildReadStateStore"),D=48,z=16,ve=[{top:6,left:6},{top:6,right:6},{bottom:6,left:6},{bottom:6,right:6}],Ne=ne.getAssetIDByName("FolderIcon");function ye(e){return e==null?"#5865f2":`#${e.toString(16).padStart(6,"0")}`}function $e({node:e}){const t=Ze?.useStateFromStores?.([me],function(){let r=0;for(const i of e.children)r+=me?.getMentionCount?.(i.id)??0;return r},[e.children])??0;return t>0?n.createElement(o.View,{style:q.outline},n.createElement(o.View,{style:q.badge},n.createElement(o.Text,{style:q.text},t>99?"99+":String(t)))):null}function et({node:e}){const t=ye(e.color);return n.createElement(o.View,{style:U.outer},n.createElement(o.View,{style:[U.icon,{backgroundColor:t}]},e.children.slice(0,4).map(function(r,i){return n.createElement(o.View,{key:r.id,style:[U.cell,ve[i]]},n.createElement(oe,{id:r.id,size:z}))})),n.createElement($e,{node:e}))}const U=o.StyleSheet.create({outer:{width:D,height:D},icon:{width:D,height:D,borderRadius:16,overflow:"hidden"},cell:{position:"absolute",width:z,height:z,borderRadius:8,overflow:"hidden"}});function tt({children:e}){const t=n.useRef(new o.Animated.Value(0)).current;return n.useEffect(function(){o.Animated.timing(t,{toValue:1,duration:180,useNativeDriver:!0}).start()},[]),n.createElement(o.Animated.View,{style:{opacity:t}},e)}function nt({node:e,onPick:t}){const r=Ye(e.id),i=function(){Je?.toggleGuildFolderExpand?.(e.id)};return r?n.createElement(n.Fragment,null,n.createElement(o.Pressable,{onPress:i},n.createElement(o.View,{style:[be.openIcon,{backgroundColor:ye(e.color)}]},n.createElement(o.Image,{source:Ne,style:be.folderImg,tintColor:"#fff"}))),e.children.map(function(l){return n.createElement(tt,{key:l.id},n.createElement(pe,{node:l,onPick:t}))})):n.createElement(o.Pressable,{onPress:i},n.createElement(et,{node:e}))}const be=o.StyleSheet.create({openIcon:{width:D,height:D,borderRadius:16,alignItems:"center",justifyContent:"center"},folderImg:{width:24,height:24}}),q=o.StyleSheet.create({outline:{position:"absolute",bottom:-3,right:-3,minWidth:23,minHeight:23,borderRadius:12,backgroundColor:"#1a1a2e",alignItems:"center",justifyContent:"center"},badge:{minWidth:19,height:19,borderRadius:9,backgroundColor:"#ed4245",alignItems:"center",justifyContent:"center",paddingHorizontal:5},text:{color:"#fff",fontSize:10,fontWeight:"700",lineHeight:19}}),ot=s.findByStoreName("SortedGuildStore"),rt=s.findByProps("getRootNavigationRef"),Se=s.findByProps("triggerHapticFeedback","HapticFeedbackTypes"),Ee=s.findByProps("transitionToGuild"),st=s.find(function(e){return e?.QuestDockExternalCoordinationContext}),Ce=st?.QuestDockExternalCoordinationContext,ke=s.find(function(e){return e?.QuestDockMode?.COLLAPSED!=null})?.QuestDockMode,we=48,H=6,it=12;function Re({gestureContext:e}){const t=n.useCallback(function(u){Se?.triggerHapticFeedback(Se.HapticFeedbackTypes.SOFT),Ee?.transitionToGuild?Ee.transitionToGuild(u,null):rt?.getRootNavigationRef()?.navigate("guilds",{guildId:u})},[]),r=n.useMemo(function(){return(ot?.getGuildsTree()?.root?.children||[]).filter(function(u){return u.type!=="root"})},[]),i=e?n.useContext(e):null,l=i?.minExpandedContentHeight,d=n.useCallback(function(u){if(!l)return;const h=u.nativeEvent.layout.height;l.get()!==h&&l.set(h)},[l]),c=(Ce?n.useContext(Ce):null)?.setRestingQuestDockMode,S=i?.questDockWrapperSpecs;n.useEffect(function(){if(!c||!ke||!S)return;const u=o.BackHandler.addEventListener("hardwareBackPress",function(){return(S.get()?.height??56)>80?(c(ke.COLLAPSED),!0):!1});return function(){return u.remove()}},[c,S]);const{width:E}=o.Dimensions.get("window"),g=Math.max(3,Math.floor((E-it*2+H)/(we+H))),f=g*we+(g-1)*H,C=Math.max(0,(E-f)/2);return n.createElement(o.View,{style:Be.alignTop},n.createElement(o.View,{style:[Be.grid,{paddingHorizontal:C,gap:H}],onLayout:d},r.map(function(u){return u.type==="folder"?n.createElement(nt,{key:u.id,node:u,onPick:t}):n.createElement(pe,{key:u.id,node:u,onPick:t})})))}const Be=o.StyleSheet.create({alignTop:{flex:1,justifyContent:"flex-start",alignItems:"flex-start"},grid:{flexDirection:"row",flexWrap:"wrap",paddingTop:4,paddingBottom:16}}),K=new Map;let b=null,W=!1;function De(e,t,r){K.set(e,{replacement:t,extraProps:r})}function lt(e){if(W)return;if(b=k.React.createElement,!b){console.warn("[ServerDrawer] React.createElement is null, skipping patch");return}const t=function(r,i,...l){if(!b)return k.React.createElement(r,i,...l);const d=K.get(r);if(d){const c=d.extraProps?{...i,...d.extraProps}:i;return b.call(k.React,d.replacement,c,...l)}return b.call(k.React,r,i,...l)};Object.assign(t,b),k.React.createElement=t,W=!0,e.push(function(){W&&b&&(k.React.createElement=b,W=!1),K.clear()})}const X="[ServerDrawer]",Pe=s.find(function(e){return e?.QuestDockGestureContext})?.QuestDockGestureContext;function ut(e){const t=s.find(function(i){return i?.type?.displayName==="QuestDockContentExpanded"||i?.type?.name==="QuestDockContentExpanded"});if(!t?.type)return console.log(X,"WARN: QuestDockContentExpanded not found"),!1;const r=t.type;return De(r,Re,{gestureContext:Pe}),t.type=function(){return k.React.createElement(Re,{gestureContext:Pe})},e.push(function(){t.type=r}),console.log(X,"PATCH: QuestDockContentExpanded replaced"),!0}function x(e,t){const r=s.find(function(d){return d?.type?.displayName===e||d?.type?.name===e});if(!r?.type)return console.log(X,`WARN: ${e} not found`),!1;const i=r.type,l=i;return r.type=function(){return null},l&&(Object.defineProperties(r.type,Object.getOwnPropertyDescriptors(l)),r.type.displayName=e),t.push(function(){r.type=i}),!0}const at="[ServerDrawer]",dt=ne.getAssetIDByName("ChatIcon"),Ie=s.findByProps("triggerHapticFeedback","HapticFeedbackTypes"),xe=s.findByProps("selectPrivateChannel"),ct=s.findByName("SelectedChannelStore"),ft=s.findByProps("useStateFromStores"),pt=ft?.useStateFromStores,Y=s.findByProps("getGuildId"),J=s.findByProps("colors","unsafe_rawColors")?.colors,gt=s.findByProps("ME"),ht=gt?.ME??"/channels/@me";function mt(){if(Ie?.triggerHapticFeedback(Ie.HapticFeedbackTypes.SOFT),xe?.selectPrivateChannel){const e=ct?.getLastSelectedChannelId?.();xe.selectPrivateChannel(e)}}function yt(){try{return Y?pt([Y],function(){const e=Y?.getGuildId?.();return e==null||e===ht}):!1}catch{return!1}}function Ae(){const e=yt(),t=e?J?.WHITE??"#fff":J?.INTERACTIVE_NORMAL??"#80848e";return n.createElement(o.Pressable,{onPress:mt,style:{flex:1,alignItems:"center",justifyContent:"center"}},e?n.createElement(o.View,{style:{position:"absolute",left:0,top:"25%",width:4,height:"50%",borderRadius:2,backgroundColor:J?.WHITE??"#fff"}}):null,n.createElement(o.Image,{source:dt,style:{width:28,height:28,tintColor:t}}))}function bt(){const e=s.findByName("GuildsBar");if(e)return{default:e};let t=s.find(function(r){try{return r?.default?.type?.name==="GuildsBar"}catch{return!1}});return t?.default||(t=s.find(function(r){try{return r?.default?.displayName==="GuildsBar"}catch{return!1}}),t?.default)?t:null}function St(e){const t=bt();if(!t?.default)return console.log(at,"WARN: GuildsBar not found"),!1;const r=t.default;return De(r,Ae),t.default=function(){return n.createElement(Ae)},t.default.displayName="GuildsBar",e.push(function(){t.default=r}),!0}const Z="[ServerDrawer]",a=[];var Et={onLoad(){console.log(Z,"onLoad");let e=0;lt(a),e++,Qe(a)&&e++,Ve(a)&&e++,Ge(a)&&e++,We(a)&&e++,ut(a)&&e++,x("QuestDockContentCollapsed",a)&&e++,x("QuestDockEnrolledHeader",a)&&e++,x("QuestDockUnenrolledHeader",a)&&e++,x("QuestDockEnrolledBody",a)&&e++,x("QuestDockUnenrolledBody",a)&&e++,St(a)&&e++,console.log(Z,`onLoad done \u2014 ${e} patches applied, ${a.length} cleanups`)},onUnload(){console.log(Z,"onUnload");for(const e of a)e();a.length=0}};return L.default=Et,Object.defineProperty(L,"__esModule",{value:!0}),L})({},vendetta.metro,vendetta.metro.common,window.React,vendetta.metro.common.ReactNative,vendetta.ui,vendetta.ui.assets);