// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-3.0-or-later // @source: https://gitlab.com/soapbox-pub/ditto/-/tree/f0a3877c import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{Ar as t,Fn as n,N as r,ir as i,qi as a,r as o,x as s}from"./lucide-icons-BdRF0moN.js";import{t as c}from"./jsx-runtime-By8HlURe.js";import{t as l}from"./dist-DQ82bf9M.js";import{h as u}from"./useQuery-rCAlChE8.js";import{t as d}from"./useMutation-CgsR0O-3.js";import{o as f,t as p}from"./useCurrentUser-C6OJJlWo.js";import{t as m}from"./utils-BFSTDHdM.js";import{t as h}from"./useNostrPublish-CrMjnYm4.js";import{C as g,D as _,E as v,R as y,S as b,a as x,c as ee,j as S,m as C,o as w,r as T,w as E,x as D}from"./blobbi-CLChx8JU.js";import{l as te,n as ne,o as re,u as O}from"./useStatusReaction-L-HlqtEq.js";import{b as ie,d as k,m as A,n as j}from"./blobbi-shop-items-gin9pdH4.js";import{a as M,d as N,l as P,m as F,o as I,p as ae,s as oe,t as L}from"./blobbi-action-utils-CeIPzrFd.js";var R=e(a(),1);async function z(e,t){let n=C(t),r=AbortSignal.timeout(1e4),i=(await e.query([{kinds:[...T],authors:[t],"#d":n}],{signal:r})).filter(E);if(i.length===0)return null;let a=i.filter(e=>e.kind===w);if(a.length>0)return _(a.sort((e,t)=>t.created_at-e.created_at)[0])??null;let o=i.filter(e=>b(e));return o.length>0?_(o.sort((e,t)=>t.created_at-e.created_at)[0])??null:null}var B=c(),V={feed:5,play:8,clean:6,medicine:10,boost:7},H={play_music:7,sing:9},U={...V,...H};function W(e){return U[e]??0}function G(e,t=1){return t<1?0:(V[e]??0)*t}function K(e,t){let n=(e??0)+t;return Math.max(0,n)}function q(e){return e<=0?``:`+${e} XP`}function se(e){let{nostr:t}=l(),n=(0,R.useCallback)(async(e,n)=>{let r=(await t.query([{kinds:[x],authors:[e],"#d":[n]}])).filter(e=>g(e)&&!D(e)).sort((e,t)=>t.created_at-e.created_at);return r.length===0?null:v(r[0])??null},[t]);return{fetchFreshBlobbiBeforeAction:(0,R.useCallback)(async r=>{if(!e)return null;let{companion:i,profile:a}=r;if(i.isLegacy)return console.warn(`[FreshBlobbi] Refusing to act on legacy companion (unsupported):`,i.d.slice(0,24)),null;let[o,s]=await Promise.all([n(e,i.d),z(t,e)]),c=o??i,l=s??a;return{companion:c,allTags:c.allTags,content:c.event.content,profileAllTags:l.allTags,profileEvent:l.event}},[e,t,n])}}var ce={orange:`text-orange-500`,yellow:`text-yellow-500`,green:`text-green-500`,blue:`text-blue-500`,violet:`text-violet-500`},le={orange:`bg-orange-500/10`,yellow:`bg-yellow-500/10`,green:`bg-green-500/10`,blue:`bg-blue-500/10`,violet:`bg-violet-500/10`},ue={orange:`#f97316`,yellow:`#eab308`,green:`#22c55e`,blue:`#3b82f6`,violet:`#8b5cf6`},de=`currentColor`,fe=.12,pe={hunger:s,happiness:i,health:n,hygiene:t,energy:o},me={sm:{container:`size-9`,icon:`size-3.5`,strokeWidth:2.5,alertSize:`size-2.5`,alertPos:`-top-1 -right-1.5`,gapDeg:20},md:{container:`size-[4.5rem] sm:size-20`,icon:`size-6 sm:size-7`,strokeWidth:2.5,alertSize:`size-3.5`,alertPos:`-top-1.5 -right-2`,gapDeg:16}},J=36,Y=15,X=J/2,Z=J/2,Q=2*Math.PI*Y;function $({filled:e,max:t,fillHex:n,strokeWidth:r,gapDeg:i}){let a=(360-i*t)/t,o=a/360*Q,s=[],c=i/2;for(let l=0;l{if(!o?.pubkey)throw Error(`You must be logged in to use items`);if(!e)throw Error(`No companion selected`);if(!t)throw Error(`Profile not found`);if(!oe(e,l)){let t=N(e,l);throw Error(t??`This companion cannot use this item`)}let u=j(i);if(!u)throw Error(`Item not found in catalog`);if(!u.effect)throw Error(`This item has no effect`);let d=e.stage===`egg`;if(d&&l===`medicine`&&!F(u.effect))throw Error(`This medicine has no effect on eggs`);if(d&&l===`clean`&&!ae(u.effect))throw Error(`This item has no cleaning effect on eggs`);let f=await n();if(!f)throw Error(`Failed to prepare companion for action`);let p=Math.floor(Date.now()/1e3),m=ie({stage:f.companion.stage,state:f.companion.state,stats:f.companion.stats,lastDecayAt:f.companion.lastDecayAt,now:p}).stats;if(l===`play`){let e=Math.abs(u.effect.energy??0),t=m.energy;if(e>0&&t0&&r<100)&&!(e>0&&t>=e))throw Error(`Playing would have no effect - your Blobbi is already at maximum happiness and has no energy to spend`)}let h=f.companion.stage===`egg`,g={},_={};if(h&&l===`medicine`){let e=u.effect.health??0,t=I(m.health??0,e);g.health=t.toString(),_.health=t-(m.health??0),g.hygiene=(m.hygiene??0).toString(),g.happiness=(m.happiness??0).toString(),g.hunger=`100`,g.energy=`100`}else if(h&&l===`clean`){let e=I(m.hygiene??0,u.effect.hygiene??0),t=I(m.happiness??0,u.effect.happiness??0);g.hygiene=e.toString(),_.hygiene=e-(m.hygiene??0),g.happiness=t.toString();let n=t-(m.happiness??0);n!==0&&(_.happiness=n),g.health=(m.health??0).toString(),g.hunger=`100`,g.energy=`100`}else{let e=M({...m},u.effect);g.hunger=P(e.hunger).toString(),_.hunger=(e.hunger??0)-(m.hunger??0),g.happiness=P(e.happiness).toString(),_.happiness=(e.happiness??0)-(m.happiness??0),g.energy=P(e.energy).toString(),_.energy=(e.energy??0)-(m.energy??0),g.hygiene=P(e.hygiene).toString(),_.hygiene=(e.hygiene??0)-(m.hygiene??0),g.health=P(e.health).toString(),_.health=(e.health??0)-(m.health??0)}let v=p.toString(),b=f.companion.progressionState,C=f.allTags;(b===`incubating`||b===`evolving`)&&te(`interactions`,1,o?.pubkey,f.companion.d);let w=f.content;if(b===`incubating`||b===`evolving`){let e=re(o?.pubkey,f.companion.d);e&&e.length>0&&(w=y(f.content,e))}let T=ne(f.companion)??{},E=G(l,1),D=K(f.companion.experience??0,E),O=S(C,{...g,...T,experience:D.toString(),last_interaction:v,last_decay_at:v});r(await s({kind:x,content:w,tags:O,prev:f.companion.event}));let L=k[l];L&&A(s,{ownerPubkey:f.companion.event.pubkey,blobbiDTag:f.companion.d,action:L,source:a,itemId:i});{let e=ee(f.companion.event.pubkey,f.companion.d);c.invalidateQueries({queryKey:[`blobbi-interactions`,e]})}return{itemName:u.name,action:l,statsChanged:_,xpGained:E,newXP:D}},onSuccess:({itemName:e,action:t,xpGained:n})=>{let r=L[t],i=q(n);f({title:`${r.label} successful!`,description:`Used ${e} on your Blobbi. ${i}`}),O(t,o?.pubkey)},onError:e=>{f({title:`Failed to use item`,description:e.message,variant:`destructive`})}})}export{K as a,z as c,se as i,$ as n,W as o,he as r,q as s,ge as t}; // @license-end