1import{j as e}from"./vendor-query-CoKCXE9e.js";import{r as c,f as M}from"./vendor-react-NJLRjSjs.js";import{D as E}from"./DashboardLayout-5jOk5tUx.js";import{P as F}from"./PageHeader-CnzFbckG.js";import{s as u,b as q,a as R,B as N,aA as U}from"./index-DBAqNMm0.js";import{B as z}from"./badge-Csgi5GhZ.js";import{A as D,b as B}from"./useDragonPoints-C4S1wFWL.js";import{D as W,a as X}from"./dialog-eMS9T6fc.js";import{X as G,c as V,d as J,am as H,at as K,bt as P,s as Q,L as $}from"./vendor-icons-BJkqKOmI.js";import{f as Y}from"./format-BwcsVm1d.js";import"./brandLogo-C0908pMR.js";import"./dropdown-menu-BFHvz46V.js";import"./index-Cd4qj_5u.js";import"./DonnyChatView-BBEsDqHi.js";import"./DonnyQuickChips-DBak1d39.js";import"./useSignedUrl-D4M-jcc1.js";import"./AppStatusBadge-BgmVf9wi.js";import"./index-D5Al1KqY.js";import"./WebOnly-CfHjVaUL.js";import"./platform-BaPLhuaL.js";import"./input-DJN1ntgm.js";import"./separator-dobnH5n_.js";import"./sheet-BHhZsRsH.js";import"./useConversations-olrM9-KO.js";import"./useOrgData-BHYzqlqx.js";import"./vendor-supabase-B1MD-rV-.js";import"./index-B6uzpQIh.js";import"./useFeatureFlag-CzIwtlTg.js";import"./en-US-DWrl2lTx.js";const Z=t=>{const[x,l]=c.useState([]),[p,d]=c.useState(!0),[b,w]=c.useState(null);return c.useEffect(()=>{(async()=>{try{d(!0);const{data:{user:h}}=await u.auth.getUser();if(!h)throw new Error("Not authenticated");let f=u.from("analytics_events").select("event_data, created_at").eq("user_id",h.id).eq("event_type","dragon_feed_like");t&&(f=f.or(`org_unit_id.eq.${t},org_unit_id.is.null`));const{data:g,error:v}=await f.order("created_at",{ascending:!1});if(v)throw v;const m=new Map;g==null||g.forEach(s=>{const a=s.event_data,y=a==null?void 0:a.content_id,A=a==null?void 0:a.creator_id,_=a==null?void 0:a.action;if(y&&A){const I=m.get(y);(!I||new Date(s.created_at)>I.timestamp)&&m.set(y,{creatorId:A,action:_,timestamp:new Date(s.created_at)})}});const j=Array.from(m.entries()).filter(([s,a])=>a.action==="like").map(([s,a])=>({contentId:s,...a}));if(j.length===0){l([]);return}const S=[...new Set(j.map(s=>s.creatorId))],{data:L,error:r}=await u.from("creator_profiles").select("id, user_id, creator_name, portfolio_urls, profile_slug").in("user_id",S);if(r)throw r;const o=new Map((L??[]).map(s=>[s.user_id,s])),n=j.map(async s=>{const a=o.get(s.creatorId);if(!a)return null;const y=s.contentId.replace(`${a.id}-`,""),_=(Array.isArray(a.portfolio_urls)?a.portfolio_urls:[]).find(C=>C===y);if(!_)return null;let I=_;if(!_.startsWith("http")){const{data:C}=await u.storage.from("profile-assets").createSignedUrl(_,3600);C!=null&&C.signedUrl&&(I=C.signedUrl)}const T=/\.(mp4|webm|mov|avi)$/i.test(_);
1return{id:s.contentId,url:I,type:T?"video":"image",creatorName:a.creator_name||"Creator",creatorSlug:a.profile_slug||"",creatorId:a.user_id||a.id,submittedAt:s.timestamp}}),i=await Promise.all(n);l(i.filter(s=>s!==null))}catch(h){w(h instanceof Error?h.message:"Failed to load liked content")}finally{d(!1)}})()},[t]),{likedItems:x,loading:p,error:b}},O=({item:t,allItems:x,currentIndex:l,onClose:p,onNavigate:d})=>{const[b,w]=c.useState(!1),[k,h]=c.useState(!1),f=c.useRef(null),g=M(),{toast:v}=q(),{activeOrgUnit:m}=R();c.useEffect(()=>{(async()=>{if(!t)return;const{data:{user:n}}=await u.auth.getUser();if(!n)return;const{data:i}=await u.from("analytics_events").select("event_data").eq("user_id",n.id).eq("event_type","dragon_feed_like").eq("event_data->>content_id",t.id).order("created_at",{ascending:!1}).limit(1).maybeSingle();if(i&&typeof i.event_data=="object"&&i.event_data!==null){const s=i.event_data;w(s.action==="like")}else w(!1)})()},[t==null?void 0:t.id,t]),c.useEffect(()=>{const o=n=>{n.key==="Escape"&&p(),n.key==="ArrowLeft"&&l>0&&d(l-1),n.key==="ArrowRight"&&l<x.length-1&&d(l+1)};return window.addEventListener("keydown",o),()=>window.removeEventListener("keydown",o)},[l,x.length,p,d]);const j=async()=>{var n,i;const o=!b;w(o);try{const{data:{user:s}}=await u.auth.getUser();if(!s)return;if(await u.from("analytics_events").insert({event_type:"dragon_feed_like",user_id:s.id,org_unit_id:(m==null?void 0:m.id)??null,page_url:U(window.location.href),user_agent:navigator.userAgent,event_data:{content_id:t==null?void 0:t.id,creator_id:t==null?void 0:t.creatorId,action:o?"like":"unlike"}}),o){const a=((n=s.user_metadata)==null?void 0:n.full_name)||((i=s.email)==null?void 0:i.split("@")[0])||"Someone";await u.functions.invoke("create-notification",{body:{recipientId:t==null?void 0:t.creatorId,type:"content_liked",category:"content",title:"New like",body:`${a} liked your content`,actorId:s.id,actorName:a,icon:"like",data:{content_id:t==null?void 0:t.id},emailData:{likerName:a,contentUrl:t==null?void 0:t.url}}}).catch(y=>console.error("Failed to send like notification:",y))}}catch(s){console.error("Failed to track like:",s)}},S=async()=>{var o;if(t)try{const{data:n,error:i}=await u.rpc("create_or_get_direct_conversation",{user1_uuid:(o=(await u.auth.getUser()).data.user)==null?void 0:o.id,user2_uuid:t.creatorId});if(i)throw i;v({title:"Opening conversation",description:`Starting a conversation with ${t.creatorName}`}),g(`/dashboard/business/messages/direct/${n}`)}catch(n){console.error("Failed to create conversation:",n),v({title:"Error",description:"Failed to start conversation. Please try again.",variant:"destructive"})}},L=()=>{t!=null&&t.creatorSlug&&g(`/creator/${t.creatorSlug}`)},r=async()=>{if(f.current)try{k?(f.current.pause(),h(!1)):(await f.current.play(),h(!0))}catch(o){console.error("Video playback error:",o)}};return t?e.jsx(W,{open:!!t,onOpenChange:p,children:e.jsx(X,{className:"max-w-5xl h-[90vh] p-0 gap-0",children:e.jsxs("div",{className:"relative h-full flex flex-col bg-background",children:[e.jsx(N,{variant:"ghost",size:"icon",className:"absolute top-2 right-2 z-10 bg-black/50 hover:bg-black/70 text-white",onClick:p,children:e.jsx(G,{className:"h-4 w-4"})}),l>0&&e.jsx(N,{variant:"ghost",size:"icon",className:"absolute left-2 top-1/2 -translate-y-1/2 z-10 bg-black/50 hover:bg-black/70 text-white",onClick:()=>d(l-1),children:e.jsx(V,{className:"h-6 w-6"})}),l<x.length-1&&e.jsx(N,{variant:"ghost",size:"icon",className:"absolute right-2 top-1/2 -translate-y-1/2 z-10 bg-black/50 hover:bg-black/70 text-white",onClick:()=>d(l+1),children:e.jsx(J,{className:"h-6 w-6"})}),e.jsx("div",{className:"flex-1 flex items-center justify-center bg-black/95 relative",children:t.type==="video"?e.jsxs(e.Fragment,{children:[e.jsx("video",{ref:f,src:t.url,className:"max-h-full max-w-full object-contain",controls:!0,playsInline:!0,onPlay:()=>h(!0),onPause:()=>h(!1)}),!k&&e.jsx("button",{className:"absolute inset-0 flex items-center justify-center",onClick:r,children:e.jsx("div",{className:"bg-white/90 rounded-full p-4 shadow-lg",children:e.jsx(H,{className:"h-8 w-8 text-primary fill-current"})})})]}):e.jsx("img",{src:t.url,alt:`Content by ${t.creatorName}`,className:"max-h-full max-w-full object-contain"})}),e.jsx("div",{className:"p-4 border-t bg-card",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("button",{onClick:L,className:"flex items-center gap-3 hover:opacity-80 transition-opacity",children:[e.jsx(D,{className:"h-10 w-10",children:e.jsx(B,{children:e.jsx(K,{className:"h-5 w-5"})})}),e.jsxs("div",{className:"text-left",children:[e.jsx("p",{className:"font-semibold text-foreground",children:t.creatorName}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Creator"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(N,{variant:b?"default":"outline",size:"sm",onClick:j,className:"gap-2",children:[e.jsx(P,{className:`h-4 w-4 ${b?"fill-current":""}`}),"Like"]}),e.jsxs(N,{variant:"outline",size:"sm",onClick:S,className:"gap-2",children:[e.jsx(Q,{className:"h-4 w-4"}),"Message"]})]})]})})]})})}):null},Ie=()=>{const{activeOrgUnit:t}=R(),{likedItems:x,loading:l,error:p}=Z(t==null?void 0:t.id),[d,b]=c.useState([]),[w,k]=c.useState(null),[h,f]=c.useState(0),[g,v]=c.useState(new Set);c.useEffect(()=>{x&&b(x)},[x]);const m=M(),{toast:j}=q(),S=(r,o)=>{k(r),f(o)},L=async(r,o,n)=>{n.stopPropagation(),v(i=>new Set(i).add(r));try{const{data:{user:i}}=await u.auth.getUser();if(!i)return;await u.from("analytics_events").insert({event_type:"dragon_feed_like",user_id:i.id,org_unit_id:(t==null?void 0:t.id)??null,page_url:U(window.location.href),user_agent:navigator.userAgent,event_data:{content_id:r,creator_id:o,action:"unlike"}}),b(s=>s.filter(a=>a.id!==r)),j({title:"Removed from Inspiration",description:"Content removed from your saved items"})}catch(i){console.error("Failed to unlike:",i),j({title:"Error",description:"Failed to remove like. Please try again.",variant:"destructive"}),v(s=>{const a=new Set(s);return a.delete(r),a})}};return l?e.jsx(E,{userRole:"business_client",children:e.jsxs("div",{className:"min-h-screen bg-white overflow-x-hidden",children:[e.jsx(F,{children:e.jsxs("div",{className:"flex items-center",children:[e.jsx("span",{className:"h-5 w-5 bg-gray-200 rounded-full animate-pulse mr-2"}),e.jsx("span",{className:"flex-1 h-4 bg-gray-200 rounded-full animate-pulse mx-8"})]})}),e.jsx("div",{className:"px-4 pt-4 pb-24 md:pb-0 flex items-center justify-center min-h-[300px]",children:e.jsx($,{className:"h-10 w-10 animate-spin text-dc-teal"})})]})}):p?e.jsx(E,{userRole:"business_client",children:e.jsx("div",{className:"min-h-screen bg-white overflow-x-hidden flex items-center justify-center p-4",children:e.jsx("div",{className:"border-2 border-dc-teal rounded-2xl p-6 text-center max-w-sm w-full",children:e.jsx("p",{className:"text-sm text-red-500 font-medium",children:p})})})}):e.jsxs(E,{userRole:"business_client",children:[e.jsxs("div",{className:"min-h-screen bg-white overflow-x-hidden md:max-w-4xl md:mx-auto",children:[e.jsx(F,{children:e.jsxs("div",{className:"flex items-center",children:[e.jsx("button",{onClick:()=>m(-1),className:"text-dc-pink-accent text-lg mr-2 flex items-center",children:e.jsx(V,{className:"h-5 w-5"})}),e.jsx("h1",{className:"flex-1 font-sans text-base font-bold text-gray-900 uppercase tracking-wide text-center",children:"Inspiration"}),e.jsxs(z,{variant:"secondary",className:"rounded-full text-xs shrink-0",children:[d.length," saved"]})]})}),e.jsx("div",{className:"px-4 pt-4 pb-24 md:pb-0",children:d.length===0?e.jsxs("div",{className:"border-2 border-dc-teal rounded-2xl p-10 text-center",children:[e.jsx(P,{className:"h-12 w-12 text-gray-300 mx-auto mb-3 opacity-50"}),e.jsx("h3",{className:"font-bold text-gray-900 mb-1",children:"No liked content yet"}),e.jsx("p",{className:"text-sm text-gray-500 mb-4",children:"Start exploring the Dragon Feed and like content you love!"}),e.jsx(N,{onClick:()=>
1m("/dashboard/business/dragon-feed"),className:"rounded-full bg-dc-teal-btn text-white font-bold px-6",children:"Explore Dragon Feed"})]}):e.jsx("div",{className:"grid grid-cols-2 gap-3",children:d.map((r,o)=>e.jsxs("div",{className:"border-2 border-dc-teal rounded-2xl overflow-hidden bg-white cursor-pointer active:scale-95 transition-transform",onClick:()=>S(r,o),children:[e.jsxs("div",{className:"relative aspect-square overflow-hidden bg-gray-100",children:[r.type==="video"?e.jsxs(e.Fragment,{children:[e.jsx("video",{src:r.url,className:"w-full h-full object-cover",muted:!0,playsInline:!0}),e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black/20",children:e.jsx("div",{className:"bg-white/90 rounded-full p-2 shadow",children:e.jsx(H,{className:"h-5 w-5 text-dc-teal fill-current"})})})]}):e.jsx("img",{src:r.url,alt:`Content by ${r.creatorName}`,className:"w-full h-full object-cover",loading:"lazy"}),e.jsx("div",{className:"absolute top-2 left-2",children:e.jsx(z,{className:"text-xs bg-black/60 text-white border-0 rounded-full",children:r.type==="video"?"Video":"Photo"})}),e.jsx("div",{className:"absolute top-2 right-2",children:e.jsx(N,{size:"sm",variant:"secondary",className:"h-7 w-7 p-0 rounded-full bg-white/90 hover:bg-white",onClick:n=>L(r.id,r.creatorId,n),disabled:g.has(r.id),children:g.has(r.id)?e.jsx($,{className:"h-3 w-3 animate-spin text-gray-400"}):e.jsx(P,{className:"h-3 w-3 fill-red-500 text-red-500"})})})]}),e.jsxs("div",{className:"p-3",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(D,{className:"h-6 w-6 ring-1 ring-dc-teal",children:e.jsx(B,{className:"text-xs bg-dc-teal/10",children:e.jsx(K,{className:"h-3 w-3 text-dc-teal"})})}),e.jsx("button",{onClick:n=>{n.stopPropagation(),m(`/creator/${r.creatorSlug}`)},className:"font-bold text-xs text-gray-900 truncate hover:text-dc-teal transition-colors text-left flex-1",children:r.creatorName})]}),r.submittedAt&&e.jsx("p",{className:"text-xs text-gray-500",children:Y(new Date(r.submittedAt),"MMM d, yyyy")})]})]},r.id))})})]}),w&&e.jsx(O,{item:w,allItems:d,currentIndex:h,onClose:()=>k(null),onNavigate:f})]})};export{Ie as default}; 2//# sourceMappingURL=BusinessActivity-CDM0_eFG.js.map
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.