1import{D as R,a as z,b as G,u as W,G as J,r as c,j as e,aa as X,ab as K,ac as Q,ad as Y,ae as u,c as A,C as Z,cs as ee,ah as H}from"./main-DX7XzkoU.js";import{B as T}from"./badge-BOGaWzi1.js";import{S as se}from"./skeleton-DN2cjZOe.js";import{T as te,a as ae,b as re}from"./tabs-BuRg9jtd.js";import{D as oe,a as ie,b as le,c as ne}from"./dropdown-menu-D6liHcXh.js";import{s as j}from"./untyped-client-BsKF0fUL.js";import{A as M}from"./AppHeader-CzkMBh75.js";import{P as q}from"./PageShell-Bd7x8hXC.js";import{P}from"./PageHeader-CM5sf6Dy.js";import{M as ce}from"./MobileBottomNav-B6c1hPKj.js";import{F as de}from"./filter-BMbwhTzt.js";import{I as y}from"./image-off-BUfV3N24.js";import{C as pe}from"./clock-DZY59rpR.js";import{U as me}from"./user-check-BR60HPjZ.js";import{A as ue}from"./archive-restore-D8eOAN1h.js";import{A as he}from"./archive-BQ6K3UDF.js";import{e as ge,p as xe}from"./pt-BR-g-tPW2Ip.js";import{f as ve}from"./format-kQpqiptj.js";import{P as fe,G as be}from"./panels-top-left-DM7gdoeV.js";import{I as _e}from"./image-play-FzvV3P2U.js";import{M as je}from"./megaphone-B0K-HV7w.js";import{V as ye}from"./video-BvJDFQSG.js";import{S as we}from"./smartphone-WGY3uvd5.js";import"./index-D6Z5KIMn.js";import"./chevron-right-D27HfhtL.js";import"./circle-BXmX70XD.js";import"./sheet-D4yLKOxB.js";import"./AppInstallBanner-CAnCi_kO.js";import"./CreateContentModal-eREkTihJ.js";import"./referral-code-CAIXjQN4.js";import"./lightbulb-UJa6zn96.js";import"./image-BBUOngQh.js";import"./palette-OTKsHiwO.js";import"./wand-sparkles-CwRAYUwy.js";import"./clapperboard-BoJYuZop.js";import"./layers-UGj9VXD5.js";import"./ThemeToggle-C5kzRcph.js";import"./monitor-MvsPdGOU.js";import"./routes-Dh-CjbFu.js";import"./history-BQ1iBcZd.js";import"./chart-no-axes-column-CL-SWzid.js";import"./link-D6mXMmG7.js";import"./settings-N25lzdMz.js";import"./circle-help-CV3y08qY.js";import"./user-x-BOA8xi05.js";import"./globe-BBWCCznd.js";import"./download-DFu9GkQ8.js";import"./useInstagramProfiles-D_KQvT_K.js";import"./instagram-uOX4SJX4.js";import"./plus-C6FQ2-b-.js";import"./arrow-left-Cf41rOjY.js";import"./gem-DGeoeC5P.js";import"./menu-B6sRxHFL.js";import"./link-2-CASnJw5r.js";import"./house-C4ToeB93.js";/** 2 * @license lucide-react v0.462.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const Ne=R("EllipsisVertical",[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"12",cy:"5",r:"1",key:"gxeob9"}],["circle",{cx:"12",cy:"19",r:"1",key:"lyex9k"}]]),Se=["pending","scheduled","processing","publishing"],ke=500,As=()=>{const b=z(),{t}=G(),{user:o}=W(),{selectedProfile:r}=J(),[m,g]=c.useState([]),[w,N]=c.useState(new Map),[D,S]=c.useState(!0),[x,E]=c.useState("pending"),[h,I]=c.useState("all"),k=c.useCallback(async()=>{if(!(!(o!=null&&o.id)||!(r!=null&&r.id))){S(!0),g([]),N(new Map);try{const{data:s,error:a}=await j.from("posts").select("id, title, thumbnail_url, slide_images, content_type, slides_count, status, created_at, approval_status, approval_revision_count, archived_at").eq("user_id",o.id).eq("instagram_profile_id",r.id).eq("status","completed").order("created_at",{ascending:!1}).limit(ke);if(a)throw a;const{data:d,error:l}=await j.from("scheduled_posts").select("post_id, status").eq("user_id",o.id).eq("instagram_profile_id",r.id).not("post_id","is",null);if(l)throw l;const p=new Map;for(const i of d??[]){const n=i.post_id;n&&(i.status==="published"?p.set(n,"published"):Se.includes(i.status)&&p.get(n)!=="published"&&p.set(n,"scheduled"))}g(s??[]),N(p)}catch(s){console.error("Erro ao carregar posts:",s)}finally{S(!1)}}},[o==null?void 0:o.id,r==null?void 0:r.id]);c.useEffect(()=>{o!=null&&o.id&&(r!=null&&r.id)&&k()},[o==null?void 0:o.id,r==null?void 0:r.id,k]);const v=c.useCallback(s=>w.get(s.id)??"pending",[w]),f=c.useMemo(()=>{const s={pending:0,scheduled:0,published:0,archived:0};for(const a of m)a.archived_at?s.archived+=1:s[v(a)]+=1;return s},[m,v]),C=c.useMemo(()=>m.filter(s=>{const a=!!s.archived_at;if(x==="archived"){if(!a)return!1}else if(a||v(s)!==x)return!1;return h==="none"?s.approval_status==null:h!=="all"?s.approval_status===h:!0}),[m,x,h,v]),V=async(s,a)=>{var p;const d=a?new Date().toISOString():null,l=((p=m.find(i=>i.id===s))==null?void 0:p.archived_at)??null;g(i=>i.map(n=>n.id===s?{...n,archived_at:d}:n));try{const{error:i}=await j.from("posts").update({archived_at:d}).eq("id",s);if(i)throw i;H.success(t(a?"postsHistory.archived_toast":"postsHistory.unarchived_toast"))}catch(i){console.error("Erro ao arquivar post:",i),H.error(t(a?"postsHistory.archive_error":"postsHistory.unarchive_error")),g(n=>n.map(_=>_.id===s?{..._,archived_at:l}:_))}},F=s=>{switch(s){case"carousel":return e.jsx(be,{className:"w-3 h-3"});case"story":case"story_sequence":return e.jsx(we,{className:"w-3 h-3"});case"reel":return e.jsx(ye,{className:"w-3 h-3"});case"ad":return e.jsx(je,{className:"w-3 h-3"});case"reel_cover":return e.jsx(_e,{className:"w-3 h-3"});case"post":default:return e.jsx(fe,{className:"w-3 h-3"})}},L=s=>{switch(s){case"carousel":return t("postSuggestions.carousel");case"story":return t("postSuggestions.story");case"story_sequence":return t("postSuggestions.story_sequence");case"reel":return t("postSuggestions.reel");case"ad":return t("adCreator.badge");case"reel_cover":return t("create.reel_cover");case"post":default:return t("postSuggestions.post")}},U=s=>{const a=ee.language==="en"?ge:xe;return ve(new Date(s),"dd/MM/yyyy HH:mm",{locale:a})},B=s=>s.thumbnail_url?s.thumbnail_url:s.slide_images&&s.slide_images.length>0?s.slide_images[0]:null,$=(s,a)=>
6{if(a==="ad"){b(`/dashboard/ad-creator/result/${s}`,{state:{from:"/dashboard/posts"}});return}b(`/dashboard/post/${s}`,{state:{from:"/dashboard/posts"}})};if(D)return e.jsxs(q,{header:e.jsx(M,{}),maxWidth:"6xl",children:[e.jsx(P,{title:t("dashboard.all_posts"),backTo:"/dashboard"}),e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-3 md:gap-4",children:[...Array(8)].map((s,a)=>e.jsx(se,{className:"aspect-square rounded-lg"},a))})]});const O=[{value:"pending",label:t("postsHistory.tab_pending"),count:f.pending},{value:"scheduled",label:t("postsHistory.tab_scheduled"),count:f.scheduled},{value:"published",label:t("postsHistory.tab_published"),count:f.published},{value:"archived",label:t("postsHistory.tab_archived"),count:f.archived}];return e.jsxs(q,{header:e.jsx(M,{}),maxWidth:"6xl",bottomNav:e.jsx(ce,{}),children:[e.jsx(P,{title:t("dashboard.all_posts"),subtitle:r?`@${r.username}`:void 0,backTo:"/dashboard"}),e.jsx(te,{value:x,onValueChange:s=>E(s),children:e.jsx(ae,{className:"mb-4 w-full grid grid-cols-2 h-auto gap-1 sm:w-auto sm:inline-flex sm:h-10 sm:gap-0",children:O.map(s=>e.jsxs(re,{value:s.value,className:"text-xs sm:text-sm px-2 sm:px-3",children:[s.label,e.jsx("span",{className:"ml-1.5 text-muted-foreground",children:s.count})]},s.value))})}),e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx(de,{className:"w-4 h-4 text-muted-foreground"}),e.jsxs(X,{value:h,onValueChange:s=>I(s),children:[e.jsx(K,{className:"w-[220px] h-9",children:e.jsx(Q,{})}),e.jsxs(Y,{children:[e.jsx(u,{value:"all",children:t("approval.filter.all")}),e.jsx(u,{value:"none",children:t("approval.filter.none")}),e.jsx(u,{value:"pending",children:t("approval.status.pending")}),e.jsx(u,{value:"changes_requested",children:t("approval.status.changes_requested")}),e.jsx(u,{value:"approved",children:t("approval.status.approved")}),e.jsx(u,{value:"cancelled",children:t("approval.status.cancelled")})]})]})]}),m.length===0?e.jsxs("div",{className:"text-center py-16",children:[e.jsx(y,{className:"w-16 h-16 mx-auto mb-4 text-muted-foreground/50"}),e.jsx("h2",{className:"text-lg font-medium mb-2",children:t("dashboard.no_posts_yet")}),e.jsx("p",{className:"text-muted-foreground mb-6",children:t("dashboard.no_posts_description")}),e.jsx(A,{onClick:()=>b("/dashboard"),children:t("dashboard.create_first_post")})]}):C.length===0?e.jsxs("div",{className:"text-center py-16",children:[e.jsx(y,{className:"w-16 h-16 mx-auto mb-4 text-muted-foreground/50"}),e.jsx("p",{className:"text-muted-foreground",children:t("postsHistory.empty")})]}):e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-3 md:gap-4",children:C.map(s=>{const a=B(s),d=!!s.archived_at;return e.jsx(Z,{className:"group cursor-pointer overflow-hidden transition-all duration-200 hover:shadow-lg hover:scale-[1.02] active:scale-[0.98] touch-manipulation border border-border/50",onClick:()=>$(s.id,s.content_type),children:e.jsxs("div",{className:"relative aspect-square bg-muted",children:[a?e.jsx("img",{src:a,alt:s.title||"Post",className:"w-full h-full object-cover transition-transform duration-300 group-hover:scale-105",loading:"lazy"}):e.jsx("div",{className:"w-full h-full flex items-center justify-center bg-gradient-to-br from-muted to-muted/50",children:e.jsx(y,{className:"w-8 h-8 text-muted-foreground/50"})}),e.jsx("div",{className:"absolute inset-0 bg-gradient-to-t from-black/70 via-transparent to-transparent opacity-0 group-hover:opacity-100 transition-opacity duration-200",children:e.jsxs("div",{className:"absolute bottom-0 left-0 right-0 p-3",children:[e.jsx("p",{className:"text-white text-sm font-medium truncate mb-1",children:s.title||t("chat.untitled")}),e.jsxs("p",{className:"text-white/70 text-xs flex items-center gap-1",children:[e.jsx(pe,{className:"w-3 h-3"}),U(s.created_at)]})]})}),e.jsxs("div",{className:"absolute top-2 left-2 flex flex-wrap gap-1 pr-10",children:[e.jsxs(T,{variant:"secondary",className:"text-[10px] h-5 px-1.5 gap-1 bg-black/50 text-white border-0 backdrop-blur-sm",children:[F(s.content_type),L(s.content_type)]}),s.approval_status&&e.jsxs(T,{variant:"secondary",className:`text-[10px] h-5 px-1.5 gap-1 border-0 backdrop-blur-sm ${s.approval_status==="approved"?"bg-green-600/90 text-white":s.approval_status==="changes_requested"?"bg-amber-500/90 text-white":s.approval_status==="cancelled"?"bg-red-600/90 text-white":"bg-blue-600/90 text-white"}`,children:[e.jsx(me,{className:"w-3 h-3"}),t(`approval.status.${s.approval_status}`),s.approval_revision_count>0&&e.jsxs("span",{className:"ml-0.5",children:["· R",s.approval_revision_count+1]})]})]}),e.jsx("div",{className:"absolute top-2 right-2",children:e.jsxs(oe,{children:[e.jsx(ie,{asChild:!0,children:e.jsx(A,{variant:"secondary",size:"icon",className:"h-6 w-6 bg-black/50 text-white border-0 backdrop-blur-sm hover:bg-black/70",onClick:l=>l.stopPropagation(),"aria-label":t("postsHistory.options"),children:e.jsx(Ne,{className:"w-3.5 h-3.5"})})}),e.jsx(le,{align:"end",onClick:l=>l.stopPropagation(),children:e.jsx(ne,{onClick:l=>{l.stopPropagation(),V(s.id,!d)},children:d?e.jsxs(e.Fragment,{children:[e.jsx(ue,{className:"w-4 h-4 mr-2"}),t("postsHistory.unarchive")]}):e.jsxs(e.Fragment,{children:[e.jsx(he,{className:"w-4 h-4 mr-2"}),t("postsHistory.archive")]})})})]})})]})},s.id)})})]})};export{As as default};
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.