1(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[5875],{14734:(e,t,s)=>{"use strict";async function l(e){let t=e.per_page||5,s="".concat("https://api.sociallibra.com/wp-json/social_libra/v2","/story_frames");if(e.slug)s+="/".concat(e.slug),e.article&&(s+="?article=".concat(e.article));else{let l=new URLSearchParams({per_page:String(t)});e.searchQuery&&l.append("s",e.searchQuery),e.offset&&l.append("offset",String(e.offset)),e.user&&l.append("user",String(e.user)),e.topic&&l.append("topic",String(e.topic)),s+="?".concat(l.toString())}let l={next:{revalidate:0,cache:"no-store"},method:"GET",credentials:"include",headers:{"Content-Type":"application/json"}};e.token&&(l.headers.Authorization="Bearer ".concat(e.token));let r=await fetch(s,l);if(!r.ok)return{frames:{},articles:{},max:!1};let a=await r.json();return"object"!=typeof a?{frames:{},articles:{},max:!1}:(e.returnSingle&&Object.keys(a).map((e,t)=>0===t&&a[e]),{frames:a.frames,articles:a.articles,max:Object.keys(a).length<t,currentFrame:e.slug?e.slug:""})}s.d(t,{A:()=>l})},25765:(e,t,s)=>{"use strict";s.d(t,{default:()=>o});var l=s(95155),r=s(12115),a=s(42409),n=s(32382),i=s(1399);function o(e){var t,s,o;let{influencer:c}=e,d=null==c||null==(t=c.followers)?void 0:t.length,{user:u,setCurrentUser:m}=(0,r.useContext)(a.Rs),[x,h]=(0,r.useState)(!1),{users:p,setUsersData:g}=(0,r.useContext)(a.Aw),f=(null==(s=u.following)?void 0:s.length)&&(null==(o=u.following)?void 0:o.includes(c.id))?"Unfollow":"Follow";return(0,l.jsxs)(l.Fragment,{children:[d?(0,l.jsxs)("p",{className:"text-sm",children:[d," following"]}):null,(0,l.jsx)("button",{onClick:()=>{if(!u.token)return void h(!0);let e={method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(u.token)},body:JSON.stringify({followed_user_id:c.id})};fetch("".concat("https://api.sociallibra.com/wp-json/social_libra/v2","/follow_user"),e).then(e=>e.json()).then(e=>{if("success"==e){var t,s;let e=(null==(t=u.following)?void 0:t.length)?u.following:[],l=p.choices["slu_".concat(c.id)]&&(null==(s=p.choices["slu_".concat(c.id)].followers)?void 0:s.length)?p.choices["slu_".concat(c.id)].followers:[];e&&e.includes(c.id)?(e=e.filter(e=>e!==c.id),l&&(l=l.filter(e=>e!==u.id))):(e.push(c.id),l&&l.push(u.id)),g({...p,choices:{...p.choices,["slu_".concat(c.id)]:{...p.choices["slu_".concat(c.id)],followers:l}}}),m&&m({...u,following:e})}})},className:"btn-primary",children:f}),!u.token&&x?(0,l.jsxs)(n.A,{className:"sm:w-1/3",onClose:()=>{h(!1)},children:[(0,l.jsx)("p",{className:"text-center",children:"You need to be logged in to follow users"}),(0,l.jsx)(i.default,{})]}):null]})}},26125:(e,t,s)=>{"use strict";s.d(t,{T:()=>n});var l=s(95155),r=s(12115),a=s(25016);let n=r.forwardRef((e,t)=>{let{className:s,...r}=e;return(0,l.jsx)("textarea",{className:(0,a.cn)("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",s),ref:t,...r})});n.displayName="Textarea"},30220:(e,t,s)=>{"use strict";async function l(e){let t=e.per_page||5,s="".concat("https://api.sociallibra.com/wp-json/social_libra/v2","/users");e.id?s+="/".concat(e.id):e.name?s+="/".concat(e.name,"?getBy=login"):(s+="?per_page=".concat(t),e.searchQuery&&(s+="&s=".concat(e.searchQuery)),e.roles&&(s+="&roles=".concat(e.roles))),console.log("Loading user from ",s);let l={next:{revalidate:36,tags:["users"]},headers:{"Content-Type":"application/json",Authorization:e.token?"Bearer ".concat(e.token):""}},r=await fetch(s,l);if(!r.ok)return!1;let a=await r.json(),n=a;return e.returnSingle&&(n=Object.keys(a).map(e=>a[e])),{choices:n,max:Object.keys(a).length<t}}s.d(t,{A:()=>l})},36021:()=>{},60353:(e,t,s)=>{"use strict";s.d(t,{t:()=>f,m:()=>j,default:()=>b,emptyFrame:()=>g});var l=s(95155),r=s(14734),a=s(64133),n=s(63523),i=s(42409),o=s(70925),c=s(12115),d=s(96354),u=s(33431),m=s(32382),x=s(1399);function h(e){let{topic:t,topicId:s,topicLabel:o,hasFrames:h=!1}=e,p=o||t,{user:g}=(0,c.useContext)(i.Rs),{setFramesData:f}=(0,c.useContext)(j),[b,v]=(0,c.useState)([]),[N,w]=(0,c.useState)(!0),[y,k]=(0,c.useState)(""),[C,S]=(0,c.useState)("idle"),[A,_]=(0,c.useState)(new Set),[F,T]=(0,c.useState)(""),[E,L]=(0,c.useState)(""),[O,P]=(0,c.useState)(""),[z,R]=(0,c.useState)(""),[D,I]=(0,c.useState)("idle"),[M,B]=(0,c.useState)(""),[V,U]=(0,c.useState)(null),[$,Y]=(0,c.useState)(!1),[K,J]=(0,c.useState)(1),[Q,W]=(0,c.useState)(!1),[q,H]=(0,c.useState)(!1),G=e=>{1===e?(w(!0),v([]),k("")):W(!0),fetch("".concat("https://api.sociallibra.com/wp-json/social_libra/v2","/rss_feed?topics=").concat(encodeURIComponent(t),"&page=").concat(e)).then(e=>e.json()).then(t=>{let s=Object.values(t.articles||{}),l=new Set(1===e?[]:b.map(e=>e.url)),r=s.filter(e=>!l.has(e.url));v(t=>1===e?s:[...t,...r]),H("boolean"==typeof t.max?t.max:e>1&&0===r.length),J(e),w(!1),W(!1)}).catch(()=>{k("Could not load articles for this topic."),w(!1),W(!1)})};(0,c.useEffect)(()=>{G(1)},[t]);let X=async()=>{let e=b.filter(e=>A.has(e.url));if(F.trim()&&e.length&&g.token){I("submitting"),B("");try{var l;let[a,...n]=e,i=await (0,d.kj)({title:F.trim(),description:"",topics:[s?String(s):t],perspectiveLeft:E.trim(),perspectiveNeutral:O.trim(),perspectiveRight:z.trim(),url:a.url,articleTitle:a.title},g.token),o=null!=(l=i.frame_id)?l:i.id;if(!o)return void I("error");for(let e of n)await (0,d.K2)(o,{title:e.title,url:e.url},g.token);let c=await (0,r.A)({slug:String(o),token:g.token}),u=c.frames?Object.values(c.frames)[0]:null;u&&(f(e=>({...e,articles:{...e.articles,...c.articles||{}}})),U(u)),S("idle")}catch(e){B((null==e?void 0:e.message)||"Something went wrong. Please try again."),I("error")}}};return(0,l.jsxs)("div",{className:"w-full",children:[!h&&(0,l.jsxs)("p",{className:"text-center text-muted-foreground my-4",children:["No story frames yet for ",(0,l.jsx)("strong",{children:p}),". Start one from the articles below."]}),$&&(0,l.jsxs)(m.A,{className:"sm:w-3/5 p-2",onClose:()=>Y(!1),children:[(0,l.jsx)("h4",{children:"You have to be signed in to create a Story Frame. If you do not have an account, you may register for free."}),(0,l.jsx)(x.default,{onSuccess:()=>Y(!1)})]}),V&&(0,l.jsxs)("div",{className:"mb-6 w-full",children:[(0,l.jsxs)("div",{className:"mb-2 p-4 border rounded-lg bg-green-50 text-green-800 text-sm flex items-center gap-4",children:["Story Frame created! Start voting below.",(0,l.jsx)("button",{onClick:()=>U(null),className:"ms-auto text-xs text-muted-foreground",children:"Dismiss"})]}),(0,l.jsx)(n.default,{currentFrame:V,opened:!0,list:!1})]}),N?(0,l.jsx)(a.A,{}):y?(0,l.jsx)("p",{className:"text-red-400 text-center",children:y}):0===b.length?!h&&(0,l.jsx)("p",{className:"text-center text-muted-foreground",children:"No recent articles found for this topic."}):(0,l.jsxs)(l.Fragment,{children:["idle"===C?(0,l.jsxs)("div",{className:"mb-4 flex flex-col items-center gap-2",children:[h&&(0,l.jsx)("p",{className:"text-sm text-muted-foreground",children:"Or start a new Story Frame from recent articles"}),(0,l.jsx)(u.$,{variant:"outline",onClick:()=>
1{if(!g.token)return void Y(!0);_(new Set(b.map(e=>e.url))),T(p),I("idle"),S("building")},children:"Create a Story Frame from these articles"})]}):(0,l.jsxs)("div",{className:"mb-6 p-4 border rounded-lg bg-background shadow-sm space-y-3",children:[(0,l.jsx)("h3",{className:"font-semibold text-sm",children:"Create a Story Frame from this topic"}),(0,l.jsxs)("div",{className:"space-y-1",children:[(0,l.jsx)("label",{className:"text-xs text-muted-foreground block",children:"Title"}),(0,l.jsx)("input",{value:F,onChange:e=>T(e.target.value),className:"w-full border rounded px-2 py-1.5 text-sm bg-background"})]}),(0,l.jsxs)("div",{className:"space-y-1",children:[(0,l.jsx)("label",{className:"text-xs text-muted-foreground block",children:"Perspective labels (optional)"}),(0,l.jsxs)("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-2",children:[(0,l.jsx)("input",{value:E,onChange:e=>L(e.target.value),placeholder:"Perspective 1",className:"w-full border rounded px-2 py-1.5 text-sm bg-background",style:{borderColor:"#3B82F6"}}),(0,l.jsx)("input",{value:O,onChange:e=>P(e.target.value),placeholder:"Neutral",className:"w-full border rounded px-2 py-1.5 text-sm bg-background"}),(0,l.jsx)("input",{value:z,onChange:e=>R(e.target.value),placeholder:"Perspective 2",className:"w-full border rounded px-2 py-1.5 text-sm bg-background",style:{borderColor:"#DC2626"}})]})]}),(0,l.jsxs)("p",{className:"text-xs text-muted-foreground",children:[A.size," of ",b.length," articles selected â use the checkboxes below."]}),(0,l.jsxs)("div",{className:"flex gap-2",children:[(0,l.jsx)(u.$,{size:"sm",onClick:X,disabled:"submitting"===D||!F.trim()||!A.size,children:"submitting"===D?"Creatingâ¦":"Create Story Frame (".concat(A.size,")")}),(0,l.jsx)(u.$,{variant:"outline",size:"sm",onClick:()=>S("idle"),children:"Cancel"})]}),"error"===D&&(0,l.jsx)("p",{className:"text-red-500 text-xs",children:M||"Something went wrong. Please try again."})]}),(0,l.jsx)("div",{className:"grid gap-4 grid-cols-1 sm:grid-cols-2 md:grid-cols-3",children:b.map((e,t)=>{var s;let r=(null==(s=e.images)?void 0:s.medium)||e.urlToImage,a=A.has(e.url);return(0,l.jsxs)("div",{className:"border rounded-lg overflow-hidden flex flex-col bg-background shadow-sm transition-all ".concat("building"===C&&a?"ring-2 ring-primary":""),children:[r&&(0,l.jsx)("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",children:(0,l.jsx)("img",{src:r,alt:e.title,onError:e=>{e.currentTarget.style.display="none"},className:"w-full h-40 object-cover"})}),(0,l.jsxs)("div",{className:"p-3 flex flex-col gap-2 flex-1",children:[(()=>{let t=e.relative_time||e.date;return(e.source||e.category||t)&&(0,l.jsxs)("p",{className:"text-xs text-muted-foreground flex flex-wrap items-center gap-x-1",children:[e.source&&(0,l.jsx)("span",{children:e.source}),e.category&&(0,l.jsxs)(l.Fragment,{children:[e.source&&(0,l.jsx)("span",{children:"â¢"}),(0,l.jsx)("span",{className:"px-1.5 py-0.5 rounded bg-secondary text-secondary-foreground",children:e.category})]}),t&&(0,l.jsxs)(l.Fragment,{children:[(e.source||e.category)&&(0,l.jsx)("span",{children:"â¢"}),(0,l.jsx)("span",{children:t})]})]})})(),(0,l.jsx)("h4",{className:"font-semibold text-sm line-clamp-2",children:(0,l.jsx)("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",className:"hover:underline",children:e.title})}),e.description&&(0,l.jsx)("p",{className:"text-xs text-muted-foreground line-clamp-2",children:e.description}),"building"===C?(0,l.jsxs)("label",{className:"flex items-center gap-2 text-xs mt-auto cursor-pointer select-none",children:[(0,l.jsx)("input",{type:"checkbox",checked:a,onChange:()=>{var t;return t=e.url,void _(e=>{let s=new Set(e);return s.has(t)?s.delete(t):s.add(t),s})}}),"Include in Story Frame"]}):null]})]},t)})}),!q&&(0,l.jsx)("div",{className:"flex justify-center my-4",children:(0,l.jsx)(u.$,{variant:"outline",size:"sm",onClick:()=>G(K+1),disabled:Q,children:Q?"Loadingâ¦":"Load more"})})]})]})}function p(e){let{query:t,hasFrames:s=!1}=e,{user:r}=(0,c.useContext)(i.Rs),[n,o]=(0,c.useState)([]),[h,p]=(0,c.useState)(!0),[g,f]=(0,c.useState)(""),[j,b]=(0,c.useState)("idle"),[v,N]=(0,c.useState)(new Set),[w,y]=(0,c.useState)(""),[k,C]=(0,c.useState)(""),[S,A]=(0,c.useState)(""),[_,F]=(0,c.useState)(""),[T,E]=(0,c.useState)("idle"),[L,O]=(0,c.useState)(""),[P,z]=(0,c.useState)(null),[R,D]=(0,c.useState)(!1),[I,M]=(0,c.useState)(1),[B,V]=(0,c.useState)(!1),[U,$]=(0,c.useState)(!1),Y=e=>{1===e?(p(!0),o([]),f(""),b("idle")):V(!0),fetch("".concat("https://api.sociallibra.com/wp-json/social_libra/v2","/rss_feed?topics=").concat(encodeURIComponent(t),"&page=").concat(e)).then(e=>e.json()).then(t=>{let s=Object.values(t.articles||{}),l=new Set(1===e?[]:n.map(e=>e.url)),r=s.filter(e=>!l.has(e.url));o(t=>1===e?s:[...t,...r]),$("boolean"==typeof t.max?t.max:e>1&&0===r.length),M(e),p(!1),V(!1)}).catch(()=>{f("Could not load articles for this search."),p(!1),V(!1)})};(0,c.useEffect)(()=>{Y(1)},[t]);let K=async()=>{let e=n.filter(e=>v.has(e.url));if(w.trim()&&e.length&&r.token){E("submitting"),O("");try{var t;let[s,...l]=e,a=await (0,d.kj)({title:w.trim(),description:"",topics:[],perspectiveLeft:k.trim(),perspectiveNeutral:S.trim(),perspectiveRight:_.trim(),url:s.url,articleTitle:s.title},r.token),n=null!=(t=a.frame_id)?t:a.id;if(!n)return void E("error");for(let e of l)await (0,d.K2)(n,{title:e.title,url:e.url},r.token);z(n),b("idle")}catch(e){O((null==e?void 0:e.message)||"Something went wrong. Please try again."),E("error")}}};return(0,l.jsxs)("div",{className:"w-full",children:[!s&&(0,l.jsxs)("p",{className:"text-center text-muted-foreground my-4",children:["No story frames found for ",(0,l.jsx)("strong",{children:t}),". Start one from the articles below."]}),R&&(0,l.jsxs)(m.A,{className:"sm:w-3/5 p-2",onClose:()=>D(!1),children:[(0,l.jsx)("h4",{children:"You have to be signed in to create a Story Frame. If you do not have an account, you may register for free."}),(0,l.jsx)(x.default,{onSuccess:()=>D(!1)})]}),P&&(0,l.jsxs)("div",{className:"mb-4 p-4 border rounded-lg bg-green-50 text-green-800 text-sm flex items-center gap-4",children:["Story Frame created!",(0,l.jsx)("a",{href:"/story-frame/".concat(P),className:"font-bold underline ms-1",children:"View it â"}),(0,l.jsx)("button",{onClick:()=>z(null),className:"ms-auto text-xs text-muted-foreground",children:"Dismiss"})]}),h?(0,l.jsx)(a.A,{}):g?(0,l.jsx)("p",{className:"text-red-400 text-center",children:g}):0===n.length?!s&&(0,l.jsx)("p",{className:"text-center text-muted-foreground",children:"No recent articles found for this search."}):(0,l.jsxs)(l.Fragment,{children:["idle"===j?(0,l.jsxs)("div",{className:"mb-4 flex flex-col items-center gap-2",children:[s&&(0,l.jsx)("p",{className:"text-sm text-muted-foreground",children:"Or start a new Story Frame from these results"}),(0,l.jsx)(u.$,{variant:"outline",onClick:()=>
1{if(!r.token)return void D(!0);N(new Set(n.map(e=>e.url))),y(t),E("idle"),b("building")},children:"Create a Story Frame from these results"})]}):(0,l.jsxs)("div",{className:"mb-6 p-4 border rounded-lg bg-background shadow-sm space-y-3",children:[(0,l.jsx)("h3",{className:"font-semibold text-sm",children:"Create a Story Frame from this search"}),(0,l.jsxs)("div",{className:"space-y-1",children:[(0,l.jsx)("label",{className:"text-xs text-muted-foreground block",children:"Title"}),(0,l.jsx)("input",{value:w,onChange:e=>y(e.target.value),className:"w-full border rounded px-2 py-1.5 text-sm bg-background"})]}),(0,l.jsxs)("div",{className:"space-y-1",children:[(0,l.jsx)("label",{className:"text-xs text-muted-foreground block",children:"Perspective labels (optional)"}),(0,l.jsxs)("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-2",children:[(0,l.jsx)("input",{value:k,onChange:e=>C(e.target.value),placeholder:"Perspective 1",className:"w-full border rounded px-2 py-1.5 text-sm bg-background",style:{borderColor:"#3B82F6"}}),(0,l.jsx)("input",{value:S,onChange:e=>A(e.target.value),placeholder:"Neutral",className:"w-full border rounded px-2 py-1.5 text-sm bg-background"}),(0,l.jsx)("input",{value:_,onChange:e=>F(e.target.value),placeholder:"Perspective 2",className:"w-full border rounded px-2 py-1.5 text-sm bg-background",style:{borderColor:"#DC2626"}})]})]}),(0,l.jsxs)("p",{className:"text-xs text-muted-foreground",children:[v.size," of ",n.length," results selected â use the checkboxes below."]}),(0,l.jsxs)("div",{className:"flex gap-2",children:[(0,l.jsx)(u.$,{size:"sm",onClick:K,disabled:"submitting"===T||!w.trim()||!v.size,children:"submitting"===T?"Creatingâ¦":"Create Story Frame (".concat(v.size,")")}),(0,l.jsx)(u.$,{variant:"outline",size:"sm",onClick:()=>b("idle"),children:"Cancel"})]}),"error"===T&&(0,l.jsx)("p",{className:"text-red-500 text-xs",children:L||"Something went wrong. Please try again."})]}),(0,l.jsx)("div",{className:"grid gap-4 grid-cols-1 sm:grid-cols-2 md:grid-cols-3",children:n.map((e,t)=>{var s;let r=(null==(s=e.images)?void 0:s.medium)||e.urlToImage,a=v.has(e.url);return(0,l.jsxs)("div",{className:"border rounded-lg overflow-hidden flex flex-col bg-background shadow-sm transition-all ".concat("building"===j&&a?"ring-2 ring-primary":""),children:[r&&(0,l.jsx)("img",{src:r,alt:e.title,onError:e=>{e.currentTarget.style.display="none"},className:"w-full h-40 object-cover"}),(0,l.jsxs)("div",{className:"p-3 flex flex-col gap-2 flex-1",children:[(()=>{let t=e.relative_time||e.date;return(e.source||e.category||t)&&(0,l.jsxs)("p",{className:"text-xs text-muted-foreground flex flex-wrap items-center gap-x-1",children:[e.source&&(0,l.jsx)("span",{children:e.source}),e.category&&(0,l.jsxs)(l.Fragment,{children:[e.source&&(0,l.jsx)("span",{children:"â¢"}),(0,l.jsx)("span",{className:"px-1.5 py-0.5 rounded bg-secondary text-secondary-foreground",children:e.category})]}),t&&(0,l.jsxs)(l.Fragment,{children:[(e.source||e.category)&&(0,l.jsx)("span",{children:"â¢"}),(0,l.jsx)("span",{children:t})]})]})})(),(0,l.jsx)("h4",{className:"font-semibold text-sm line-clamp-2",children:e.title}),e.description&&(0,l.jsx)("p",{className:"text-xs text-muted-foreground line-clamp-2",children:e.description}),"building"===j?(0,l.jsxs)("label",{className:"flex items-center gap-2 text-xs mt-auto cursor-pointer select-none",children:[(0,l.jsx)("input",{type:"checkbox",checked:a,onChange:()=>{var t;return t=e.url,void N(e=>{let s=new Set(e);return s.has(t)?s.delete(t):s.add(t),s})}}),"Include in Story Frame"]}):null]})]},t)})}),!U&&(0,l.jsx)("div",{className:"flex justify-center my-4",children:(0,l.jsx)(u.$,{variant:"outline",size:"sm",onClick:()=>Y(I+1),disabled:B,children:B?"Loadingâ¦":"Load more"})})]})]})}let g={guid:function(e){let t="",s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",l=s.length,r=0;for(;r<10;)t+=s.charAt(Math.floor(Math.random()*l)),r+=1;return t}(0),title:"",description:"",topics:[],ranks:["","Neutral",""],author:0,author_name:"",articles:[],votes:{},scores:{},status:"draft",updated:!1,searchTerms:[],rankSuggestions:[],selectedArticles:{},comments:{},newComments:{},comment_count:0,tab:"articles",likedBy:[],editing:"all",canEdit:!0,new:!0},f=(0,c.createContext)({currentFrame:g,setFrameState:()=>{}}),j=(0,c.createContext)({framesData:null,setFramesData:()=>{},openFrame:()=>{}});function b(e){let{data:t,query:s=null,list:d=!1}=e,{user:u}=(0,c.useContext)(i.Rs),{search:m}=(0,c.useContext)(i.o7),[x,g]=(0,c.useState)({articles:t.articles,frames:t.frames,loading:!1,loadingMore:!1,max:t.max,initialLoad:!0,nonce:"",currentFrame:s&&s.slug?s.slug:"",highlightVoteUserId:s&&s.voteUserId?s.voteUserId:"",searchQuery:m.query}),f=async()=>{g(e=>({...e,loadingMore:!0}));let e=await (0,r.A)({token:u.token,offset:Object.keys(x.frames).length,per_page:5,searchQuery:m.query,...s});g(t=>({...t,articles:{...t.articles,...e.articles},frames:{...t.frames,...e.frames},max:e.max,loadingMore:!1}))},b=async()=>{let e={...s,token:u.token,searchQuery:m.query,nonce:!0,slug:m.query?"":null==s?void 0:s.slug},t=await (0,r.A)(e);g(e=>({...e,...t}))};if((0,c.useEffect)(()=>
1{if(x.initialLoad)return void g(e=>({...e,initialLoad:!1}));b()},[u.token,m.query]),(0,c.useEffect)(()=>{let e=e=>{e.state&&e.state.frameSlug?g(t=>({...t,currentFrame:e.state.frameSlug})):g(e=>({...e,currentFrame:""}))};return window.addEventListener("popstate",e),()=>window.removeEventListener("popstate",e)},[]),x.loading)return(0,l.jsx)(a.A,{});let v=x.frames,N=Object.keys(v).length;return(0,l.jsx)(j.Provider,{value:{framesData:x,setFramesData:g,openFrame:(e,t)=>{void 0!==e&&(t=t||"",g(t=>({...t,currentFrame:e})))}},children:(0,l.jsxs)("div",{className:"story-frames min-w-[300px] max-w-screen-lg w-full flex flex-col p-1 items-center",children:[u.token?(0,l.jsx)(o.A,{initialTopics:(null==s?void 0:s.topicId)?[String(s.topicId)]:(null==s?void 0:s.topic)?[s.topic]:void 0}):null,N<1?!(null==s?void 0:s.topic)&&!m.query&&(0,l.jsx)("h3",{className:"text-center",children:"No Story Frames Found"}):(0,l.jsxs)("div",{className:"flex flex-col gap-3 w-full",children:[Object.keys(v).map(e=>{let t=v[e];return(0,l.jsx)(n.default,{list:d,currentFrame:t},e)}),!x.max&&N>1&&(0,l.jsx)("div",{className:"text-center my-7",children:x.loadingMore?(0,l.jsx)(a.A,{}):(0,l.jsx)("button",{onClick:f,children:"Load More"})})]}),(null==s?void 0:s.topic)?(0,l.jsx)(h,{topic:s.topic,topicId:s.topicId,topicLabel:s.topicLabel,hasFrames:N>0}):m.query?(0,l.jsx)(p,{query:m.query,hasFrames:N>0}):null]})})}},63523:(e,t,s)=>{"use strict";s.d(t,{default:()=>th});var l=s(95155),r=s(12115),a=s(18955),n=s(42409),i=s(60353),o=s(61543),c=s(5379);function d(){let{topics:e,setTopicsData:t}=(0,r.useContext)(n.U5),{currentFrame:s,setFrameState:a}=(0,r.useContext)(i.t),{theme:d}=(0,c.D)(),u="topics"==s.editing||"all"==s.editing;if((0,r.useEffect)(()=>{if(!e||!s.topics||e.max)return;let l=s.topics.filter(t=>!e.choices.some(e=>e.id===t));l.length>0&&fetch("".concat("https://api.sociallibra.com","/wp-json/wp/v2/categories?include=").concat(l.join(","))).then(e=>e.json()).then(e=>{if(!e.length)return;let s=e.map(e=>({label:e.name,value:e.slug,id:e.id}));if(void 0===t)return void console.error("setTopicsData is undefined. Ensure TopicsContext is properly initialized.");t(e=>{let t=s.filter(t=>!e.choices.some(e=>e.id===t.id));return{...e,choices:[...e.choices,...t],max:t.length<15}})})},[e,s.topics,t]),!e.choices)return(0,l.jsx)("p",{children:"Loading..."});let m=e.choices.map(e=>({label:e.label,value:e.id?e.id.toString():e.value})),x=s.topics.map(e=>{var t;return{label:(null==(t=m.find(t=>t.value===e.toString()))?void 0:t.label)||e,value:e.toString()}}),h=x.filter(e=>isNaN(Number(e.label))).map(e=>e.label);if(s.new&&!s.title)return null;let p=h.join(", ");return u?(0,l.jsx)("div",{className:"flex flex-col",children:(0,l.jsxs)("label",{className:"w-full",children:[(0,l.jsx)("span",{className:"block mb-2",children:"Topics:"}),(0,l.jsx)(o.Ay,{className:"z-[1100] sl-select-container",classNamePrefix:"sl-select",closeMenuOnSelect:!0,value:x,onChange:e=>{e.some(e=>"__load_more__"===e.value)||a(t=>({...t,topics:e.map(e=>e.value),rssLoaded:!1,updated:!0}))},isClearable:!0,isSearchable:!0,placeholder:"Select Topics...",menuPortalTarget:"undefined"!=typeof document?document.body:null,styles:{menuPortal:e=>({...e,zIndex:9999})},options:m,isMulti:!0})]})}):(0,l.jsx)(l.Fragment,{children:e&&(0,l.jsxs)("p",{onClick:()=>{s.canEdit&&a(e=>({...e,editing:"topics"}))},children:["Topics: ",p||"No topics"]})})}var u=s(62666);function m(){let{currentFrame:e,setFrameState:t}=(0,r.useContext)(i.t),[s,a]=(0,r.useState)(""),n="search-terms"==e.editing||"all"==e.editing,o=e=>{t(t=>({...t,searchTerms:e.map(e=>e.value),rssLoaded:!1}))},c=e.searchTerms.map(e=>({label:e,value:e}));return n?(0,l.jsxs)("label",{className:"w-full",children:["RSS Search Terms:",(0,l.jsx)(u.A,{className:"z-[1100] sl-select-container",classNamePrefix:"sl-select",components:{DropdownIndicator:null},inputValue:s,isClearable:!0,closeMenuOnSelect:!1,value:c,menuIsOpen:!1,onChange:o,onInputChange:e=>a(e),onKeyDown:e=>{if(s)switch(e.key){case"Enter":case"Tab":let t;o([...c,{label:t=s,value:t}]),a(""),e.preventDefault()}},menuPortalTarget:document.body,placeholder:"Type your search terms and press enter...",styles:{menuPortal:e=>({...e,zIndex:9999})},isMulti:!0})]}):(0,l.jsx)(l.Fragment,{children:e.searchTerms.length?(0,l.jsxs)("p",{children:["Search Terms: ",e.searchTerms.join(", ")
1]}):null})}var x=s(36230);function h(e){let{className:t,value:s,onChange:a,suggestions:n,placeholder:i}=e,[o,c]=(0,r.useState)(!1),d=(0,r.useRef)(null);return(0,r.useEffect)(()=>{if(o){var e;null==d||null==(e=d.current)||e.focus()}},[o,s]),(0,l.jsx)("div",{className:"relative",children:(0,l.jsxs)(x.AM,{open:o,onOpenChange:e=>{e||c(!1)},children:[(0,l.jsx)(x.dT,{asChild:!0,children:(0,l.jsx)("textarea",{ref:d,maxLength:30,className:t,onClick:()=>c(!0),placeholder:i,onChange:e=>a(e.target.value),value:s})}),n&&(0,l.jsx)(x.hl,{onFocusOutside:e=>{e.preventDefault(),e.stopPropagation(),d.current&&!e.currentTarget.contains(d.current)&&c(!1)},onOpenAutoFocus:e=>{var t;e.preventDefault(),e.stopPropagation(),null==d||null==(t=d.current)||t.focus()},className:"bg-background w-fit",children:(0,l.jsx)("ul",{className:"divide-y divide-slate-200 w-fit",children:("string"==typeof n?JSON.parse(n):n).map((e,t)=>(0,l.jsx)("option",{className:"p-1 bg-background hover:bg-accent",onClick:()=>{a(e)},children:e},"".concat(e,"-").concat(t)))})})]})})}var p=s(25016),g=s(98128),f=s(68425),j=s(47734),b=s(30757),v=s(26991),N=s(23508),w=s(7620);let y={light:"",dark:".dark"},k=r.createContext(null);function C(){let e=r.useContext(k);if(!e)throw Error("useChart must be used within a <ChartContainer />");return e}let S=r.forwardRef((e,t)=>{let{id:s,className:a,children:n,config:i,...o}=e,c=r.useId(),d="chart-".concat(s||c.replace(/:/g,""));return(0,l.jsx)(k.Provider,{value:{config:i},children:(0,l.jsxs)("div",{"data-chart":d,ref:t,className:(0,p.cn)("flex aspect-video justify-center text-xs [&_.recharts-cartesian-axis-tick_text]:fill-muted-foreground [&_.recharts-cartesian-grid_line[stroke='#ccc']]:stroke-border/50 [&_.recharts-curve.recharts-tooltip-cursor]:stroke-border [&_.recharts-dot[stroke='#fff']]:stroke-transparent [&_.recharts-layer]:outline-none [&_.recharts-polar-grid_[stroke='#ccc']]:stroke-border [&_.recharts-radial-bar-background-sector]:fill-muted [&_.recharts-rectangle.recharts-tooltip-cursor]:fill-muted [&_.recharts-reference-line_[stroke='#ccc']]:stroke-border [&_.recharts-sector[stroke='#fff']]:stroke-transparent [&_.recharts-sector]:outline-none [&_.recharts-surface]:outline-none",a),...o,children:[(0,l.jsx)(A,{id:d,config:i}),(0,l.jsx)(v.u,{children:n})]})})});S.displayName="Chart";let A=e=>{let{id:t,config:s}=e,r=Object.entries(s).filter(e=>{let[,t]=e;return t.theme||t.color});return r.length?(0,l.jsx)("style",{dangerouslySetInnerHTML:{__html:Object.entries(y).map(e=>{let[s,l]=e;return"\n".concat(l," [data-chart=").concat(t,"] {\n").concat(r.map(e=>{var t;let[l,r]=e,a=(null==(t=r.theme)?void 0:t[s])||r.color;return a?" --color-".concat(l,": ").concat(a,";"):null}).join("\n"),"\n}\n")}).join("\n")}}):null},_=N.m,F=r.forwardRef((e,t)=>{let{active:s,payload:a,className:n,indicator:i="dot",hideLabel:o=!1,hideIndicator:c=!1,label:d,labelFormatter:u,labelClassName:m,formatter:x,color:h,nameKey:g,labelKey:f}=e,{config:j}=C(),b=r.useMemo(()=>{var e;if(o||!(null==a?void 0:a.length))return null;let[t]=a,s="".concat(f||(null==t?void 0:t.dataKey)||(null==t?void 0:t.name)||"value"),r=T(j,t,s),n=f||"string"!=typeof d?null==r?void 0:r.label:(null==(e=j[d])?void 0:e.label)||d;return u?(0,l.jsx)("div",{className:(0,p.cn)("font-medium",m),children:u(n,a)}):n?(0,l.jsx)("div",{className:(0,p.cn)("font-medium",m),children:n}):null},[d,u,a,o,m,j,f]);if(!s||!(null==a?void 0:a.length))return null;let v=1===a.length&&"dot"!==i;return(0,l.jsxs)("div",{ref:t,className:(0,p.cn)("grid min-w-[8rem] items-start gap-1.5 rounded-lg border border-border/50 bg-background px-2.5 py-1.5 text-xs shadow-xl",n),children:[v?null:b,(0,l.jsx)("div",{className:"grid gap-1.5",children:a.map((e,t)=>{let s="".concat(g||e.name||e.dataKey||"value"),r=T(j,e,s),a=h||e.payload.fill||e.color;return(0,l.jsx)("div",{className:(0,p.cn)("flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5 [&>svg]:text-muted-foreground","dot"===i&&"items-center"),children:x&&(null==e?void 0:e.value)!==void 0&&e.name?x(e.value,e.name,e,t,e.payload):(0,l.jsxs)(l.Fragment,{children:[(null==r?void 0:r.icon)?(0,l.jsx)(r.icon,{}):!c&&(0,l.jsx)("div",{className:(0,p.cn)("shrink-0 rounded-[2px] border-[--color-border] bg-[--color-bg]",{"h-2.5 w-2.5":"dot"===i,"w-1":"line"===i,"w-0 border-[1.5px] border-dashed bg-transparent":"dashed"===i,"my-0.5":v&&"dashed"===i}),style:{"--color-bg":a,"--color-border":a}}),(0,l.jsxs)("div",{className:(0,p.cn)("flex flex-1 justify-between leading-none",v?"items-end":"items-center"),children:[(0,l.jsxs)("div",{className:"grid gap-1.5",children:[v?b:null,(0,l.jsx)("span",{className:"text-muted-foreground",children:(null==r?void 0:r.label)||e.name})]}),e.value&&(0,l.jsx)("span",{className:"font-mono font-medium tabular-nums text-foreground",children:e.value.toLocaleStr
1ing()})]})]})},e.dataKey)})})]})});function T(e,t,s){if("object"!=typeof t||null===t)return;let l="payload"in t&&"object"==typeof t.payload&&null!==t.payload?t.payload:void 0,r=s;return s in t&&"string"==typeof t[s]?r=t[s]:l&&s in l&&"string"==typeof l[s]&&(r=l[s]),r in e?e[r]:e[s]}function E(){let{currentFrame:e}=(0,r.useContext)(i.t),{currentArticle:t}=(0,r.useContext)(eN),s=e.votes["sfa_"+t.id]||null,a={};e.scores["sfa_"+t.id].votes;let n=e.scores["sfa_"+t.id].score||0,o=[],c={},d={left:[{label:"81 to 100",range:"-100--81",min:-100,max:-81},{label:"61 to 80",range:"-80--61",min:-80,max:-61},{label:"41 to 60",range:"-60--41",min:-60,max:-41},{label:"21 to 40",range:"-40--21",min:-40,max:-21}],center:[{label:"1-20 "+e.ranks[0],range:"-20--1",min:-20,max:-1},{label:e.ranks[1],range:"0",min:0,max:0},{label:"1-20 "+e.ranks[2],range:"1-20",min:1,max:20}],right:[{label:"21 to 40",range:"21-40",min:21,max:40},{label:"41 to 60",range:"41-60",min:41,max:60},{label:"61 to 80",range:"61-80",min:61,max:80},{label:"81 to 100",range:"81-100",min:81,max:100}]};return e.ranks.map((e,t)=>{let l=e.toLowerCase().replace(/\s+/g,"_");a[l]=2==t?"#f96f72":0==t?"#60a5fa":"#e3e3e3";let r=0;for(let e in s)s[e].score>20&&2==t&&(d.right.map(t=>{void 0==c[l]&&(c[l]={}),s[e].score>=t.min&&s[e].score<=t.max&&(c[l][t.range]?c[l][t.range].count++:(c[l]=c[l]||{},c[l][t.range]={count:1,label:t.label}))}),r++),s[e].score<-20&&0==t&&(d.left.map(t=>{void 0==c[l]&&(c[l]={}),s[e].score>=t.min&&s[e].score<=t.max&&(c[l][t.range]?c[l][t.range].count++:(c[l]=c[l]||{},c[l][t.range]={count:1,label:t.label}))}),r++),s[e].score>-20&&s[e].score<20&&1==t&&(d.center.map(t=>{void 0==c[l]&&(c[l]={}),s[e].score>=t.min&&s[e].score<=t.max&&(c[l][t.range]?c[l][t.range].count++:(c[l]=c[l]||{},c[l][t.range]={count:1,label:t.label}))}),r++);o.push({rank:e,[l]:r})}),(0,l.jsx)(S,{config:{},className:"min-h-[200px] w-full",children:(0,l.jsxs)(g.E,{accessibilityLayer:!0,data:o,children:[(0,l.jsx)(f.d,{vertical:!1}),(0,l.jsx)(j.W,{dataKey:"rank",tickLine:!1,tickMargin:10,axisLine:!1}),(0,l.jsx)(_,{allowEscapeViewBox:{x:!0,y:!0},defaultIndex:n>20?2:n<-20?0:1,content:(0,l.jsx)(F,{formatter:(e,t,s,r)=>(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)("div",{className:"h-2.5 w-2.5 shrink-0 rounded-[2px] bg-(--color-bg)",style:{"--color-bg":"var(--color-".concat(t,")")}}),c[t]&&Object.keys(c[t]).map(e=>(0,l.jsxs)("div",{className:"text-foreground mt-1.5 flex basis-full items-center border-t pt-1.5 text-xs font-medium",children:[c[t][e].label,(0,l.jsxs)("div",{className:"text-foreground ms-auto flex items-baseline gap-0.5 font-mono font-medium tabular-nums",children:[c[t][e].count,(0,l.jsx)("span",{className:"text-muted-foreground font-normal",children:1==c[t][e].count?"vote":"votes"})]})]},e)),(0,l.jsxs)("div",{className:"text-foreground mt-1.5 flex basis-full items-center border-t pt-1.5 text-xs font-medium",children:["Total",(0,l.jsxs)("div",{className:"text-foreground ms-auto flex items-baseline gap-0.5 font-mono font-medium tabular-nums",children:[e,(0,l.jsx)("span",{className:"text-muted-foreground font-normal",children:1==e?"vote":"votes"})]})]})]})})}),e.ranks.map((e,t)=>{let s=e.toLowerCase().replace(/\s+/g,"_");return(0,l.jsx)(b.y,{dataKey:s,fill:a[s],radius:4,stackId:"a"},s)})]})})}function L(e){var t,s,a;let{textClass:n=""}=e,{currentArticle:o}=(0,r.useContext)(eN),{currentFrame:c}=(0,r.useContext)(i.t),d="sfa_"+(o.id||o.url),u=null!=(a=null==(t=c.scores[d])?void 0:t.score)?a:0,m=(null==(s=c.scores[d])?void 0:s.votes)?c.ranks[u>0?2:u<0?0:1]:"",h=Math.abs(u),g=m.length>10?m.slice(0,10)+"...":m;return(0,l.jsx)(x.AM,{children:(0,l.jsx)(x.Wv,{className:"w-full",children:(0,l.jsxs)("div",{className:"relative bg-background text-center text-foreground w-full m-auto overflow-hidden border border-input",children:[(0,l.jsx)("div",{className:"absolute top-0 bottom-0",style:{background:u>0?"#DC262680":u<0?"#3B82F680":"transparent",width:"".concat(h+10,"%"),left:u>0?"auto":0,right:u<0?"auto":0}}),(0,l.jsx)("p",{title:m,className:(0,p.cn)("m-1 z-auto font-bold shadow-foreground relative",n),children:0==u?g:"".concat(h,"% ").concat(g)}),(0,l.jsx)(x.hl,{style:{width:"350px"},className:"p-2",children:(0,l.jsx)(E,{})})]})})})}F.displayName="ChartTooltip",w.s,r.forwardRef((e,t)=>
1{let{className:s,hideIcon:r=!1,payload:a,verticalAlign:n="bottom",nameKey:i}=e,{config:o}=C();return(null==a?void 0:a.length)?(0,l.jsx)("div",{ref:t,className:(0,p.cn)("flex items-center justify-center gap-4","top"===n?"pb-3":"pt-3",s),children:a.map(e=>{let t="".concat(i||e.dataKey||"value"),s=T(o,e,t);return(0,l.jsxs)("div",{className:(0,p.cn)("flex items-center gap-1.5 [&>svg]:h-3 [&>svg]:w-3 [&>svg]:text-muted-foreground"),children:[(null==s?void 0:s.icon)&&!r?(0,l.jsx)(s.icon,{}):(0,l.jsx)("div",{className:"h-2 w-2 shrink-0 rounded-[2px]",style:{backgroundColor:e.color}}),null==s?void 0:s.label]},e.value)})}):null}).displayName="ChartLegend",s(36021);let O=function(e){let{onChange:t,value:s}=e,{currentFrame:a}=(0,r.useContext)(i.t),[n,o]=(0,r.useState)(0),c=(0,r.useRef)(null);(0,r.useEffect)(()=>{c.current&&c.current.focus()},[c.current]);let d=e=>{let s=e.target.value;-1==n&&(s=-1*Math.abs(s)),s>100&&(s=100),s<-100&&(s=-100),t(s)},u=s<0?"blue":s>0?"red":"black",m=a.ranks;if(m.length<2)return(0,l.jsx)("p",{children:"The frame needs at least 2 ranks"});let x=s>0?m[2]:s<0?m[0]:m[1];return(0,l.jsxs)("div",{children:[(0,l.jsx)("input",{ref:c,type:"range",min:"-100",max:"100",value:s,onChange:e=>{let s=e.target.value;s>0&&o(1),s<0&&o(-1),t(s)},className:"shadow-foreground border border-foreground slider appearance-none bg-gradient-to-r from-blue-500 via-trans
1parent to-red-600 focus:outline-none focus:ring-2 focus:ring-offset-2 w-full",style:{backgroundSize:"500%",backgroundPosition:"".concat(50+s/2,"% 50%"),WebkitAppearance:"none",cursor:"pointer"}}),(0,l.jsx)("div",{className:"flex flex-row justify-stretch",children:m&&m.map((e,r)=>(0,l.jsxs)("p",{className:(0,p.cn)("text-center w-1/3 text-sm sm:text-md",x==e?"text-"+u+"-500 font-bold":"text-foreground"),children:[x==e&&1!=r?(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)("input",{type:"number",className:"bg-transparent text-end border-transparent focus-visible:border-transparent w-9 no-num-controls -ms-2",min:"0",max:"100",value:Math.abs(s),onChange:d}),(0,l.jsx)("span",{children:"% "})]}):null,(0,l.jsx)("span",{className:(0,p.cn)("cursor-pointer text-center"),onClick:()=>{x!=e&&(c.current&&c.current.focus(),t(1==r?0:2==r?70:-70))},children:e})]},r))})]})};var P=s(1399),z=s(64133),R=s(32382),D=s(42475),I=s(17181),M=s(33431),B=s(26125);function V(e){let{src:t,alt:s}=e,[a,n]=(0,r.useState)("loading");return(0,l.jsxs)("div",{className:"relative w-full aspect-[3/2] rounded-md overflow-hidden bg-muted",children:["loading"===a&&(0,l.jsx)("div",{className:"absolute inset-0 flex items-center justify-center animate-pulse bg-muted",children:(0,l.jsx)(z.A,{})}),"error"===a&&(0,l.jsx)("div",{className:"absolute inset-0 flex items-center justify-center text-xs text-muted-foreground",children:"Preview unavailable"}),(0,l.jsx)("img",{src:t,alt:s,onLoad:()=>n("loaded"),onError:()=>n("error"),className:(0,p.cn)("w-full h-full object-cover","loaded"!==a&&"opacity-0")})]})}function U(e){let{title:t,imageUrl:s,shareUrl:r,onClose:a}=e;return(0,l.jsx)(R.A,{className:"w-full sm:w-1/3",onClose:a,children:(0,l.jsxs)("div",{className:"p-4 flex flex-col gap-3",children:[(0,l.jsxs)("h3",{className:"text-2xl font-bold",children:["Share ",(0,l.jsx)(I.A,{className:"inline"})]}),(0,l.jsx)(V,{src:s,alt:"Share preview"}),(0,l.jsx)("h4",{className:"text-lg font-bold",children:t}),(0,l.jsx)("button",{className:"btn-primary",onClick:()=>window.navigator.share({title:t,url:r}),children:"Share Now"})]})})}function $(e){let{setShare:t}=e;return(0,l.jsx)("button",{onClick:()=>{t(!0)},className:"w-full block",children:(0,l.jsx)(I.A,{className:"inline"})})}function Y(e){let{setShare:t}=e,{currentFrame:s}=(0,r.useContext)(i.t),a="https://www.sociallibra.com//api/og/?frame="+s.id,n="".concat("https://www.sociallibra.com/","/story-frame/").concat(s.slug);return(0,l.jsx)(R.A,{className:"w-full sm:w-1/3",onClose:()=>t(!1),children:(0,l.jsxs)("div",{className:"p-4 flex flex-col gap-3",children:[(0,l.jsxs)("h3",{className:"text-2xl font-bold",children:["Share this frame ",(0,l.jsx)(I.A,{className:"inline"})]}),(0,l.jsx)(V,{src:a,alt:"Frame URL"}),(0,l.jsx)("h4",{className:"text-lg font-bold",children:s.title}),(0,l.jsx)("button",{className:"btn-primary",onClick:()=>{window.navigator.share({title:s.title,url:n})},children:"Share Now"})]})})}function K(e){let{onClose:t,className:s="",minimal:o=!1,scoreOnly:c=!1,withSave:d=!0}=e,u=(0,a.c)("VoteForm"),{user:m,setCurrentUser:x}=(0,r.useContext)(n.Rs),{currentFrame:h,setFrameState:g}=(0,r.useContext)(i.t),{currentArticle:f}=(0,r.useContext)(eN),j=f.id||f.guid,b=j?"sfa_"+j:"newArticle",v="frame_"+h.id,N=h.votes&&h.votes[b]?h.votes[b]["user_"+m.id]:null,w=m.voting&&m.voting[v+"_"+b]?m.voting[v+"_"+b]:{score:N?N.score:null,comment:N?N.comment:"",loading:!1,error:"",success:"",public:!N||N.public,changed:!1},y={loading:(null==w?void 0:w.loading)||!1,score:(null==w?void 0:w.score)!=null?w.score:0,comment:(null==w?void 0:w.comment)||"",public:(null==w?void 0:w.public)!==!1&&(null==w?void 0:w.public)!==0&&(null==w?void 0:w.public)!=="0",changed:(null==w?void 0:w.changed)||!1},[k,C]=(0,r.useState)({loginForm:!1,thanks:!1,sharing:!1}),{loading:S,score:A,comment:_}=y,F=y.public,T="".concat("https://www.sociallibra.com/","/story-frame/").concat(h.slug,"/articles/").concat(j,"/vote/").concat(m.id),E="".concat("https://www.sociallibra.com/","/api/og?frame=").concat(h.id,"&article=").concat(j,"&user=").concat(m.id),L=u("shareTitle",{title:f.title}),V=()=>C(e=>({...e,sharing:!0})),$=e=>{void 0!==x&&x(t=>{let s=t.voting&&t.voting[v+"_"+b]?t.voting[v+"_"+b]:{...N,loading:!1,error:"",success:"",score:0,comment:"",public:!0};return{...t,voting:{...t.voting,[v+"_"+b]:{...s,score:void 0!==e.score?Number(e.score)||0:s.score||0,comment:void 0!==e.comment?e.comment:s.comment||"",public:void 0!==e.public?e.public:!1!==s.public&&0!==s.public&&"0"!==s.public,changed:!0}}}})};return c?(0,l.jsx)(O,{value:A||0,onChange:()=>{}}):(0,l.jsxs)("div",{className:s,children:[(0,l.jsxs)("div",{onClick:e=>{m&&m.id||(e.preventDefault(),C(e=>({...e,loginForm:!0})))},className:(0,p.cn)("self-center m-auto"),children:[(0,l.jsxs)("div",{className:"mb-2 w-full",children:[(0,l.jsx)("label",{className:(0,p.cn)("block font-bold mb-2",o?"sr-only":""),children:u("yourVote")}),(0,l.jsx)(O,{value:A||0,onChange:e=>$({score:e})})]}),d&&!S&&(0,l.jsxs)("div",{className:"flex flex-row items-center gap-2 mb-3",children:[(0,l.jsx)("input",{id:"public",type:"checkbox",checked:F,onChange:e=>$({public:e.target.checked})}),(0,l.jsx)("label",{htmlFor:"public",className:"text-sm font-medium cursor-pointer",children:u("makeVotePublic")})]}),y.changed&&d&&!S&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)("div",{className:"mb-3",children:[(0,l.jsxs)("label",{htmlFor:"comment",className:(0,p.cn)("block font-bold mb-1 text-sm",o?"sr-only":""),children:[u("comment")," ",(0,l.jsx)("span",{className:"font-normal text-muted-foreground",children:u("optional")})]}),(0,l.jsx)(B.T,{id:"comment",name:"comment",value:_,placeholder:u("explainYourVote"),onChange:e=>$({comment:e.target.value})})]}),(0,l.jsxs)("div",{className:"flex justify-end gap-2",children:[t&&(0,l.jsx)(M.$,{variant:"outline",onClick:t,children:u("cancel")}),(0,l.jsx)(M.$,{type:"submit",onClick:()=>
1{if(!m||!m.id)return void C(e=>({...e,loginForm:!0}));void 0!==x&&(x(e=>({...e,voting:{...e.voting,[v+"_"+b]:{...e.voting?e.voting[v+"_"+b]:{},score:A,comment:_,public:F,changed:!1}}})),t&&t(),g(e=>{var t,s,l,r;let a=null!=(r=null==(s=e.scores)||null==(t=s[b])?void 0:t.votes)?r:0;(!e.votes[b]||!e.votes[b]["user_"+m.id])&&a++;let n={...e.votes,[b]:{...h.votes[b],["user_"+m.id]:{score:A,comment:_,public:F}}},i=0;Object.keys(n[b]).forEach(e=>{i+=Number(n[b][e].score)}),i/=a;let o=(0,p.z0)(i),c=i>20?2:i<-20?0:1,d=(null==h||null==(l=h.scores[b])?void 0:l.score)||0,u={...e.selectedArticles};return d!=i&&(u[c]=b),{...e,updated:!0,votes:n,selectedArticles:u,selectedRank:c+1,scores:{...e.scores,[b]:{score:o,votes:a,rank:c}}}}),C(e=>({...e,thanks:!0,loginForm:!1})),fetch("".concat("https://api.sociallibra.com/wp-json/social_libra/v2","/article_votes"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(m.token)},body:JSON.stringify({frame:h.id,article:f.id||f,score:A,comment:_,public:F})}).catch(console.error))},className:(0,p.cn)("text-background font-bold py-2 px-4 rounded focus:outline-none",A>20?"bg-red-500 hover:bg-red-700":A<-20?"bg-blue-500 hover:bg-blue-700":"bg-foreground hover:bg-foreground
1/80"),children:u("vote")})]})]}),!y.changed&&N&&d&&(0,l.jsx)("div",{className:"flex justify-end mt-1",children:(0,l.jsxs)(M.$,{variant:"outline",size:"sm",onClick:V,title:u("shareYourVote"),children:[(0,l.jsx)(I.A,{className:"w-4 h-4 me-1"}),u("share")]})}),S&&(0,l.jsx)(z.A,{})]}),k.loginForm&&(0,l.jsxs)(R.A,{className:"sm:w-3/5 p-2",onClose:()=>C(e=>({...e,loginForm:!1})),children:[(0,l.jsx)("h4",{children:u("signInToVote")}),(0,l.jsx)(P.default,{})]}),k.thanks&&(0,l.jsx)(D.lG,{open:k.thanks,onOpenChange:e=>C(t=>({...t,thanks:e})),children:(0,l.jsxs)(D.Cf,{children:[(0,l.jsx)(D.c7,{children:(0,l.jsx)(D.L3,{children:u("thankYouTitle")})}),(0,l.jsx)("p",{className:"text-sm text-muted-foreground",children:u("voteSubmitted",{isPublic:F?"yes":"no",hasComment:_?"yes":"no"})}),(0,l.jsxs)("div",{className:"flex gap-2 justify-end mt-4",children:[(0,l.jsxs)(M.$,{variant:"outline",onClick:V,children:[(0,l.jsx)(I.A,{className:"w-4 h-4 me-1"}),u("shareYourVote")]}),(0,l.jsx)(M.$,{onClick:()=>C(e=>({...e,thanks:!1})),children:u("done")})]})]})}),k.sharing&&(0,l.jsx)(U,{title:L,imageUrl:E,shareUrl:T,onClose:()=>C(e=>({...e,sharing:!1}))})]})}var J=s(87513),Q=s(37772),W=s(37135),q=s(96052),H=s(83161);let G=e=>{let{shouldScaleBackground:t=!0,...s}=e;return(0,l.jsx)(H._s.Root,{shouldScaleBackground:t,...s})};G.displayName="Drawer";let X=H._s.Trigger,Z=H._s.Portal,ee=H._s.Close,et=r.forwardRef((e,t)=>{let{className:s,...r}=e;return(0,l.jsx)(H._s.Overlay,{ref:t,className:(0,p.cn)("fixed inset-0 z-50 bg-foreground
1/80 backdrop-blur-sm",s),...r})});et.displayName=H._s.Overlay.displayName;let es=r.forwardRef((e,t)=>{let{className:s,children:r,...a}=e;return(0,l.jsxs)(Z,{children:[(0,l.jsx)(et,{}),(0,l.jsxs)(H._s.Content,{ref:t,className:(0,p.cn)("fixed inset-x-0 bottom-0 z-[9998] mt-24 flex h-auto flex-col rounded-t-[10px] border bg-background",s),...a,children:[(0,l.jsx)("div",{className:"mx-auto mt-4 h-2 w-[100px] rounded-full bg-muted"}),r]})]})});es.displayName="DrawerContent";let el=e=>{let{className:t,...s}=e;return(0,l.jsx)("div",{className:(0,p.cn)("grid gap-1.5 p-4 text-center sm:text-start",t),...s})};el.displayName="DrawerHeader";let er=e=>{let{className:t,...s}=e;return(0,l.jsx)("div",{className:(0,p.cn)("mt-auto flex flex-col gap-2 p-4",t),...s})};er.displayName="DrawerFooter";let ea=r.forwardRef((e,t)=>{let{className:s,...r}=e;return(0,l.jsx)(H._s.Title,{ref:t,className:(0,p.cn)("text-lg font-semibold leading-none tracking-tight",s),...r})});ea.displayName=H._s.Title.displayName,r.forwardRef((e,t)=>{let{className:s,...r}=e;return(0,l.jsx)(H._s.Description,{ref:t,className:(0,p.cn)("text-sm text-muted-foreground",s),...r})}).displayName=H._s.Description.displayName;var en=s(18720);let ei=[{value:"Out of context",key:"outOfContext"},{value:"Irrelevant to the topic",key:"irrelevant"},{value:"Not appropriate",key:"notAppropriate"},{value:"Misleading or false information",key:"misleading"},{value:"Clickbait or deceptive title",key:"clickbait"},{value:"Low-quality or spam-like content",key:"lowQuality"},{value:"Offensive or harmful language",key:"offensive"},{value:"Duplicate or reposted content",key:"duplicate"},{value:"Copyright or attribution issue",key:"copyright"},{value:"Other",key:"other"}],eo=()=>{let e=(0,a.c)("ArticleActions"),t=(0,a.c)("ArticleActions.reason"),{currentArticle:s}=(0,r.useContext)(eN),{user:o}=(0,r.useContext)(n.Rs),{currentFrame:c,setFrameState:d}=(0,r.useContext)(i.t),[u,m]=(0,r.useState)({actions:!1,sharing:!1,editing:!1,reporting:!1}),h=(0,r.useRef)(null),{actions:p,editing:g,sharing:f,reporting:j}=u,b="sfa_"+(s.id||s.url),v=async()=>{confirm(e("confirmDelete"))&&(d(e=>{let t=[...e.articles].filter(e=>e!=b);return{...e,updated:!0,articles:t}}),await fetch("".concat("https://api.sociallibra.com/wp-json/social_libra/v2","/articles/").concat(s.id),{method:"DELETE",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(o.token)}}).then(e=>e.json()).then(e=>e).catch(e=>!1))},N="".concat("https://www.sociallibra.com/","/story-frame/").concat(c.slug,"/articles/").concat(s.slug),w=async t=>{t.preventDefault();let l=new FormData(t.currentTarget),r=h.current,a=l.get("report_reason"),n=l.get("details");if(!a)return void alert(e("selectReasonAlert"));try{let t=await fetch("".concat("https://api.sociallibra.com/wp-json/social_libra/v2","/report_article"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({articleId:s.id,reason:a,details:(null==n?void 0:n.trim())||null})}),l=await t.json();if(!t.ok)throw Error((null==l?void 0:l.message)||e("requestFailed"));r&&r.reset(),m(e=>({...e,reporting:!1})),en.toast.success(l.message||e("reportSubmitted"))}catch(e){en.toast.error(e.message)}},y="".concat("https://www.sociallibra.com/","/api/og?frame=").concat(c.id,"&article=").concat(s.id||s.guid);return(0,l.jsxs)("div",{className:"article-actions gap-2 flex justify-end absolute top-5 end-5",children:[(0,l.jsx)("button",{onClick:()=>m(e=>({...e,sharing:!0})),children:(0,l.jsx)(I.A,{size:18})}),f&&(0,l.jsx)(U,{title:s.title||c.title,imageUrl:y,shareUrl:N,onClose:()=>m(e=>({...e,sharing:!1}))}),(0,l.jsxs)(x.AM,{open:p,onOpenChange:e=>m(t=>({...t,actions:e})),children:[(0,l.jsx)(x.Wv,{children:(0,l.jsx)(Q.A,{})}),(0,l.jsxs)(x.hl,{className:"bg-background shadow-lg rounded-lg w-auto p-0",children:[o.id==c.author&&(0,l.jsx)(l.Fragment,{children:s.id&&(o.id==c.author||s.author==o.id)&&(0,l.jsxs)("button",{className:"hover:bg-red-100 rounded-lg hover:text-black p-1 w-full",onClick:e=>{e.stopPropagation(),v()},children:[e("delete")," ",(0,l.jsx)(W.A,{size:18,className:"text-red-400 inline"})]})}),(0,l.jsxs)("button",{className:"hover:bg-green-100 rounded-lg hover:text-black p-1 w-full",onClick:e=>{e.stopPropagation(),m(e=>({...e,reporting:!0}))},children:[e("report")," ",(0,l.jsx)(q.A,{size:18,className:"inline"})]})]})]}),(0,l.jsx)(G,{open:j,onOpenChange:e=>{e||m(t=>({...t,reporting:e}))},children:(0,l.jsxs)(es,{className:"max-h-screen justify-center items-center",children:[(0,l.jsx)(el,{className:"flex flex-col sm:flex-row h-64 sm:h-32 p-1 justify-center",children:(0,l.jsx)(ea,{children:e("reportTitle",{title:s.title})})}),(0,l.jsxs)("form",{ref:h,onSubmit:w,className:"space-y-4 px-4 pb-6 md:w-1/3",children:[(0,l.jsxs)("fieldset",{className:"space-y-2",children:[(0,l.jsx)("legend",{className:"text-sm font-medium",children:e("reasonForReport")}),ei.map(e=>{let{value:s,key:r}=e;return(0,l.jsxs)("label",{className:"flex items-center gap-2 text-sm",children:[(0,l.jsx)("input",{type:"radio",name:"report_reason",value:s,className:"accent-primary"}),t(r)]},s)})]}),(0,l.jsxs)("div",{className:"space-y-1",children:[(0,l.jsx)("label",{htmlFor:"details",className:"text-sm font-medium",children:e("additionalDetails")}),(0,l.jsx)("textarea",{id:"details",name:"details",rows:4,placeholder:e("additionalDetailsPlaceholder"),className:"w-full rounded-md border p-2 text-sm"})]}),(0,l.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,l.jsx)("button",{type:"button",className:"btn-secondary",children:e("cancel")}),(0,l.jsx)("button",{type:"submit",className:"btn-primary",children:e("submitReport")})]})]})]})})]})};var ec=s(96354),ed=s(30220),eu=s(72921);function em(){var e;let{currentFrame:t}=(0,r.useContext)(i.t),{currentArticle:s}=(0,r.useContext)(eN),{framesData:a}=(0,r.useContext)(i.m),{user:o}=(0,r.useContext)(n.Rs),c=null==a?void 0:a.highlightVoteUserId,d="sfa_"+(s.id||s.guid),u=Object.entries((null==(e=t.votes)?void 0:e[d])||{}).filter(e=>{let[t,s]=e;return t.startsWith("user_")&&(0,ec.Qz)(s.public)}).map(e=>{let[t,s]=e;return{userId:t.replace("user_",""),score:Number(s.score)||0,comment:s.comment||""}}),[m,x]=(0,r.useState)({});return((0,r.useEffect)(()=>{let e=u.map(e=>e.userId).filter(e=>!m[e]);e.length&&Promise.all(e.map(e=>(0,ed.A)({id:Number(e),token:o.token,returnSingle:!0}))).then(t=>{x(s=>{let l={...s};return t.forEach((t,s)=>{let r=t?t.choices[0]:null;r&&(l[e[s]]=r)}),l})})},[d,u.length]),u.length)?(0,l.jsx)("div",{className:"flex flex-col gap-2",children:u.map(e=>{let s=m[e.userId],r=e.score>20?2:e.score<-20?0:1,a=t.ranks[r]||"",n=(0,p.cn)("inline-block text-xs font-bold px-2 py-1 rounded-b-lg text-background",r<1?"bg-blue-400":r>1?"bg-red-400":"bg-secondary text-foreground"),i=c===e.userId;return(0,l.jsxs)("div",{className:(0,p.cn)("flex flex-col gap-2 p-3 border rounded-md bg-background",i?"border-foreground shadow-secondary shadow-lg":""),children:[(0,l.jsxs)("div",{className:"flex items-center gap-2",children:[(0,l.jsx)(eu.A,{user:s||{},width:28,height:28}),(0,l.jsx)("span",{className:"font-bold text-sm",children:(null==s?void 0:s.name)||"A Social Libra voter"}),(0,l.jsx)("span",{className:n,children:0==e.score?a:"".concat(Math.abs(e.score),"% ").concat(a)})]}),e.comment?(0,l.jsxs)("p",{className:"text-sm",children:["â",e.comment,"â"]}):null]},e.userId)})}):(0,l.jsx)("p",{className:"text-sm text-muted-foreground p-1",children:"No public votes for this article yet."})}var ex=s(46980),eh=s.n(ex);
1function ep(e){let{content:t="",className:s=""}=e;if(!t)return null;let r=eh().sanitize(t);return(0,l.jsx)("div",{className:s,dangerouslySetInnerHTML:{__html:r}})}var eg=s(59034);function ef(e){let{className:t,children:s,...r}=e;return(0,l.jsxs)(eg.bL,{"data-slot":"scroll-area",className:(0,p.cn)("relative",t),...r,children:[(0,l.jsx)(eg.LM,{"data-slot":"scroll-area-viewport",className:"focus-visible:ring-ring/50 size-full rounded-[inherit] transition-[color,box-shadow] outline-none focus-visible:ring-[3px] focus-visible:outline-1",children:s}),(0,l.jsx)(ej,{}),(0,l.jsx)(eg.OK,{})]})}function ej(e){let{className:t,orientation:s="vertical",...r}=e;return(0,l.jsx)(eg.VM,{"data-slot":"scroll-area-scrollbar","data-orientation":s,orientation:s,className:(0,p.cn)("data-horizontal:h-2.5 data-horizontal:flex-col data-horizontal:border-t data-horizontal:border-t-transparent data-vertical:h-full data-vertical:w-2.5 data-vertical:border-l data-vertical:border-l-transparent flex touch-none p-px transition-colors select-none",t),...r,children:(0,l.jsx)(eg.lr,{"data-slot":"scroll-area-thumb",className:"rounded-full bg-border relative flex-1"})})}let eb=(0,r.lazy)(()=>Promise.all([s.e(5004),s.e(277),s.e(8562),s.e(8772)]).then(s.bind(s,88772))),ev=(0,r.lazy)(()=>Promise.all([s.e(2614),s.e(4718)]).then(s.bind(s,54718))),eN=(0,r.createContext)({currentArticle:{id:0,title:"",description:"",content:"",source:"",url:"",images:{},type:"original"},setCurrentArticle:()=>{}});function ew(e){var t,s;let{category:o="",article:c,showFull:d=!1,changeArticle:u,className:m}=e,x=(0,a.c)("Votes"),{currentFrame:h,setFrameState:g}=(0,r.useContext)(i.t),{eventsData:f}=(0,r.useContext)(n.Pc),{user:j}=(0,r.useContext)(n.Rs),{framesData:b}=(0,r.useContext)(i.m),v=null==b?void 0:b.highlightVoteUserId,{type:N,title:w,content:y,description:k,source:C,url:S,images:A,isRss:_}=c,F=h.votes?h.votes["sfa_"+c.id]:null,T=h.scores&&(null==(t=h.scores["sfa_"+c.id])?void 0:t.votes)?null==(s=h.scores["sfa_"+c.id])?void 0:s.votes:0;if(F&&F["user_"+j.id]){let e=0|F["user_"+j.id].score;0!=e?"".concat(Math.abs(e),"% ").concat(e<0?h.ranks[0]:h.ranks[2]):h.ranks[1]}let E=c.urlToImage||(null==A?void 0:A.medium)||(null==A?void 0:A.large)||(null==A?void 0:A.thumb)||"/images/default-article.jpg",[O,P]=(0,r.useState)(!1),z=(0,r.useRef)(!1),[R,I]=(0,r.useState)(!1),[M,B]=(0,r.useState)(!1),V=(0,r.useRef)(null);(0,r.useEffect)(()=>{V.current&&B(V.current.scrollHeight>V.current.clientHeight)},[y]),(0,r.useEffect)(()=>{!z.current&&v&&T>0&&(P(!0),z.current=!0)},[v,T]),(0,r.useEffect)(()=>{if(!c.id||!h.slug)return;let e="/story-frame/".concat(h.slug,"/articles/").concat(c.id);window.location.pathname!==e&&window.history.pushState(null,"",e)},[c.id,h.slug]);let U=(e,t)=>{u&&u(s=>{let l={...s.article,[t]:e};return l.updated=!!l.title&&!!l.description&&!!(l.content||"original"!=l.type),{...s,article:l}})},$=w&&!("original"==c.type&&!y);return(0,l.jsx)(eN.Provider,{value:{currentArticle:c},children:(0,l.jsx)("div",{className:(0,p.cn)("px-4 frame-article relative",m),children:(0,l.jsxs)("div",{className:"text-center justify-center p-5",children:[(0,l.jsx)(eo,{}),(0,l.jsxs)("div",{className:"flex flex-col sm:flex-row gap-5",children:[(0,l.jsxs)("div",{className:"flex flex-col gap-2 sm:w-1/3",children:[(0,l.jsx)("img",{width:"200",height:"200",className:"h-32 m-auto object-cover sm:w-full",src:E,alt:w||""}),u&&"original"==N&&(0,l.jsx)(J.A,{uploadFiles:e=>{if(e&&0==e.length)return;let t=URL.createObjectURL(e[0]);t&&u&&u(s=>({...s,article:{...s.article,images:{...s.article.images,medium:t}},files:e}))},placeholder:"Change Image"})]}),(0,l.jsx)("div",{className:"flex flex-col gap-2 sm:w-2/3",children:(0,l.jsx)("h3",{className:"mb-0 text-start w-full text-sm sm:text-lg font-bold ",children:u&&"external"!=N?(0,l.jsxs)("label",{className:"flex flex-col",children:[(0,l.jsx)("span",{className:"text-sm sm:text-lg font-normal",children:"Title"}),(0,l.jsx)("textarea",{rows:2,className:"input-text-type font-bold text-sm sm:text-lg resize-none",placeholder:"Article Title",value:w,onChange:e=>U(e.target.value,"title")})]}):w})})]}),(0,l.jsx)("div",{className:"relative cursor-pointer justify-end flex gap-2",children:C?(0,l.jsx)("p",{className:"w-full text-start text-xs",title:"Source: ".concat(C),children:C}):null}),0!=T&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(L,{}),(0,l.jsxs)(D.lG,{open:O,onOpenChange:P,children:[(0,l.jsx)(D.zM,{asChild:!0,children:(0,l.jsx)("button",{onClick:()=>P(!0),className:"underline text-sm",children:x("count",{count:T})})}),(0,l.jsxs)(D.Cf,{className:"max-w-md max-h-[80vh] overflow-y-auto",children:[(0,l.jsx)(D.c7,{children:(0,l.jsx)(D.L3,{children:"Public Votes"})}),(0,l.jsx)(em,{})]})]})]}),(0,l.jsx)(ef,{className:"",children:(0,l.jsxs)("div",{className:"text-start",children:[u?(0,l.jsxs)("label",{className:"flex flex-col",children:[(0,l.jsx)("span",{className:"text-sm sm:text-lg",children:"Description"}),(0,l.jsx)("textarea",{className:"input-text-type overflow-auto",required:!0,placeholder:"Article Description",value:k,rows:2,onChange:e=>U(e.target.value,"description")})]}):(0,l.jsx)(ep,{content:k}),u&&"original"==N?(0,l.jsxs)("label",{className:"flex flex-col",children:[(0,l.jsx)("span",{className:"text-sm sm:text-lg",children:"Body"}),(0,l.jsx)(r.Suspense,{fallback:(0,l.jsx)("div",{children:"Loading editor..."}),children:(0,l.jsx)(eb,{initialValue:y,onChange:e=>U(e,"content")})})]}):(0,l.jsx)(l.Fragment,{children:y&&!_?"original"==N?(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)("div",{ref:V,className:(0,p.cn)(!R&&"line-clamp-4"),children:(0,l.jsx)(ep,{content:y})}),M&&(0,l.jsx)("button",{type:"button",className:"mt-1 text-sm underline",onClick:()=>I(e=>!e),children:R?"Show less":"Read more"})]}):(0,l.jsx)(ep,{content:y}):(0,l.jsx)(l.Fragment,{children:"social"==N?(0,l.jsx)(r.Suspense,{fallback:(0,l.jsx)("div",{children:"Loading..."}),children:(0,l.jsx)(ev,{full:!0,url:S,source:C})}):null})})]})}),S?(0,l.jsxs)("a",{href:S,target:"_blank",rel:"noopener noreferrer",className:"text-xs sm:text-sm",children:["Read the full article on ",C]}):null,$||!u?(0,l.jsx)(K,{withSave:!u}):null]})})})}var ey=s(63433);function ek(e){var t,s,a,o,c,d,u;let{className:m="",article:x,active:h=!1,onClick:g,withTitle:f=!1}=e,{currentFrame:j,setFrameState:b}=(0,r.useContext)(i.t),{users:v}=(0,r.useContext)(n.Aw);if(!x)return null;let N="sfa_"+(x.id||x.url),w=null!=(d=null==(s=j.scores)||null==(t=s[N])?void 0:t.score)?d:0,y=null!=(u=null==(o=j.scores)||null==(a=o[N])?void 0:a.votes)?u:0,k=w>20?2:w<-20?0:1;j.ranks[k];let C=x.urlToImage||(null==x||null==(c=x.images)?void 0:c.thumb)||"/images/default-article.jpg",S=x.title&&x.title.length>50?x.title.slice(0,50)+"...":x.title||"",A=v.choices?v.choices["slu_".concat(x.author)]:null,_=A?A.name:x.author,F=x.source||_;return(0,l.jsx)(eN.Provider,{value:{currentArticle:x},children:(0,l.jsxs)("div",{className:(0,p.cn)("relative w-full rounded-tl flex flex-col grow shrink min-h-[140px] p-2",k<1?"bg-blue-200 dark:bg-blue-900":k>1?"bg-red-200 dark:bg-red-900":"bg-secondary text-foreground",m),onClick:e=>{g&&g()},children:[(0,l.jsxs)("div",{className:"flex flex-row justify-between gap-2",children:[(0,l.jsx)("img",{width:160,height:160,alt:"",className:(0,p.cn)("object-cover h-16 w-20 rounded-tl",h?"border-2":""),src:C}),(0,l.jsx)("div",{className:(0,p.cn)("w-full sm:block",f?"":"hidden"),children:(0,l.jsx)("h6",{className:"text-start text-sm",title:x.title,children:S})})]}),(0,l.jsxs)("p",{className:"break-normal text-[10px] sm:text-sm text-start",children:[F,y?(0,l.jsxs)("span",{children:[" ⢠",
1y," votes"]}):null,x.date?(0,l.jsx)("span",{children:" ⢠"}):null,x.relative_time||x.date]}),y?(0,l.jsx)(L,{textClass:"text-sm"}):(0,l.jsx)("p",{className:"bg-gradient-to-r from-blue-500 via-transparent to-red-600 text-center",children:"Be first to vote"})]})})}var eC=s(15239);function eS(e){var t,s;let{article:a}=e,{user:o}=(0,r.useContext)(n.Rs),{currentFrame:c,setFrameState:d}=(0,r.useContext)(i.t),u=c.votes?c.votes["sfa_"+(a.id||a.guid)]:null,m="";if(u&&u["user_"+o.id]){let e=0|u["user_"+o.id].score;m=0!=e?"".concat(Math.abs(e),"% ").concat(e<0?c.ranks[0]:c.ranks[2]):c.ranks[1]}let x=a.urlToImage||"/assets/logo-padding.jpeg",h=a.description;return(0,l.jsx)(eN.Provider,{value:{currentArticle:a},children:(0,l.jsxs)("li",{className:"flex flex-wrap bg-background rounded-lg overflow-hidden shadow w-full",children:[(null==(t=a.images)?void 0:t.medium)?(0,l.jsx)(eC.default,{width:"300",height:"300",src:null==(s=a.images)?void 0:s.medium,onError:e=>{e.currentTarget.src="/images/default-article.jpg"},alt:a.title,className:"h-36 w-full object-contain bg-input"}):(0,l.jsx)("img",{width:"300",height:"300",src:x,onError:e=>{e.currentTarget.src="/images/default-article.jpg"},alt:a.title,className:"h-36 w-full object-contain"}),(0,l.jsxs)("div",{className:"p-4 w-full",children:[(0,l.jsx)("h4",{className:"text-md font-semibold",children:a.title}),(0,l.jsxs)("h5",{className:"text-sm",children:["Source: ",a.source]}),u&&(0,l.jsx)(l.Fragment,{children:(0,l.jsx)(L,{})}),a.description&&(0,l.jsxs)("p",{className:"mt-2 text-sm",children:[h.slice(0,150),"..."]}),m?(0,l.jsxs)("p",{className:"text-center text-sm font-semibold mt-2",children:["You voted ",m]}):null,(0,l.jsxs)("div",{className:"flex gap-2 mt-2",children:[(0,l.jsx)(M.$,{variant:"outline",onClick:()=>{d(e=>{var t;let s={...e.selectedArticles};if(!s)return e;let l=null!=(t=a.id)?t:a.guid;return l?(s["ai"==a.type?6:5]="sfa_"+l,{...e,selectedArticles:s}):e})},className:"flex-1",children:"Read more"}),(0,l.jsx)(M.$,{onClick:()=>{d(e=>{var t;let s={...e.selectedArticles};if(!s)return e;let l=null!=(t=a.id)?t:a.guid;return l?(s["ai"==a.type?4:3]="sfa_"+l,{...e,selectedArticles:s}):e})},className:"flex-1",children:m?"Change Vote":"Vote"})]})]})]})})}function eA(e){var t,s;let{className:a="",index:n=0,orientation:o="horizontal",browseChange:c=!0,template:d="minimum"}=e,{currentFrame:u,setFrameState:m}=(0,r.useContext)(i.t),{openFrame:x,framesData:h}=(0,r.useContext)(i.m),g=u.selectedArticles,[f,j]=(0,r.useState)(),b=null==(t=u.feedData)?void 0:t.articles,v=null==(s=u.aiArticles)?void 0:s.articles,N=u.articles,w=N?N.filter(e=>{var t;let s=null==h?void 0:h.articles[e];return 3==n&&(null==s?void 0:s.isRss)||u.scores&&(null==(t=u.scores[e])?void 0:t.rank)==n?e:null}):null;if(4==n&&v&&(w=Object.keys(v)),3==n&&b&&(w=Object.keys(b)),!w)return null;let y=e=>{if(!g||!w)return;let t=w.indexOf(g[n])+e;if(t<0||t>=w.length)return;let s=w[t];m(e=>{let t={...e.selectedArticles};return t[n]=s,{...e,selectedArticles:t}})},k=window.innerWidth<640?"horizontal":o;return(0,l.jsxs)(ey.FN,{opts:{align:"start"},orientation:k,setApi:j,className:(0,p.cn)("w-full bg-background justify-center",a),children:[w.length>1?(0,l.jsx)(ey.Q8,{disabled:!1,className:(0,p.cn)("translate-y-0 z-50","vertical"==k?"relative rotate-90 top-3":"absolute -left-3 right-auto"),onClick:()=>{f&&(f.scrollPrev(),y(-1))}}):null,(0,l.jsx)(ey.Wk,{className:"max-h-[600px]",children:w.map((e,t)=>{if(t>0&&!u.opened)return null;let s=g&&g[n]&&g[n]==e||(!g||!g[n])&&0==t,r=null==h?void 0:h.articles[e];return r?(0,l.jsxs)(ey.A7,{className:"basis-3/4 sm:basis-1/3",children:["minimum"==d&&(0,l.jsx)(ek,{active:u.selectedRank==n+1,article:r,withTitle:!0,className:(0,p.cn)("cursor-pointer grow shrink z-[500] p-2",s?"border-foreground":"bg-blend-darken bg-background opacity-50",0==t?"ms-0":"ms-2"),onClick:()=>{m(t=>{let s={...t.selectedArticles};return s[n]=e,{...t,selectedArticles:s}}),null==f||f.scrollTo(t),x&&x(u.slug||"",e||"")}}),"compact"==d&&(0,l.jsx)(eS,{article:r})]},e):null})}),w.length>1?(0,l.jsx)(ey.Oj,{disabled:!1,className:(0,p.cn)("translate-y-0 z-50","vertical"==k?"relative rotate-90 bottom-3":"absolute -right-3 left-auto"),onClick:()=>{f&&(y(1),f.scrollNext())}}):null]})}var e_=s(65229);function eF(e){let{className:t=""}=e,[s,a]=(0,r.useState)(!1);return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)("button",{onClick:()=>a(!0),className:(0,p.cn)("text-white bg-blue-500 hover:bg-blue-700 rounded px-4 py-2",t),children:"Login"}),s?(0,l.jsxs)("dialog",{open:!0,className:"fixed w-full sm:w-1/4 inset-0 z-50 bg-black flex justify-center items-center",children:[(0,l.jsx)(P.default,{}),(0,l.jsx)("button",{onClick:()=>a(!1),className:"absolute top-0 right-0 p-2 text-white bg-red-500 hover:bg-red-700",children:"X"})]}):null]})}function eT(e){let[t,s]=(0,r.useState)(!1);return(0,r.useEffect)(()=>{let t=window.matchMedia(e);s(t.matches);let l=e=>s(e.matches);return t.addEventListener("change",l),()=>t.removeEventListener("change",l)},[e]),t}function eE(){var e;let{currentFrame:t,setFrameState:s}=(0,r.useContext)(i.t),{framesData:a,setFramesData:o}=(0,r.useContext)(i.m),{user:c}=(0,r.useContext)(n.Rs),{topics:d}=(0,r.useContext)(n.U5),[u,m]=(0,r.useState)({isLoading:!1,loadingMore:!1,error:"",page:1,max:!1}),x=(0,r.useRef)(null),h=eT("(min-width: 640px)"),p=t.selectedArticles[3]?null==a?void 0:a.articles[t.selectedArticles[3]]:null,g=!!t.selectedArticles[3],f=t.topics||[],j=d.choices?d.choices.filter(e=>null!=e.id&&f.map(String).includes(String(e.id))||f.includes(e.label)).map(e=>e.label):[],b=t.searchTerms,v=c.token,N=async function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;if(!b.length&&!j.length)return void m(e=>({...e,error:"No topics or search terms selected for this frame."}));m(t=>({...t,isLoading:1===e,loadingMore:e>1,error:""}));let l=Array.from(new Set([...b,...j])),r="".concat("https://api.sociallibra.com/wp-json/social_libra/v2","/rss_feed?frame=").concat(t.id,"&topics=").concat(l.join(","),"&page=").concat(e);try{let l=await fetch(r,{headers:{"Content-Type":"application/json",Authorization:v?"Bearer ".concat(v):""}});if(!l.ok)throw Error("HTTP error! Status: ".concat(l.status));let a=await l.json(),n=Object.keys(a.articles||{}),i=t.articles||[],c=n.filter(e=>!i.includes(e));s(e=>{let t=e.articles?e.articles.concat(n):[];var s=t.filter((e,s)=>t.indexOf(e)===s);return{...e,scores:{...e.scores,...a.scores},articles:s,rssLoaded:!0,votes:{...e.votes,...a.votes}}}),o(e=>({...e,articles:{...e.articles,...a.articles}})),m(t=>({...t,isLoading:!1,loadingMore:!1,page:e,max:"boolean"==typeof a.max?a.max:e>1&&0===c.length}))}catch(e){m(t=>({...t,isLoading:!1,loadingMore:!1,error:e.message}))}};if((0,r.useEffect)(()=>{t.rssLoaded||N(1)},[d,b,v]),(0,r.useEffect)(()=>
1{if(u.max||u.loadingMore||u.isLoading)return;let e=x.current;if(!e)return;let t=new IntersectionObserver(e=>{e[0].isIntersecting&&N(u.page+1)},{rootMargin:"400px"});return t.observe(e),()=>t.disconnect()},[u.max,u.loadingMore,u.isLoading,null==(e=t.articles)?void 0:e.length]),u.isLoading)return(0,l.jsx)(z.A,{});if(u.error)return(0,l.jsx)("p",{className:"text-red-400 font-bold text-lg text-center",children:u.error});let w=t.articles;if(!w)return(0,l.jsx)("p",{className:"text-red-400 font-bold text-lg text-center",children:"No articles found for this topic."});let y=w.filter(e=>{let t=null==a?void 0:a.articles[e];return(null==t?void 0:t.isRss)?e:null});if(!y.length)return(0,l.jsx)("p",{className:"text-red-400 font-bold text-lg text-center",children:"No articles found for this topic."});let k=(null==p?void 0:p.urlToImage)||"/icon-256x256.png";return(0,l.jsxs)("div",{className:"py-4",children:[(0,l.jsx)(eA,{className:"w-full m-auto",index:3,template:"compact"}),!u.max&&y.length?(0,l.jsx)("div",{ref:x,className:"text-center my-4 h-8",children:u.loadingMore?(0,l.jsx)(z.A,{}):null}):null,p&&g?(()=>{var e,t;let r=()=>{s(e=>{let t={...e.selectedArticles};return t[3]="",{...e,selectedArticles:t}})},a=(null==(e=p.images)?void 0:e.medium)?(0,l.jsx)(eC.default,{width:"80",height:"80",src:null==(t=p.images)?void 0:t.medium,onError:e=>{e.currentTarget.src="/images/default-article.jpg"},alt:p.title,className:"w-20 h-20 rounded object-cover shrink-0"}):(0,l.jsx)("img",{width:"80",height:"80",src:k,onError:e=>{e.currentTarget.src="/images/default-article.jpg"},alt:p.title,className:"w-20 h-20 rounded object-cover shrink-0"}),n=(0,l.jsxs)("div",{className:"relative flex flex-col sm:flex-row items-center gap-3 w-full",children:[(0,l.jsx)(eo,{}),a,(0,l.jsx)("h3",{className:"text-center sm:text-start p-1 text-lg sm-text-2xl font-bold",children:p.title})]}),i=(0,l.jsxs)("div",{className:"relative flex flex-col sm:flex-row items-center gap-3 w-full",children:[(0,l.jsx)(eo,{}),a,(0,l.jsx)(ea,{className:"text-center sm:text-start p-1 text-lg sm-text-2xl font-bold",children:p.title})]}),o=c.id>0?(0,l.jsx)(K,{minimal:!0,className:"w-full bg-background p-1 flex justify-stretch"}):(0,l.jsxs)("div",{children:[(0,l.jsx)("p",{children:"You must be logged in to vote on articles."}),(0,l.jsx)(eF,{})]});return(0,l.jsx)(eN.Provider,{value:{currentArticle:p},children:h?(0,l.jsxs)(R.A,{onClose:r,className:"sm:w-[480px]",children:[n,o]}):(0,l.jsx)(G,{open:g,onOpenChange:e=>{e||r()},children:(0,l.jsxs)(es,{className:"max-h-screen justify-center align-middle",children:[(0,l.jsxs)(el,{className:"flex flex-col sm:flex-row p-1 justify-center",children:[i,(0,l.jsx)(ee,{className:"absolute top-2 right-2",asChild:!0,children:(0,l.jsx)(e_.A,{})})]}),o]})})})})():null]})}function eL(e){let{full:t=!1,clickable:s=!0}=e,{currentFrame:a,setFrameState:o}=(0,r.useContext)(i.t),{topics:c}=(0,r.useContext)(n.U5),{openFrame:d,framesData:u}=(0,r.useContext)(i.m),m=a.rankSuggestions,{articles:x}=a,g="ranks"==a.editing||"all"==a.editing,f=a.ranks,j=a.selectedRank||-1,b=a.selectedArticles||{},v=j-1,N=a.ranks&&3===Object.keys(a.ranks).length&&Object.values(a.ranks).every(e=>""!==e),w=a.title&&a.topics&&a.topics.length>0;if((0,r.useEffect)(()=>{x&&(null==u?void 0:u.articles)&&f.map((e,t)=>{let s=null==a?void 0:a.selectedArticles,l=x.filter(e=>{var s;return a.scores&&(null==(s=a.scores[e])?void 0:s.rank)==t?e:null});l&&!l.includes(s[t])&&o(e=>{let s={...e.selectedArticles};return s[t]=l[0]||"",{...e,selectedArticles:s}})})},[v,f,x,o]),!b||a.new&&!a.title)return null;let y=null;return(0,l.jsxs)("div",{className:"my-3 flex flex-col relative",children:[(0,l.jsx)("div",{className:(0,p.cn)("bg-background flex mb-2 justify-stretch text-center items-center w-full z-[2000] sticky top-0"),children:f.map((e,t)=>{let r=a.selectedRank==t+1;return(0,l.jsx)("div",{onClick:()=>{s&&e&&!g&&(o(e=>({...e,selectedRank:t+1})),d&&d(a.slug||""))},className:(0,p.cn)("text-sm relative flex flex-col op w-1/3 flex-1/3",a.opened?"gap-10":"flex-1 gap-4"),children:g?(0,l.jsx)(h,{className:(0,p.cn)("ph-foreground input-text-type w-full h-full content-center bg-transparent border resize-none overflow-hidden max-h-10 sm:max-h-5 text-xs text-center font-bold sm:text-sm",1==t?"m-auto":2==t?"ml-auto":"mr-auto",t<1?"border-blue-200 text-blue-400":t>1?"border-red-200 text-red-400":"border-foreground"),placeholder:1===t?"Neutral":2===t?"Perspective 2":"Perspective 1",suggestions:m[t],value:e,onCh
1ange:e=>{"__load_more__"===e?console.log("load more suggestions"):o(s=>{let l=s.ranks;return l[t]=e,{...s,ranks:l,updated:!0}})}}):(0,l.jsx)("span",{className:(0,p.cn)(r&&s||!a.opened?"":"opacity-60 hover:opacity-100","text-background font-bold text-center w-full drop-shadow-lg p-1 rounded-b-lg h-7 overflow-auto whitespace-nowrap",t<1?"bg-blue-400":t>1?"bg-red-400":"bg-secondary text-foreground"),children:e})},t+1)})}),t?(0,l.jsx)("div",{className:(0,p.cn)("bg-background flex mb-2 justify-stretch text-center gap-3 items-start w-full sticky top-0 z-[2000] flex-row"),children:f.map((e,t)=>{let s=a.selectedRank==t+1,r=(null==u?void 0:u.articles)?null==u?void 0:u.articles[b[t]]:null;return(s&&r&&(y=r),a.opened||!r)?null:(0,l.jsx)(ek,{onClick:()=>{!g&&(o(e=>{let s={...e.selectedArticles};return{...e,selectedRank:t+1,selectedArticles:s,tab:"articles"}}),d&&d(a.slug||""))},className:(0,p.cn)("shadow-foreground border border-input cursor-pointer hover:shadow-lg hover:shadow-foreground transition-all duration-200 ease-in-out",1==t?"hidden sm:block":""),article:r,active:!0},t+1)})}):null,w&&N&&!y&&a.opened&&s?(0,l.jsx)(eE,{}):null,t&&y&&a.opened&&(0,l.jsxs)("div",{className:"flex flex-col sm:flex-row w-full h-full",children:[(0,l.jsx)(ew,{article:y,className:"overflow-scroll w-auto sm:w-2/3",category:a.ranks[j-1]}),(0,l.jsx)(eA,{orientation:"vertical",className:"sticky bottom-0 sm:w-1/3 h-auto",index:v})]})]})}var eO=s(11010);function eP(){let{currentFrame:e,setFrameState:t}=(0,r.useContext)(i.t),[s,a]=(0,r.useState)(null),[n,o]=(0,r.useState)(!1);return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)("button",{onClick:()=>{o(!0),a({...e,opened:!1,slug:e.slug+"-edit",editing:"all"})},className:"w-full block px-4 py-2 text-foreground hover:bg-input ",children:["Edit ",(0,l.jsx)(eO.A,{className:"inline"})]}),n&&(0,l.jsx)(R.A,{className:"w-full md:w-3/4 md:h-auto my-1",onClose:()=>o(!1),children:(0,l.jsx)(th,{currentFrame:s||e,onEdit:e=>{a({...e,editing:""}),t(t=>({...t,...e,editing:"",opened:t.opened}))}})})]})}function ez(){let[e,t]=(0,r.useState)({deleting:!1,loading:!1}),{currentFrame:s}=(0,r.useContext)(i.t),{setFramesData:a}=(0,r.useContext)(i.m),{user:o}=(0,r.useContext)(n.Rs),c=async()=>{if(!confirm("Are you sure you want to delete this frame?"))return;t({deleting:!0,loading:!0});let e=await fetch("https://api.sociallibra.com/wp-json/social_libra/v2/story_frames/"+s.id,{method:"DELETE",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(o.token)}});await e.json()&&a(e=>{let t={...e.frames};return delete t["sf_"+s.id],{...e,frames:t}})};return(0,l.jsx)(l.Fragment,{children:(0,l.jsxs)("button",{onClick:()=>{c()},className:"w-full text-red-400 hover:text-background block px-4 py-2 hover:bg-red-400",children:["Delete ",(0,l.jsx)(W.A,{className:"inline"})]})})}var eR=s(6191);s(68238);let eD={title:"",url:"",type:"original",description:"",content:"",source:"",images:{thumb:"",medium:"",large:""},score:0,totalVotes:0,votes:{},saved:!1,updated:!1,urlToImage:"",category:""},eI={original:"Write an Article",external:"Link to External",rss:"RSS Feed",social:"Social Media"},eM=new AbortController,eB=eM.signal,eV="",eU=e=>{let{buttonClass:t="",buttonText:s="",initialUrl:o=""}=e,c=(0,a.c)("NewArticle"),{currentFrame:d,setFrameState:u}=(0,r.useContext)(i.t),x="frame_"+d.id,{framesData:h,setFramesData:g}=(0,r.useContext)(i.m),{user:f,setCurrentUser:j}=(0,r.useContext)(n.Rs),[b,v]=(0,r.useState)({addArticle:!!o,loading:!1,loadingArticle:!1,error:"",success:"",article:eD,files:[]});(0,r.useEffect)(()=>{if(!o)return;let e=o;e.includes("https://")||e.includes("http://")||(e="https://"+e),v(t=>({...t,loadingArticle:!0,article:{...eD,type:"external",url:e},error:""})),_(e)},[]);let{addArticle:N,article:w,loading:y,loadingArticle:k,error:C,success:S,files:A}=b,_=async e=>{eV=e;let t=!1,s=await fetch("".concat("https://api.sociallibra.com/wp-json/social_libra/v2","/").concat(d.id,"/article_by_url/?url=").concat(e),{signal:eB,method:"GET",headers:{"Content-Type":"application/json",Authorization:f.token?"Bearer ".concat(f.token):""}});s.ok||await s.json().then(t=>{v(s=>e!==eV?s:{...s,article:{...s.article,url:e},loadingArticle:!1,error:t.message})});let l=await s.json();if(l.success){let s={...w,...l.article,type:"external",saved:!0,updated:!0};v(t=>e!==eV?t:{...t,article:s,loadingArticle:!1}),t=!0}if(t||e!==eV)return;let r=(e=>/(?:https?:\/\/)?(?:www\.)?(?:youtube\.com|youtu\.be)\/(?:watch\?v=)?(.+)/g.exec(e)?"YouTube":/(?:https?:\/\/)?(?:www\.)?(?:facebook\.com)\/(?:watch\?v=)?(.+)/g.exec(e)?"Facebook":/(?:https?:\/\/)?(?:www\.)?(?:twitter\.com)\/(?:\?v=)?(.+)/g.exec(e)||/(?:https?:\/\/)?(?:www\.)?(?:x\.com)\/(?:\?v=)?(.+)/g.exec(e)?"Twitter":/(?
1:https?:\/\/)?(?:www\.)?(?:instagram\.com)\/(?:\?v=)?(.+)/g.exec(e)?"Instagram":/(?:https?:\/\/)?(?:www\.)?(?:tiktok\.com)\/(?:\?v=)?(.+)/g.exec(e)?"TikTok":/(?:https?:\/\/)?(?:www\.)?(?:linkedin\.com)\/(?:\?v=)?(.+)/g.exec(e)?"LinkedIn":/(?:https?:\/\/)?(?:www\.)?(?:pinterest\.com)\/(?:\?v=)?(.+)/g.exec(e)?"Pinterest":"")(e);if(r&&"YouTube"!=r)return},F=e=>{eV="";let t=e.target.value;v(e=>({...e,article:{...eD,type:t,loadingArticle:!1,loading:!1,error:"",images:{thumb:"",medium:"",large:""}}}))};return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)("button",{className:(0,p.cn)("",t),title:"Add Article",onClick:e=>v(e=>({...e,addArticle:!0})),children:[s,(0,l.jsx)(eR.A,{className:"inline"})]}),(0,l.jsx)(D.lG,{open:N,onOpenChange:e=>{v(t=>({...t,addArticle:e}))},children:(0,l.jsxs)(D.Cf,{className:"sm:!max-w-[1200px] items-center justify-center flex flex-col",children:[(0,l.jsx)(D.c7,{className:"w-3/4 flex flex-col ",children:(0,l.jsxs)(D.L3,{className:"text-center text-lg",children:["Add Article to ",d.title,(0,l.jsx)(eL,{clickable:!1})]})}),(0,l.jsxs)("form",{noValidate:!0,onSubmit:e=>{var t;e.preventDefault(),e.stopPropagation(),e.target.noValidate=!0,v(e=>({...e,loading:!0}));let s=new FormData;s.append("frame",(null==(t=d.id)?void 0:t.toString())||JSON.stringify(d)),s.append("article",JSON.stringify(w));let l=f.voting?f.voting[x+"_newArticle"]:null;l&&s.append("vote",JSON.stringify(l)),A&&A.forEach(e=>s.append("files[]",e)),fetch("".concat("https://api.sociallibra.com/wp-json/social_libra/v2","/articles"),{method:"POST",headers:{Authorization:"Bearer ".concat(f.token)},body:s}).then(e=>{let t=e.json();return e.ok||t.then(e=>{throw Error(e.message)}),t}).then(e=>{e.success&&(v(e=>({...e,article:eD,loading:!1,success:"Article Saved Successfully",addArticle:!1})),en.toast.success(c("articleSaved")),!d.id&&e.frame_id&&u(t=>({...t,id:e.frame_id})),u(t=>{let s=f.voting?f.voting[x+"newArticle"]:null,l=(null==s?void 0:s.score)?s.score:0,r=l<-20?0:l>20?2:1,a={...t.scores};a["sfa_"+e.id]={score:l,votes:1,rank:r};let n={...t.selectedArticles};return n[r]="sfa_"+e.id,{...{...t,selectedArticles:n,scores:a,votes:{...t.votes,["sfa_"+e.id]:{["user_"+f.id]:{score:l,comment:""}}}}}}),j&&j(e=>{let t={...e.voting};return delete t[x+"_newArticle"],{...e,voting:t}}),g(t=>{let s={...t.articles,["sfa_"+e.id]:{...w,id:e.id,saved:!0,updated:!1}};return{...t,articles:s}}))}).catch(e=>{console.error("There was an error!",e)})},className:"flex flex-col",children:[(0,l.jsxs)("div",{className:"mb-5 flex flex-col items-center justify-center no-scrollbar -mx-4 max-h-[70vh] overflow-y-auto px-4",children:[(0,l.jsx)("label",{className:"text-lg",children:"Article Type"}),(0,l.jsx)("div",{className:"flex flex-wrap gap-4",children:Object.keys(eI).map((e,t)=>(0,l.jsx)("div",{children:(0,l.jsxs)("label",{onClick:F,children:[(0,l.jsx)("input",{className:"me-1",type:"radio",onChange:e=>{},checked:e===w.type,value:e}),eI[e]]})},t))})]}),("external"==w.type||"social"==w.type)&&(0,l.jsx)(l.Fragment,{children:(0,l.jsx)("div",{className:"mb-7",children:(0,l.jsxs)("label",{className:"block mb-2",children:[(0,l.jsx)("span",{className:"",children:"Link to article"}),(0,l.jsx)("input",{className:"form-input mt-1 block w-full",placeholder:"https://article-link.com",type:"url",name:"link",value:b.article.url,onChange:e=>{eM.abort(),eB=(eM=new AbortController).signal;let t=e.target.value;if(!t.includes("localhost")&&!t.includes(".")){eV="",v(e=>({...e,article:{...e.article,url:t},loadingArticle:!1,error:t?"Please enter a valid URL.":""}));return}v(e=>({...e,loadingArticle:!0,article:{...eD,type:e.article.type,url:t},error:""})),t.includes("https://")||t.includes("http://")||(t="https://"+t),_(t)}})]})})}),"rss"==w.type&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(m,{}),(0,l.jsx)(eE,{})]}),C&&(0,l.jsx)("p",{children:C}),k&&"external"==w.type&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(z.A,{}),(0,l.jsx)("h3",{className:"text-center",children:"Loading Article..."})]}),(w.title||"original"==w.type)&&(0,l.jsx)(l.Fragment,{children:(0,l.jsx)(ew,{article:w,changeArticle:v,showFull:!0})}),w.title?(0,l.jsx)(D.Es,{children:b.loading?(0,l.jsx)(z.A,{}):(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(M.$,{variant:"outline",className:"bg-blue-200 text-black",children:"Save"}),(0,l.jsx)(M.$,{type:"button",className:"btn-secondary block",onClick:e=>v(e=>({...e,addArticle:!1,article:eD})),children:"Cancel"})]})}):null]})]})})]})};function e$(e){let{children:t}=e,{currentFrame:s}=(0,r.useContext)(i.t),{user:a}=(0,r.useContext)(n.Rs),[o,c]=(0,r.useState)({actions:!1,sharing:!1,editing:!1}),{actions:d,editing:u,sharing:m}=o,h=e=>{c(t=>({...t,sharing:e}))};return(0,l.jsxs)("div",{className:"border rounded-md text-end absolute -top-[36px] h-[35px] bg-background end-[-1px] flex flex-row gap-2 p-2 z-50",children:[t,a.id?(0,l.jsxs)(x.AM,{open:d,onOpenChange:e=>c(t=>({...t,actions:e})),children:[(0,l.jsx)(x.Wv,{children:(0,l.jsx)(Q.A,{})}),(0,l.jsxs)(x.hl,{className:"bg-background shadow-lg rounded-lg w-[150px] text-end",children:[a.id==s.author&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(eP,{}),(0,l.jsx)(ez,{})]}),a.token&&"subscriber"!==a.role&&(0,l.jsx)(eU,{buttonText:"Article",buttonClass:"w-full px-4 py-2 text-foreground hover:bg-input"})]})]}):null,m&&(0,l.jsx)(Y,{setShare:h}),(0,l.jsx)($,{setShare:h})]})}let eY=()=>{let{currentFrame:e,setFrameState:t}=(0,r.useContext)(i.t),[s,a]=(0,r.useState)(!1),n=e.title?e.title.length:0,o="title"==e.editing||"all"==e.editing;return(0,l.jsx)("h3",{className:"mt-0 inline-block text-lg sm:text-2xl font-bold w-full",children:o?(0,l.jsxs)("div",{className:"flex flex-col",children:[(0,l.jsxs)("div",{className:"flex justify-between",children:[(0,l.jsx)("label",{htmlFor:"frame-title",className:"",children:"Frame Title"}),n>0&&s&&(0,l.jsxs)("span",{className:"self-end text-sm ",children:[n,"/",130]})]}),(0,l.jsx)("textarea",{maxLength:130,className:"w-full resize-none overflow-hidden max-h-[110px] md:max-h-[50px]",value:e.title.replace(/(\r\n|\n|\r)/gm," "),placeholder:"Story Frame Title",onFocus:()=>a(!0),onBlur:()=>a(!1),onChange:e=>{t(t=>{let s=t.slug&&t.slug!=(0,p.Yv)(t.title)?t.slug:(0,p.Yv)(e.target.value);return{...t,title:e.target.value,slug:s,updated:!0}})}}),n>130&&(0,l.jsx)("span",{className:"self-end text-sm text-red-500",children:"Title is too long"})]}):(0,l.jsx)("span",{onClick:()=>{e.canEdit&&t(e=>({...e,editing:"title"}))},children:e.new?"Frame Title":"".concat(e.title).concat("draft"===e.status?" (Draft)":"")})})},eK=()=>{let{currentFrame:e,setFrameState:t}=(0,r.useContext)(i.t),s="description"==e.editing||"all"==e.editing;return e.new&&!e.title?null:(0,l.jsx)(l.Fragment,{children:s?(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)("label",{htmlFor:"frame-description",className:"",children:"Frame Description"}),(0,l.jsx)("textarea",{rows:3,className:"w-full",placeholder:"Add Story Frame Description",onChange:e=>{t(t=>({...t,description:e.target.value}))},value:e.description})]}):e.description&&(0,l.jsx)("div",{onClick:()=>{e.canEdit&&t(e=>({...e,editing:"description"}))}
1,dangerouslySetInnerHTML:{__html:e.description||"Description"}})})};var eJ=s(20063),eQ=s(38966),eW=s(25765);function eq(e){let{className:t}=e,{currentFrame:s}=(0,r.useContext)(i.t),{user:a}=(0,r.useContext)(n.Rs),{users:o}=(0,r.useContext)(n.Aw);if(s.new)return null;let c="meta"==s.editing,{author:d}=s,u=o.choices?o.choices["slu_".concat(d)]:{id:0,name:"",description:"",avatar:"",followers:[],following:[],token:"",email:"",username:"",last_name:"",first_name:""},m=(null==u?void 0:u.description)||"";if(c)return null;let h=s.author==a.id?"You":s.author_name;return(0,l.jsxs)("ul",{className:t,children:[(0,l.jsxs)("li",{children:["Created by \xa0",(0,l.jsxs)(x.AM,{children:[(0,l.jsx)(x.Wv,{className:"text-blue-500 hover:underline",children:h}),(0,l.jsx)(x.hl,{className:"bg-background",children:(0,l.jsxs)("div",{className:"p-4",children:[(0,l.jsx)("h3",{children:s.author_name}),(0,l.jsx)(eu.A,{user:u,width:80,height:80}),(0,l.jsx)("p",{children:m}),(0,l.jsx)(eW.default,{influencer:u})]})})]})]}),(0,l.jsx)("li",{children:s.date})]})}var eH=s(73633),eG=s(8494),eX=s(84382),eZ=s(80534),e0=s(18085);function e1(){var e,t,s,a;let{user:o}=(0,r.useContext)(n.Rs),{currentFrame:c,setFrameState:d}=(0,r.useContext)(i.t),{framesData:u}=(0,r.useContext)(i.m),m=c.selectedRank?c.selectedRank-1:null,x=null!==m&&(null==(e=c.selectedArticles)?void 0:e[m])?c.selectedArticles[m]:(null==(t=c.selectedArticles)?void 0:t[0])||(null==(s=c.selectedArticles)?void 0:s[1])||(null==(a=c.selectedArticles)?void 0:a[2])||null,h=x?null==u?void 0:u.articles[x]:null,[g,f]=(0,r.useState)({comment:"",sending:!1,articleScope:""}),j=async()=>{var e,t;if(g.comment.length<1)return;let s=g.articleScope&&null!=(t=null==u||null==(e=u.articles[g.articleScope])?void 0:e.id)?t:null;f(e=>({...e,comment:"",sending:!0}));let l=Math.random().toString(36);d(e=>{let t={...e.newComments,[l]:{id:0,content:g.comment,date:"",author:o.id,article:s}};return{...e,comment_count:e.comment_count+1,newComments:t}});let r={content:g.comment,frame:c.id};s&&(r.article_id=s),await fetch("".concat("https://api.sociallibra.com/wp-json/social_libra/v2","/comments"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(o.token)},body:JSON.stringify(r)}).then(e=>e.json()).then(e=>{d(t=>{let s={...t.newComments},r={...t.comments};return e.success&&(r[e.comment]={...s[l],id:e.comment,date:e.date}),delete s[l],{...t,comments:r,newComments:s}})})},b=g.comment.length<1,v=o.avatar?o.avatar:"".concat("https://api.sociallibra.com/wp-json/social_libra/v2","/assets/default-profile.svg}");return(0,l.jsx)(l.Fragment,{children:(0,l.jsx)("div",{className:(0,p.cn)("flex flex-row justify-center items-stretch border-b-2 bg-background sticky bottom-0"),children:(0,l.jsxs)("div",{className:"full-row bg-[#56C4FD10] justify-center",children:[(0,l.jsx)("div",{className:"w-1/6 flex justify-center",children:(0,l.jsx)("img",{className:"rounded-full",width:"40",height:"40",src:"".concat(v)})}),(0,l.jsxs)("div",{className:"w-5/6",children:[h&&(0,l.jsxs)("div",{className:"flex items-center gap-4 mb-2 text-xs text-muted-foreground",children:[(0,l.jsxs)("label",{className:"flex items-center gap-1.5 cursor-pointer",children:[(0,l.jsx)("input",{type:"radio",name:"comment-scope-".concat(c.id),checked:""===g.articleScope,onChange:()=>f(e=>({...e,articleScope:""}))}),"Frame"]}),(0,l.jsxs)("label",{className:"flex items-center gap-1.5 cursor-pointer max-w-[200px]",children:[(0,l.jsx)("input",{type:"radio",name:"comment-scope-".concat(c.id),checked:g.articleScope===x,onChange:()=>f(e=>({...e,articleScope:x}))}),(0,l.jsx)("span",{className:"truncate",children:h.title})]})]}),(0,l.jsx)("form",{className:"w-full",onSubmit:e=>{e.preventDefault(),j()},children:(0,l.jsxs)("div",{className:"flex flex-row justify-end items-center gap-2",children:[(0,l.jsx)(B.T,{rows:2,onChange:e=>f(t=>({...t,comment:e.target.value})),onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),j())},value:g.comment,className:"resize-none",placeholder:"Type your response..."}),(0,l.jsx)("button",{disabled:b,className:(0,p.cn)("text-blue-400 font-bold rounded-[10px]",b?"disabled":"submit"),children:(0,l.jsx)(e0.A,{className:"w-6 h-6 rotate-[45deg]"})})]})})]})]})})})}var e2=s(35299),e5=s(18514);function e3(e){let{author:t}=e,[s,a]=(0,r.useState)(!1);return(0,l.jsxs)("div",{className:"flex flex-row items-center",children:[(0,l.jsxs)("div",{className:"flex flex-col items-center gap-2",onClick:()=>a(!s),children:[(0,l.jsx)(eu.A,{user:t,width:80,height:80,className:"rounded-full w-20 h-20"}),(0,l.jsx)("span",{className:"text-sm font-bold",children:t.name})]}),s&&!s&&(0,l.jsxs)("div",{className:"flex flex-row items-stretch bg-background z-[200] absolute top-0 end-2 sm:end-[110px]",children:[(0,l.jsxs)("div",{className:"bg-background p-4",children:[(0,l.jsx)(e_.A,{className:"absolute top-0 right-0 left-0",onClick:()=>a(!1)}),(0,l.jsxs)("div",{className:"flex flex-col items-start gap-2",children:[(0,l.jsx)("img",{src:t.avatar,className:"w-8 h-8 rounded-full me-2"}),(0,l.jsx)("span",{className:"text-sm font-bold",children:t.name})]})]}),(0,l.jsx)("div",{className:"flex flex-col gap-2 bg-[#e6e6e6] p-6",children:(0,l.jsx)("p",{className:"text-sm font-bold",children:t.url})})]})]})}function e4(e){var t,s,a;let{commentId:o,votes:c,onVote:d}=e,{user:u}=(0,r.useContext)(n.Rs),{users:m}=(0,r.useContext)(n.Aw),{currentFrame:x}=(0,r.useContext)(i.t),h="user_".concat(u.id),g=u.id&&null!=(t=null==c?void 0:c[h])?t:null,[f,j]=(0,r.useState)(!1),[b,v]=(0,r.useState)(!1),[N,w]=(0,r.useState)(null!=(s=null==g?void 0:g.score)?s:0),[y,k]=(0,r.useState)(null!=(a=null==g?void 0:g.comment)?a:""),[C,S]=(0,r.useState)(!g||(0,ec.Qz)(g.public)),[A,_]=(0,r.useState)({}),F=Object.values(c||{}).map(e=>Number(e.score)),T=F.length,E=T?Math.round(F.reduce((e,t)=>
1e+t,0)/T):null,L=null!=E?E>20?2:E<-20?0:1:null,P=x.ranks||[],z=null!=L&&P[L]||"",R=(0,p.cn)("inline-block text-xs font-bold px-2 py-0.5 rounded-full text-background",0===L?"bg-blue-400":2===L?"bg-red-400":"bg-secondary text-foreground"),D=Object.entries(c||{}).filter(e=>{let[t,s]=e;return t.startsWith("user_")&&(0,ec.Qz)(s.public)}).map(e=>{let[t,s]=e;return{userId:t.replace("user_",""),score:Number(s.score)||0,comment:s.comment||""}});return(0,r.useEffect)(()=>{let e=D.map(e=>e.userId).filter(e=>!A[e]&&!m.choices["slu_".concat(e)]);e.length&&Promise.all(e.map(e=>(0,ed.A)({id:Number(e),token:u.token,returnSingle:!0}))).then(t=>{_(s=>{let l={...s};return t.forEach((t,s)=>{let r=t?t.choices[0]:null;r&&(l[e[s]]=r)}),l})})},[D.length]),(0,l.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,l.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[null!=E&&z&&(0,l.jsx)("span",{className:R,children:0===E?z:"".concat(Math.abs(E),"% ").concat(z)}),T>0&&(0,l.jsxs)("button",{className:"text-xs text-muted-foreground underline-offset-2 hover:underline",onClick:()=>v(e=>!e),children:[T," ",1===T?"vote":"votes"]}),u.id>0&&o>0&&(0,l.jsx)("button",{className:"text-xs text-blue-500 underline",onClick:()=>j(e=>!e),children:null!==g?"Change vote":"Vote"})]}),!f&&(null==g?void 0:g.comment)&&(0,l.jsxs)("p",{className:"text-xs text-muted-foreground italic",children:["â",g.comment,"â"]}),f&&(0,l.jsxs)("div",{className:"flex flex-col gap-2 p-2 border rounded bg-background",children:[(0,l.jsx)(O,{value:N,onChange:e=>w(Number(e))}),(0,l.jsx)(B.T,{rows:2,placeholder:"Comment on your vote⦠(optional)",value:y,onChange:e=>k(e.target.value),className:"resize-none text-sm"}),(0,l.jsxs)("label",{className:"flex items-center gap-2 text-xs cursor-pointer select-none",children:[(0,l.jsx)("input",{type:"checkbox",checked:C,onChange:e=>S(e.target.checked)}),"Make vote public"]}),(0,l.jsx)(M.$,{size:"sm",onClick:()=>{d({score:N,comment:y,public:C}),j(!1),fetch("".concat("https://api.sociallibra.com/wp-json/social_libra/v2","/comment_votes"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(u.token)},body:JSON.stringify({comment:o,score:N,vote_comment:y,public:C})}).catch(console.error)},className:"btn-primary self-end",children:"Submit"})]}),b&&D.length>0&&(0,l.jsx)("div",{className:"flex flex-col gap-1.5",children:D.map(e=>{let t=A[e.userId]||m.choices["slu_".concat(e.userId)]||null,s=e.score>20?2:e.score<-20?0:1,r=P[s]||"",a=(0,p.cn)("text-xs font-bold px-2 py-0.5 rounded-full text-background",0===s?"bg-blue-400":2===s?"bg-red-400":"bg-secondary text-foreground");return(0,l.jsxs)("div",{className:"border rounded p-2 flex flex-col gap-1 bg-muted/30",children:[(0,l.jsxs)("div",{className:"flex items-center gap-2",children:[(0,l.jsx)(eu.A,{user:t||{},width:20,height:20}),(0,l.jsx)("span",{className:"text-xs font-semibold",children:(null==t?void 0:t.name)||"A voter"}),(0,l.jsx)("span",{className:a,children:0===e.score?r:"".concat(Math.abs(e.score),"% ").concat(r)})]}),e.comment&&(0,l.jsxs)("p",{className:"text-xs text-muted-foreground",children:["â",e.comment,"â"]})]},e.userId)})})]})}let e6=e=>{let{comment:t,noUpdate:s,handleUpdate:a,changeComment:n}=e,i=(0,r.useRef)(null);return(0,r.useEffect)(()=>{i.current&&(i.current.focus(),i.current.selectionStart=i.current.selectionEnd=i.current.value.length)},[]),(0,l.jsx)("form",{className:"w-full",onSubmit:a,children:(0,l.jsxs)("div",{className:"flex gap-2 items-start",children:[(0,l.jsx)(B.T,{ref:i,rows:3,onChange:n,value:t,className:"resize-none flex-1",placeholder:"Edit commentâ¦"}),(0,l.jsx)("button",{disabled:s,className:(0,p.cn)("text-blue-400 mt-1",s?"opacity-40":""),children:(0,l.jsx)(e0.A,{className:"w-5 h-5 rotate-45"})})]})})};function e8(e){var t;let{comment:s}=e,[a,o]=(0,r.useState)({editing:!1,updatedComment:"",sending:!1,error:""}),{currentFrame:c,setFrameState:d}=(0,r.useContext)(i.t),{framesData:u}=(0,r.useContext)(i.m),{user:m}=(0,r.useContext)(n.Rs),{users:x}=(0,r.useContext)(n.Aw),h=x.choices["slu_".concat(s.author)]||null,p=s.article?null==u||null==(t=u.articles["sfa_".concat(s.article)])?void 0:t.t
1itle:null,g=s.author===m.id||"administrator"===m.role,f=a.updatedComment===s.content||a.sending;return(0,l.jsxs)("div",{className:"border rounded-lg p-3 flex flex-col gap-2 bg-background",children:[(0,l.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,l.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[h&&(0,l.jsx)(e3,{author:h}),(0,l.jsx)("span",{className:"text-xs text-muted-foreground shrink-0",children:s.date||"Just now"})]}),(0,l.jsx)("div",{className:"flex items-center gap-1 shrink-0",children:s.id?g?(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)("button",{className:"p-1 text-muted-foreground hover:text-foreground",onClick:()=>o(e=>({...e,editing:!e.editing,updatedComment:s.content})),children:a.editing?(0,l.jsx)(e_.A,{size:14}):(0,l.jsx)(e5.A,{size:14})}),0!==s.id&&(0,l.jsx)("button",{className:"p-1 text-red-500",onClick:()=>{confirm("Are you sure you want to delete this comment?")&&(d(e=>{let t={...e.comments};return delete t[s.id],{...e,comments:t,comment_count:e.comment_count-1}}),fetch("".concat("https://api.sociallibra.com/wp-json/social_libra/v2","/comments/").concat(s.id),{method:"DELETE",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(m.token)}}).catch(console.error))},children:(0,l.jsx)(W.A,{size:14})})]}):null:(0,l.jsx)(e2.A,{className:"w-4 h-4 animate-spin"})})]}),p&&(0,l.jsxs)("span",{className:"text-xs text-muted-foreground bg-muted px-2 py-0.5 rounded-full self-start",children:["re: ",p]}),a.editing?(0,l.jsx)(e6,{comment:a.updatedComment,noUpdate:f,handleUpdate:e=>{e.preventDefault(),d(e=>({...e,comments:{...e.comments,[s.id]:{...s,content:a.updatedComment}}})),o(e=>({...e,editing:!1})),fetch("".concat("https://api.sociallibra.com/wp-json/social_libra/v2","/comments/").concat(s.id),{method:"PUT",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(m.token)},body:JSON.stringify({content:a.updatedComment})}).catch(console.error)},changeComment:e=>o(t=>({...t,updatedComment:e.target.value}))}):(0,l.jsx)("p",{className:"text-sm whitespace-pre-line",dangerouslySetInnerHTML:{__html:s.content}}),s.id>0&&(0,l.jsx)(e4,{commentId:s.id,votes:s.votes,onVote:e=>{if(!m.id)return;let t="user_".concat(m.id);d(l=>{let r=l.comments[s.id];return r?{...l,comments:{...l.comments,[s.id]:{...r,votes:{...r.votes,[t]:{score:e.score,comment:e.comment,public:e.public}}}}}:l})}})]})}var e9=s(97998),e7=s(5937);function te(){var e,t;let{currentFrame:s,setFrameState:a}=(0,r.useContext)(i.t),{user:o}=(0,r.useContext)(n.Rs),c=async()=>{if(!o.id)return;let e=String(o.id);a(t=>{let s=t.likedBy||[],l=s.includes(e);return{...t,likedBy:l?s.filter(t=>t!==e):[...s,e]}}),await fetch("".concat("https://api.sociallibra.com/wp-json/social_libra/v2","/like_frame/").concat(s.id),{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(o.token)}}).then(e=>e.ok).catch(()=>!1)||a(t=>{let s=t.likedBy||[],l=s.includes(e);return{...t,likedBy:l?s.filter(t=>t!==e):[...s,e]}})},d=null==(e=s.likedBy)?void 0:e.includes(String(o.id)),u=(null==(t=s.likedBy)?void 0:t.length)||0;return o.id?(0,l.jsxs)("button",{className:(0,p.cn)("flex items-center gap-1 text-sm px-2",d?"text-blue-400":"text-muted-foreground"),onClick:c,children:[(0,l.jsx)(e9.gb0,{}),u>0&&(0,l.jsx)("span",{children:u})]}):null}let tt=()=>{let e=(0,r.useRef)(null),{currentFrame:t,setFrameState:s}=(0,r.useContext)(i.t),{framesData:a}=(0,r.useContext)(i.m),{eventsData:o}=(0,r.useContext)(n.Pc),{user:c}=(0,r.useContext)(n.Rs),[d,u]=(0,r.useState)("all");(0,r.useEffect)(()=>{o&&Object.values(o.events).forEach(e=>{e.context==="sf_"+t.id&&("new_comment"===e.type&&s(t=>t.comments[e.data.id]?t:{...t,comment_count:t.comment_count+1,comments:{...t.comments,[e.data.id]:e.data}}),"delete_comment"===e.type&&s(t=>{let s={...t.comments};return delete s[e.data.id],{...t,comment_count:e.data.count,comments:s}}),"edit_comment"===e.type&&s(t=>{let s={...t.comments};return s[e.data.id].content=e.data.content,{...t,comments:s}}))})},[o]),(0,r.useEffect)(()=>{var t;null==(t=e.current)||t.scrollIntoView({behavior:"smooth",block:"nearest"})},[t.newComments]);let m=Object.keys(t.comments||{}),x=Object.keys(t.newComments||{}),h=Array.from(new Set(m.map(e=>{var s;return null==(s=t.comments[e])?void 0:s.article}).filter(e=>!!e))).map(e=>{var t;return{id:String(e),title:(null==a||null==(t=a.articles["sfa_".concat(e)
1])?void 0:t.title)||"Article ".concat(e)}}),p=m.filter(e=>{let s=t.comments[e];return"all"===d||("frame"===d?!s.article:String(s.article)===d)}),g=0===p.length&&0===x.length;return(0,l.jsxs)("div",{className:"flex flex-col gap-3 p-4",children:[h.length>0&&(0,l.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[(0,l.jsx)("span",{children:"Show:"}),(0,l.jsxs)("select",{className:"border rounded px-2 py-1 text-xs bg-background text-foreground",value:d,onChange:e=>u(e.target.value),children:[(0,l.jsx)("option",{value:"all",children:"All comments"}),(0,l.jsx)("option",{value:"frame",children:"Frame only"}),h.map(e=>(0,l.jsx)("option",{value:e.id,children:e.title},e.id))]})]}),c.id>0?(0,l.jsx)(e1,{}):(0,l.jsxs)("div",{className:"border rounded-lg p-4 text-center space-y-3",children:[(0,l.jsx)("p",{className:"text-muted-foreground text-sm",children:"Log in to join the discussion"}),(0,l.jsx)(P.default,{})]}),x.map((e,s)=>(0,l.jsx)(e8,{comment:t.newComments[e]},"new-"+s)),g?(0,l.jsx)("p",{className:"text-center text-muted-foreground py-6 text-sm",children:"No comments yet. Be the first!"}):p.map(e=>(0,l.jsx)(e8,{comment:t.comments[e]},e)),(0,l.jsx)("div",{ref:e})]})};function ts(){let{currentFrame:e}=(0,r.useContext)(i.t),t=e.comment_count||0;return(0,l.jsxs)(G,{children:[(0,l.jsx)(X,{asChild:!0,children:(0,l.jsxs)("button",{className:"flex items-center gap-1.5 text-sm text-muted-foreground hover:text-foreground px-2 transition-colors",children:[(0,l.jsx)(e7.A,{className:"w-4 h-4"}),t>0&&(0,l.jsx)("span",{className:"text-xs font-semibold",children:t})]})}),(0,l.jsxs)(es,{className:"max-h-[85vh] flex flex-col",children:[(0,l.jsxs)(el,{className:"flex flex-row justify-between items-center px-4 pt-2 pb-0",children:[(0,l.jsx)(ea,{className:"text-base",children:t>0?"Comments (".concat(t,")"):"Comments"}),(0,l.jsx)(ee,{asChild:!0,children:(0,l.jsx)("button",{className:"text-muted-foreground hover:text-foreground p-1",children:(0,l.jsx)(e_.A,{className:"w-4 h-4"})})})]}),(0,l.jsx)("div",{className:"overflow-y-auto flex-1 pb-4",children:(0,l.jsx)(tt,{})})]})]})}function tl(){var e,t,s,a,o;let{currentFrame:c,setFrameState:d}=(0,r.useContext)(i.t),u=c.selectedArticles[4]&&(null==(e=c.aiArticles)?void 0:e.articles)?null==(t=c.aiArticles)?void 0:t.articles[c.selectedArticles[4]]:null,m=!!c.selectedArticles[4],x=c.selectedArticles[6]&&(null==(s=c.aiArticles)?void 0:s.articles)?null==(a=c.aiArticles)?void 0:a.articles[c.selectedArticles[6]]:null,h=!!c.selectedArticles[6],g=eT("(min-width: 640px)"),f=()=>{d(e=>{let t={...e.selectedArticles};return t[4]="",{...e,selectedArticles:t}})},j=()=>{d(e=>{let t={...e.selectedArticles};return t[6]="",{...e,selectedArticles:t}})},{user:b}=(0,r.useContext)(n.Rs),[v,N]=(0,r.useState)({isLoading:!0,error:"",openArticle:!1,loaded:!1}),w=c.topics,y=c.searchTerms,k=b.token,C=async()=>{if(!y.length&&!w.length)return void N(e=>({...e,isLoading:!1,error:"No topics or search terms selected for this frame."}));N(e=>({...e,isLoading:!0,error:""}));let e=null;e={method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(k)},body:JSON.stringify({frame:c.id||c,return:"articles"})};try{let t=await fetch("".concat("https://api.sociallibra.com/wp-json/social_libra/v2","/ai_suggestions"),e);if(!t.ok)throw Error("HTTP error! Status: ".concat(t.status));let s=await t.json();if(!p.Fh)return;if(s.error){let e=s.error||"An error occurred.";N(t=>({...t,isLoading:!1,error:e}));return}d(e=>({...e,aiArticles:s})),N(e=>({...e,isLoading:!1}))}catch(e){N(t=>({...t,isLoading:!1,error:e.message}))}};if((0,r.useEffect)(()=>{(!v.loaded||c.aiArticles)&&C()},[w,y,k]),v.isLoading)return(0,l.jsx)(z.A,{});if(v.error)return(0,l.jsx)("p",{className:"text-red-400 font-bold text-lg text-center",children:v.error});let S=null==(o=c.aiArticles)?void 0:o.articles;if(!S||!Object.keys(S).length)return(0,l.jsx)("p",{className:"text-red-400 font-bold text-lg text-center",children:"No articles found for this topic."});let A=b.id>0?(0,l.jsx)(K,{minimal:!0,className:"w-full bg-background p-1 flex justify-stretch"}):(0,l.jsxs)("div",{children:[(0,l.jsx)("p",{children:"You must be logged in to vote on articles."}),(0,l.jsx)(eF,{})]});return(0,l.jsxs)("div",{className:"py-4",children:[(0,l.jsx)("ul",{className:"grid gap-4 grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4",children:S&&Object.keys(S).map(e=>{let t=S[e];return(0,l.jsx)(eS,{article:t},e)})}),u&&m?(0,l.jsx)(eN.Provider,{value:{currentArticle:u},children:g?(0,l.jsxs)(R.A,{onClose:f,className:"sm:w-[480px]",children:[(0,l.jsx)("h3",{className:"text-center p-1 text-lg sm:text-2xl font-bold",children:u.title}),A,(0,l.jsx)(eA,{className:"w-[90%] m-auto mt-3",index:4})]}):(0,l.jsx)(G,{open:m,onOpenChange:e=>{e||f()},children:(0,l.jsxs)(es,{className:"max-h-screen justify-center",children:[(0,l.jsxs)(el,{className:"flex flex-col p-1 justify-center",children:[(0,l.jsx)(ea,{className:"text-center p-1 text-lg sm:text-2xl font-bold",children:u.title}),(0,l.jsx)(ee,{className:"absolute top-2 right-2",asChild:!0,children:(0,l.jsx)(e_.A,{})})]}),A,(0,l.jsx)(er,{children:(0,l.jsx)(eA,{className:"w-[90%] m-auto",index:4})})]})})}):null,x&&h?(0,l.jsx)(eN.Provider,{value:{currentArticle:x},children:(()=>{let e=(0,l.jsxs)("div",{className:"flex flex-col sm:flex-row h-[50vh] p-2 sm:gap-3 overflow-y-scroll",children:[x.images.medium?(0,l.jsx)(eC.default,{src:x.images.medium,width:300,height:300,onError:e=>{e.currentTarget.src="/images/default-article.jpg"},alt:x.title,className:"h-36 w-36 object-contain bg-foreground shrink-0"}):null,(0,l.jsxs)("div",{className:"flex flex-col gap-2 w-full",children:[x.url&&(0,l.jsxs)("button",{onClick:()=>
1(0,p.zL)(x.url),className:"text-xs sm:text-sm text-foreground bg-background p-1 m-1 self-start underline",children:["Read on ",x.source]}),(0,l.jsx)(ep,{content:x.content})]})]});return g?(0,l.jsxs)(R.A,{onClose:j,className:"sm:w-3/5",children:[(0,l.jsx)("h3",{className:"text-center p-1 text-lg sm:text-2xl font-bold",children:x.title}),e]}):(0,l.jsx)(G,{open:h,onOpenChange:e=>{e||j()},children:(0,l.jsxs)(es,{className:"max-h-screen justify-center",children:[(0,l.jsxs)(el,{className:"flex flex-col p-1 justify-center",children:[(0,l.jsx)(ea,{className:"text-center p-1 text-lg sm:text-2xl font-bold",children:x.title}),(0,l.jsx)(ee,{className:"absolute top-2 right-2",asChild:!0,children:(0,l.jsx)(e_.A,{})})]}),e]})})})()}):null]})}var tr=s(5917);let ta=()=>{let{currentFrame:e,setFrameState:t}=(0,r.useContext)(i.t),[s,a]=(0,r.useState)(!1),[n,o]=(0,r.useState)(!1),c=e.slug?e.slug.length:0;return e.slug&&e.canEdit?(0,l.jsxs)("p",{className:"mt-0 inline-block font-bold w-full",children:[(0,l.jsx)("span",{children:"https://www.sociallibra.com/story-frame/"}),s?(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)("label",{htmlFor:"frame-slug",className:"",children:"Frame URL Slug"}),(0,l.jsx)("input",{maxLength:130,className:"resize-none overflow-hidden w-full max-w-sm",value:e.slug?e.slug:(0,p.Yv)(e.title),placeholder:"Story Frame Slug",onFocus:()=>o(!0),onBlur:()=>o(!1),onChange:e=>{t(t=>{let s=e.target.value?(0,p.Yv)(e.target.value):(0,p.Yv)(t.title);return{...t,slug:s,updated:!0}})}}),(0,l.jsx)(tr.A,{className:"inline ms-2 cursor-pointer text-sm",onClick:()=>a(!1)}),c>130&&(0,l.jsx)("span",{className:"self-end text-sm text-red-500",children:" Slug is too long"}),c>0&&n&&(0,l.jsxs)("span",{className:"self-end text-sm ",children:[" ",c,"/",130]})]}):(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)("span",{children:e.slug}),(0,l.jsx)(eO.A,{className:"inline ms-2 cursor-pointer text-sm",onClick:()=>a(!0)})]})]}):null};var tn=s(73850),ti=s(73697),to=s(48716),tc=s(77568);function td(e){let{title:t,segments:s,emptyLabel:r}=e,a=s.reduce((e,t)=>e+t.value,0);return(0,l.jsxs)("div",{className:"space-y-2",children:[(0,l.jsx)("h4",{className:"text-sm font-semibold",children:t}),0===a?(0,l.jsx)("p",{className:"text-xs text-muted-foreground",children:r}):(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)("div",{className:"flex gap-0.5 h-8 w-full overflow-hidden rounded",children:s.map(e=>{let t=e.value/a*100;return t<=0?null:(0,l.jsx)("div",{className:"h-full flex items-center justify-center text-[11px] font-semibold text-white",style:{width:"".concat(t,"%"),backgroundColor:e.color},title:"".concat(e.label,": ").concat(e.value," (").concat(Math.round(t),"%)"),children:t>=18?"".concat(e.value," (").concat(Math.round(t),"%)"):null},e.key)})}),(0,l.jsx)("div",{className:"flex flex-wrap gap-x-4 gap-y-1",children:s.map(e=>(0,l.jsxs)("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[(0,l.jsx)("span",{className:"inline-block w-2.5 h-2.5 rounded-sm shrink-0",style:{backgroundColor:e.color}}),(0,l.jsx)("span",{className:"text-foreground",children:e.label}),(0,l.jsx)("span",{children:e.value})]},e.key))})]})]})}function tu(e){let{label:t,value:s}=e;return(0,l.jsxs)("div",{className:"flex flex-col items-center gap-0.5 border rounded-md px-3 py-2 flex-1 min-w-[90px]",children:[(0,l.jsx)("span",{className:"text-lg font-semibold",children:s.toLocaleString()}),(0,l.jsx)("span",{className:"text-[11px] text-muted-foreground text-center",children:t})]})}let tm={score:{label:"Libra Score",color:"hsl(var(--foreground))"}};function tx(){let e=(0,a.c)("FrameAnalytics"),{currentFrame:t}=(0,r.useContext)(i.t),{framesData:s}=(0,r.useContext)(i.m),n=t.ranks&&3===t.ranks.length?t.ranks:["","Neutral",""],o=t.articles||[],{voteCounts:c,articleCounts:d,totalVotes:u}=(0,r.useMemo)(()=>{var e,s,l,r;let a=[0,0,0],n=0;for(let l of o){let r=null==(e=t.votes)?void 0:e[l];if(r)for(let e in r){let t=Number(null==(s=r[e])?void 0:s.score);!Number.isNaN(t)&&(a[(0,ec.K5)(t)]++,n++)}}let i=[0,0,0];for(let e of o){let s=null==(r=t.scores)||null==(l=r[e])?void 0:l.rank;i[0===s||2===s?s:1]++}return{voteCounts:a,articleCounts:i,totalVotes:n}},[o,t.votes,t.scores]),{sourceCounts:m,totalSources:x}=(0,r.useMemo)(()=>{let e=[new Set,new Set,new Set],l=new Set;for(let c of o){var r,a,n,i;let o=null==s||null==(a=s.articles)||null==(r=a[c])?void 0:r.source;if(!o)continue;l.add(o);let d=null==(i=t.scores)||null==(n=i[c])?void 0:n.rank;e[0===d||2===d?d:1].add(o)}return{sourceCounts:e.map(e=>e.size),totalSources:l.size}},[o,t.scores,null==s?void 0:s.articles]),h=(0,r.useMemo)(()=>{let e=[];for(let r of o){var s,l;let a=null==(l=t.scores)||null==(s=l[r])?void 0:s.history;
1if(a)for(let t of a)(null==t?void 0:t.timestamp)&&e.push({timestamp:t.timestamp,score:t.score,votes:t.votes,articleKey:r})}e.sort((e,t)=>new Date(e.timestamp).getTime()-new Date(t.timestamp).getTime());let r={},a=[];for(let t of e){r[t.articleKey]={score:t.score,votes:t.votes};let e=0,s=0;for(let t in r)e+=r[t].score*r[t].votes,s+=r[t].votes;a.push({timestamp:t.timestamp,score:s>0?Math.round(e/s*10)/10:0})}return a},[o,t.scores]),p=["#3B82F6","hsl(var(--muted-foreground))","#DC2626"],g=n.map((t,s)=>({key:"vote-".concat(s),label:t||e("unlabeled"),value:c[s],color:p[s]})),b=n.map((t,s)=>({key:"article-".concat(s),label:t||e("unlabeled"),value:d[s],color:p[s]})),v=n.map((t,s)=>({key:"source-".concat(s),label:t||e("unlabeled"),value:m[s],color:p[s]}));return(0,l.jsxs)("div",{className:"flex flex-col gap-5 py-2",children:[(0,l.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,l.jsx)(tu,{label:e("totalArticles"),value:o.length}),(0,l.jsx)(tu,{label:e("totalSources"),value:x}),(0,l.jsx)(tu,{label:e("totalVotes"),value:u}),(0,l.jsx)(tu,{label:e("totalComments"),value:t.comment_count||0})]}),(0,l.jsxs)("div",{className:"space-y-2",children:[(0,l.jsx)("h4",{className:"text-sm font-semibold",children:e("scoreOverTime")}),0===h.length?(0,l.jsx)("p",{className:"text-xs text-muted-foreground",children:e("noHistoryYet")}):(0,l.jsx)(S,{config:tm,className:"aspect-auto h-[180px] w-full",children:(0,l.jsxs)(tn.Q,{data:h,margin:{left:12,right:12},children:[(0,l.jsx)(f.d,{vertical:!1}),(0,l.jsx)(j.W,{dataKey:"timestamp",tickLine:!1,axisLine:!1,tickMargin:8,tickFormatter:e=>new Date(e).toLocaleDateString(void 0,{month:"short",day:"numeric"})}),(0,l.jsx)(ti.h,{domain:[-100,100],tickLine:!1,axisLine:!1,width:32}),(0,l.jsx)(to.e,{y:0,stroke:"hsl(var(--border))"}),(0,l.jsx)(_,{content:(0,l.jsx)(F,{labelFormatter:e=>new Date(e).toLocaleString()})}),(0,l.jsx)(tc.G,{dataKey:"score",type:"monotone",fill:"var(--color-score)",fillOpacity:.15,stroke:"var(--color-score)"})]})})]}),(0,l.jsx)(td,{title:e("voteDistribution"),segments:g,emptyLabel:e("noVotesYet")}),(0,l.jsx)(td,{title:e("articlesByPerspective"),segments:b,emptyLabel:e("noArticlesYet")}),(0,l.jsx)(td,{title:e("sourcesByPerspective"),segments:v,emptyLabel:e("noSourcesYet")})]})}let th=e=>{var t;let{editing:s="",currentFrame:o,opened:c=!1,onEdit:u=()=>{},onFrameChange:x,list:h=!1,initialArticleUrl:p,creationStep:g}=e,f=(0,a.c)("Frame"),[j,b]=(0,r.useState)(o);(0,r.useEffect)(()=>{null==x||x(j)},[j]);let v=(0,eJ.useParams)(),N="string"==typeof v.section?v.section:"articles",w=j.tab||N,{user:y}=(0,r.useContext)(n.Rs);(0,eQ.a8)();let k=async()=>{try{let e=await fetch("".concat("https://api.sociallibra.com/wp-json/social_libra/v2","/ai_suggestions"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(y.token)},body:JSON.stringify({frame:j,return:"ranks"})}),t=await e.json();if(!e.ok||t.error||!t.ranks)return;b(e=>({...e,rankSuggestions:t.ranks}))}catch(e){}};(0,r.useEffect)(()=>{var e;j.new&&j.title&&(null==(e=j.topics)?void 0:e.length)&&!j.rankSuggestions.length&&k()},[j.new,j.title,null==(t=j.topics)?void 0:t.length,j.rankSuggestions.length]);let C=async function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"draft",t={frame:{...j,status:e}},s=j.guid;b(t=>({...t,loading:!0,guid:"",status:e,error:void 0}));try{let e=await fetch("".concat("https://api.sociallibra.com/wp-json/social_libra/v2","/story_frames"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(y.token)},body:JSON.stringify(t)}),s=await e.json();if(!e.ok)throw Error(s&&s.message||"Failed to save Story Frame. Please try again.");s?(b(e=>({...e,id:s,saved:!0,loading:!1,updated:!1})),u({...j,id:s})):b(e=>({...e,loading:!1}))}catch(e){b(t=>({...t,loading:!1,error:e.message||"Something went wrong. Please try again.",guid:s}))}},{framesData:S,setFramesData:A}=(0,r.useContext)(i.m),_=(null==S?void 0:S.currentFrame)||"";(0,r.useEffect)(()=>{b(e=>({...e,rssLoaded:!1}))},[y.token]);let F=j.ranks&&3===Object.keys(j.ranks).length&&Object.values(j.ranks).every(e=>""!==e),T=j.title&&j.topics&&j.topics.length>0,E=!!j.articles&&Object.keys(j.articles).length>0,L=()=>{A(e=>({...e,currentFrame:j.slug}))},O="author"===y.role,P=(0,r.useRef)(null);return(j.opened=j.slug===_||c,j.new&&g&&"publish"!==g)?(0,l.jsx)(i.t.Provider,{value:{currentFrame:j,setFrameState:b},children:(0,l.jsxs)("div",{className:"p-4 space-y-4",children:[j.loading&&(0,l.jsx)(z.A,{}),j.error&&!j.loading&&(0,l.jsx)("p",{className:"text-red-600 text-sm",children:j.error}),j.saved&&!j.loading&&!j.updated&&(0,l.jsx)("p",{className:"text-green-800 text-sm",children:"Frame Saved"}),"topics"===g&&(0,l.jsx)(d,{}),"ranks"===g&&(0,l.jsx)(eL,{full:!1,clickable:!1}),"rss"===g&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(m,{}),(0,l.jsx)(eE,{})]}),"articles"===g&&(0,l.jsx)("div",{className:"flex flex-col gap-3 py-2",children:j.id?(0,l.jsx)(eU,{buttonText:"Add Article",initialUrl:p}):(0,l.jsxs)("div",{className:"text-center space-y-3 py-6",children:[(0,l.jsx)("p",{className:"text-muted-foreground",children:f("saveFrameFirst")}),T&&F&&(0,l.jsx)(M.$,{onClick:()=>C("draft"),children:f("saveFrame")})]})})]})}):(0,l.jsx)(i.t.Provider,{value:{currentFrame:j,setFrameState:b},children:(0,l.jsxs)("div",{ref:P,className:"group story-frame w-full bg-background relative shadow-secondary shadow-lg mt-10 scroll-m-10 border rounded-md",children:[j.new?null:(0,l.jsx)(e$,{children:j.opened&&!c&&h?(0,l.jsx)("button",{title:"Close Frame",onClick:()=>{A(e=>({...e,currentFrame:""}))},children:(0,l.jsx)(e_.A,{})}):null}),j.editing&&!j.loading&&T&&!O&&(0,l.jsxs)("p",{className:"text-xs text-muted-foreground text-center mb-2 px-4",children:["publish"===j.status?f("publishedVisibilityNote"):f("draftVisibilityNote")," ",(0,l.jsx)(eQ.N_,{href:"/account/subscription",className:"underline",children:f("becomeInfluencer")})," ",f("toReachPublicFeeds")]}),(0,l.jsxs)("div",{className:"flex flex-col items-center gap-2 mb-2 w-full z-[100000]",children:[(0,l.jsxs)("div",{className:"flex justify-center gap-2 w-full",children:[!j.saved||j.loading||j.updated?null:(0,l.jsx)("p",{className:"text-green-800 bg-background py-3 px-2 me-2",children:"publish"===j.status?"Frame Published Successfully":"Frame Saved Successfully"}),j.error&&!j.loading?(0,l.jsx)("p",{className:"text-red-600 bg-background py-3 px-2 me-2",children:j.error}):null,j.loading?(0,l.jsx)(z.A,{}):null,j.editing&&!j.loading?(0,l.jsxs)(l.Fragment,{children:[T&&F&&(0,l.jsx)(M.$,{variant:"default",onClick:()=>{C()},children:"publish"==j.status?"Revert to Draft":"Save Progress"}),E&&T&&F&&(0,l.jsx)(M.$,{className:"btn-primary",onClick:()=>{C("publish")},children:"publish"==j.status?"Save Changes":"Publish"})]}):null]}),j.saved&&!j.loading&&!j.updated&&"publish"===j.status&&j.slug&&(0,l.jsx)(M.$,{variant:"outline",onClick:()=>{let e="".concat("https://www.sociallibra.com/","/story-frame/").concat(j.slug);navigator.clipboard.writeText(e),en.toast.success(f("linkCopied"))},children:"Copy Link to Share"})]}),j.opened||j.new?(0,l.jsxs)("div",{className:"relative",children:[T&&F&&j.id?(0,l.jsxs)("div",{className:"flex flex-row h-12 items-stretch",children:[(0,l.jsx)("div",{className:"flex flex-1",children:[{name:"articles",label:"Articles",icon:"newspaper"},{name:"rss",label:"RSS",icon:"rss"},{name:"ai",label:"AI (beta)",icon:"microchip-ai"},{name:"analytics",label:"Analytics",icon:"bar-chart"}].map(e=>(0,l.jsxs)("button",{title:e.label,className:"flex flex-col justify-center items-center flex-1 text-xs sm:text-sm ".concat(w===e.name?"bg-primary text-background":"bg-background text-foreground"),onClick:()=>b(t=>({...t,tab:e.name})),children:["rss"===e.name?(0,l.jsx)(eH.A,{className:"w-4 h-4"}):"ai"===e.name?(0,l.jsx)(eG.A,{className:"w-4 h-4"}):"articles"===e.name?(0,l.jsx)(eX.A,{className:"w-4 h-4"}):"analytics"===e.name?(0,l.jsx)(eZ.A,{className:"w-4 h-4"}):null,(0,l.jsx)("span",{children:e.label})]},e.name))}),(0,l.jsxs)("div",{className:"flex items-center border-l",children:[(0,l.jsx)(ts,{}),(0,l.jsx)(te,{})]})]}):null,(0,l.jsxs)("div",{className:"p-4",children:[(0,l.jsx)("div",{className:"flex flex-row justify-between",children:(0,l.jsx)(eY,{})}),(0,l.jsx)("div",{className:"flex flex-row justify-between",children:(0,l.jsx)(ta,{})}),(0,l.jsx)("div",{className:"flex flex-col md:flex-row md:justify-between md:items-start mb-4",children:(0,l.jsx)(eq,{className:"w-1/2"})}),j.new&&(0,l.jsx)("div",{className:"my-4",children:(0,l.jsx)(eK,{})}),(0,l.jsx)(d,{}),(0,l.jsx)("div",{className:"w-full flex flex-col",children:"articles"===w?(0,l.jsx)(eL,{full:!0}):"rss"===w?(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(m,{}),(0,l.jsx)(eE,{})]}):"analytics"===w?(0,l.jsx)(tx,{}):(0,l.jsx)(tl,{})})]})]}):(0,l.jsxs)("div",{className:"p-4 md:flex md:flex-row md:gap-8",children:[(0,l.jsxs)("div",{className:"md:w-3/4",children:[(0,l.jsx)(eY,{}),(0,l.jsx)(d,{}),(0,l.jsx)(eK,{}),(0,l.jsx)(eL,{full:!0}),(0,l.jsx)(eq,{className:"block md:hidden"}),T&&(0,l.jsx)("div",{className:"w-full flex flex-row justify-between gap-2 my-5",children:j.new&&(0,l.jsx)("button",{className:"btn-primary block md:hidden ms-auto",onClick:L,children:"Open"})})]}),(0,l.jsxs)("div",{className:"hidden md:flex md:w-1/4 flex-col md:items-end justify-between gap-5",children:[(0,l.jsx)(eq,{className:"md:text-end"}),!j.new&&(0,l.jsx)("button",{className:"btn-primary",onClick:L,children:"Open"})]})]}),y.id>0?(0,l.jsx)(l.Fragment,{children:F&&j.id?(0,l.jsx)("div",{className:"flex flex-col gap-2 p-4",children:(0,l.jsx)(eU,{buttonText:"Add Article ",initialUrl:p})}):null}):null]})})}},70925:(e,t,s)=>{"use strict";s.d(t,{A:()=>g});var l=s(95155),r=s(12115),a=s(32382),n=s(63523),i=s(42409),o=s(60353),c=s(11010),d=s(5917),u=s(33431),m=s(71537),x=s(64133),h=s(25016);let p=[{name:"title",label:"Title"},{name:"description",label:"Description"},{name:"topics",label:"Topics"},{name:"ranks",label:"Perspectives"},{name:"rss",label:"RSS"},{name:"articles",label:"Articles"},{name:"publish",label:"Publish"}];function g(){var e,t;
1let{initialTitle:s,initialDescription:g,initialArticleUrl:f,initialTopics:j,forceOpen:b=!1}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},v={frame:s||(null==j?void 0:j.length)?{...o.emptyFrame,title:s||"",description:g||"",topics:j||[]}:o.emptyFrame,showForm:b,step:2*!!s,aiDescription:"",descriptionError:"",titleError:"",useAI:!1,loadingPreview:!1},{user:N}=(0,r.useContext)(i.Rs),[w,y]=(0,r.useState)(v),k=async()=>{let e=w.aiDescription.trim();if(!e)return void y(e=>({...e,descriptionError:"Please enter a description for the Story Frame."}));y(e=>({...e,loadingPreview:!0,descriptionError:""}));try{let t=await fetch("".concat("https://api.sociallibra.com/wp-json/social_libra/v2","/story_frames/ai_preview"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(N.token)},body:JSON.stringify({description:e})}),s=await t.json();if(!t.ok)throw Error(s&&s.message||"Failed to generate a Story Frame preview. Please try again.");y(t=>({...t,frame:{...t.frame,...s||{},title:t.frame.title||e,generated:!0},step:s?2:1,loadingPreview:!1}))}catch(e){y(t=>({...t,loadingPreview:!1,descriptionError:e.message||"Something went wrong. Please try again."}))}},C=()=>y(e=>({...e,step:Math.max(0,e.step-1)})),S=()=>y(e=>({...e,step:Math.min(p.length-1,e.step+1)})),A=w.step,_=w.step===p.length-1,F=!!w.frame.ranks&&3===w.frame.ranks.length&&w.frame.ranks.every(e=>""!==e.trim());return(0,l.jsxs)(l.Fragment,{children:[!b&&(0,l.jsx)("button",{title:"Add Story Frame",onClick:()=>y(e=>({...e,showForm:!0})),className:"btn-primary w-fit border rounded-md fixed bottom-5 end-2 z-50",children:(0,l.jsx)(c.A,{className:"inline-block w-5 h-5 ms-1"})}),w.showForm?(0,l.jsxs)(a.A,{className:"w-full sm:w-2/3",onClose:()=>y(e=>({...e,showForm:!1})),children:[w.step>0&&(0,l.jsxs)("div",{className:"sm:w-2/3 m-auto mb-6 px-4 sm:px-0",children:[(0,l.jsx)("div",{className:"flex items-center",children:p.map((e,t)=>(0,l.jsxs)("div",{className:(0,h.cn)("flex items-center",t<p.length-1&&"flex-1"),children:[(0,l.jsx)("span",{className:(0,h.cn)("flex items-center justify-center w-6 h-6 rounded-full text-xs font-semibold shrink-0 transition-colors",t<A&&"bg-primary text-background",t===A&&"bg-primary text-background ring-4 ring-primary/20",t>A&&"bg-muted text-muted-foreground"),children:t<A?(0,l.jsx)(d.A,{className:"w-3.5 h-3.5"}):t+1}),t<p.length-1&&(0,l.jsx)("span",{className:(0,h.cn)("flex-1 h-0.5 mx-1",t<A?"bg-primary":"bg-muted")})]},e.name))}),(0,l.jsxs)("p",{className:"text-center text-sm font-medium mt-2",children:["Step ",A+1," of ",p.length,": ",p[A].label]})]}),w.loadingPreview&&(0,l.jsx)(x.A,{}),0===w.step&&!w.loadingPreview&&(0,l.jsxs)("div",{className:"p-4 space-y-4",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-sm font-medium mb-2",children:"Give Your Frame a Title"}),(0,l.jsx)(m.p,{value:w.frame.title,onChange:e=>{var t;return t=e.target.value,void y(e=>{let s=e.frame.slug&&e.frame.slug!==(0,h.Yv)(e.frame.title)?e.frame.slug:(0,h.Yv)(t);return{...e,titleError:"",frame:{...e.frame,title:t,slug:s}}})},type:"text",placeholder:"Enter a title"}),w.titleError&&(0,l.jsx)("p",{className:"text-sm text-red-500 mt-1",children:w.titleError})]}),w.useAI?(0,l.jsxs)("div",{className:"space-y-2",children:[(0,l.jsx)("label",{className:"block text-sm font-medium",children:"What is the Story Frame about"}),(0,l.jsx)(m.p,{value:w.aiDescription,onChange:e=>y(t=>({...t,aiDescription:e.target.value,descriptionError:""})),type:"text",placeholder:"Enter description"}),w.descriptionError&&(0,l.jsx)("p",{className:"text-sm text-red-500",children:w.descriptionError}),(0,l.jsx)(u.$,{onClick:e=>{e.preventDefault(),k()},className:"btn-primary",children:"Generate with AI"})]}):(0,l.jsx)("button",{type:"button",className:"text-sm underline text-blue-600 dark:text-blue-500",onClick:()=>y(e=>({...e,useAI:!0})),children:"Need help? Describe your story and let AI suggest a title"}),(0,l.jsx)(u.$,{onClick:e=>{if(e.preventDefault(),!w.frame.title.trim())return void y(e=>({...e,titleError:"Please enter a title for your Story Frame."}));y(e=>({...e,step:1}))},className:"btn-primary",children:"Next"})]}),1===w.step&&!w.loadingPreview&&(0,l.jsxs)("div",{className:"p-4 space-y-4",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-sm font-medium mb-2",children:"Frame Description"}),(0,l.jsx)("textarea",{className:"w-full border rounded p-2 bg-background text-foreground",rows:4,placeholder:"Describe what this Story Frame is about",value:w.frame.description,onChange:e=>y(t=>({...t,frame:{...t.frame,description:e.target.value}}))})]}),(0,l.jsxs)("div",{className:"flex gap-2",children:[(0,l.jsx)(u.$,{variant:"outline",onClick:C,children:"Back"}),(0,l.jsx)(u.$,{onClick:S,className:"btn-primary",children:"Next"})]})]}),w.step>=2&&!w.loadingPreview&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(n.default,{currentFrame:w.frame,initialArt
1icleUrl:f,creationStep:p[w.step].name,onFrameChange:e=>y(t=>({...t,frame:e}))}),(0,l.jsxs)("div",{className:"flex flex-col gap-2 p-4 border-t",children:["topics"===p[w.step].name&&!(null==(e=w.frame.topics)?void 0:e.length)&&(0,l.jsx)("p",{className:"text-sm text-red-500",children:"Please select at least one topic to continue."}),"ranks"===p[w.step].name&&!F&&(0,l.jsx)("p",{className:"text-sm text-red-500",children:"Please set all three perspective labels to continue."}),(0,l.jsxs)("div",{className:"flex gap-2",children:[(0,l.jsx)(u.$,{variant:"outline",onClick:C,children:"Back"}),!_&&(0,l.jsx)(u.$,{onClick:S,className:"btn-primary",disabled:"topics"===p[w.step].name&&!(null==(t=w.frame.topics)?void 0:t.length)||"ranks"===p[w.step].name&&!F,children:"Next"})]})]})]})]}):null]})}},71537:(e,t,s)=>{"use strict";s.d(t,{p:()=>n});var l=s(95155),r=s(12115),a=s(25016);let n=r.forwardRef((e,t)=>{let{className:s,type:r,...n}=e;return(0,l.jsx)("input",{type:r,className:(0,a.cn)("flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",s),ref:t,...n})});n.displayName="Input"},72921:(e,t,s)=>{"use strict";s.d(t,{A:()=>n});var l=s(95155),r=s(25016),a=s(15239);function n(e){var t;let{className:s="",user:n,width:i=80,height:o=80}=e,c=(t=null==n?void 0:n.avatar)?t=(t=(t=t.replace(/s=\d+/g,"s=300")).replace(/^http:/,"https:")).replace(/&.*/g,""):"/images/default-avatar.png";return(0,l.jsx)(a.default,{className:(0,r.cn)("rounded-full",s),src:c,width:i,height:o,alt:""})}}}]);
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.