1import{aI as Y,a as W,b as V,u as Z,al as ee,aM as ae,r as p,j as e,c as T,B as se,G as te,cs as re,aa as le,ab as ie,ac as oe,ad as ne,ae as F,C as de,a2 as B,a6 as ce,ag as pe,Z as me}from"./main-DX7XzkoU.js";import{B as E}from"./badge-BOGaWzi1.js";import{S as H}from"./skeleton-DN2cjZOe.js";import{s as z}from"./untyped-client-BsKF0fUL.js";import{S as ue,a as he,b as xe,c as fe,d as ge}from"./sheet-D4yLKOxB.js";import{A as _e,S as ve}from"./AppInstallBanner-CAnCi_kO.js";import{C as be}from"./CreateContentModal-eREkTihJ.js";import{A as je}from"./arrow-left-Cf41rOjY.js";import{G as Ne}from"./gem-DGeoeC5P.js";import{B as ye}from"./briefcase-bQeHiZD2.js";import{P as we}from"./plus-C6FQ2-b-.js";import{M as ke}from"./menu-B6sRxHFL.js";import{P as Ce}from"./PageShell-Bd7x8hXC.js";import{P as Se}from"./PageHeader-CM5sf6Dy.js";import{M as Pe}from"./MobileBottomNav-B6c1hPKj.js";import{e as Me,p as Ae}from"./pt-BR-g-tPW2Ip.js";import{U as K}from"./user-check-BR60HPjZ.js";import{F as Ie}from"./filter-BMbwhTzt.js";import{C as qe}from"./clock-DZY59rpR.js";import{M as Le,H as Te}from"./message-square-warning-Tvay_GN3.js";import{C as $}from"./circle-check-DRpR_UoF.js";import{I as Be}from"./image-off-BUfV3N24.js";import{f as Ee}from"./formatDistanceToNow-BwcGd3xH.js";import{C as He}from"./calendar-clock-DB9Oxi4W.js";import{f as Oe}from"./format-kQpqiptj.js";import"./ThemeToggle-C5kzRcph.js";import"./dropdown-menu-D6liHcXh.js";import"./index-D6Z5KIMn.js";import"./chevron-right-D27HfhtL.js";import"./circle-BXmX70XD.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"./lightbulb-UJa6zn96.js";import"./circle-help-CV3y08qY.js";import"./user-x-BOA8xi05.js";import"./globe-BBWCCznd.js";import"./download-DFu9GkQ8.js";import"./referral-code-CAIXjQN4.js";import"./megaphone-B0K-HV7w.js";import"./image-BBUOngQh.js";import"./smartphone-WGY3uvd5.js";import"./video-BvJDFQSG.js";import"./image-play-FzvV3P2U.js";import"./palette-OTKsHiwO.js";import"./wand-sparkles-CwRAYUwy.js";import"./clapperboard-BoJYuZop.js";import"./layers-UGj9VXD5.js";import"./link-2-CASnJw5r.js";import"./house-C4ToeB93.js";import"./constructNow-CO-G4Rcw.js";import"./endOfMonth-DpURBOFe.js";const J=Y.memo(({showBackButton:C=!1,backPath:r="/dashboard",title:n})=>{var w;const x=W(),{t:i}=V(),{user:_,signOut:S}=Z(),{subscription:l,imagesLeft:m,openCustomerPortal:j}=ee(),{openPricingModal:h}=ae(),[P,f]=p.useState(!1),N=l==null?void 0:l.images_limit,M=!!(l!=null&&l.subscribed),A=l==null?void 0:l.plan_slug,y=l==null?void 0:l.plan_name,I=((w=l==null?void 0:l.plan_slug)==null?void 0:w.endsWith("-annual"))||!1;if(!_)return null;const q=n??i("agencyHeader.title");return e.jsxs("div",{className:"flex-shrink-0 safe-area-top border-b border-border/40 bg-background/95 backdrop-blur-md shadow-sm",children:[e.jsx(_e,{}),e.jsxs("div",{className:"px-4 h-[48px] flex items-center justify-between max-w-7xl mx-auto",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[C&&e.jsxs(T,{variant:"ghost",size:"sm",onClick:()=>x(r),"aria-label":i("common.back"),className:"h-8 px-2 md:hover:bg-surface-elevated/50 gap-1",children:[e.jsx(je,{className:"w-4 h-4"}),e.jsx("span",{className:"hidden sm:inline text-sm",children:i("common.back")})]}),e.jsxs("div",{onClick:()=>x("/dashboard"),className:"hidden md:flex items-center gap-2 md:hover:opacity-80 transition-opacity cursor-pointer",children:[e.jsx("div",{className:"w-6 h-6 bg-gradient-primary rounded-full flex items-center justify-center",children:e.jsx(Ne,{className:"w-3 h-3 text-white"})}),e.jsx("span",{className:"font-semibold text-sm text-foreground",children:se.name})]}),e.jsxs("div",{className:"flex items-center gap-1.5 px-2.5 py-1 rounded-full bg-primary/10 border border-primary/20 text-xs font-medium text-primary whitespace-nowrap",children:[e.jsx(ye,{className:"w-3 h-3"}),e.jsx("span",{className:"truncate max-w-[160px] sm:max-w-none",children:q})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[typeof m=="number"&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsxs("button",{type:"button",onClick:()=>h(),className:"flex items-center gap-1.5 h-8 px-3 rounded-full bg-secondary/50 border border-border/50 text-xs font-medium whitespace-nowrap cursor-pointer md:hover:bg-secondary/80 active:bg-secondary/80 transition-colors",title:i(N?"app_header.usage_title_with_limit":"app_header.usage_title",{count:m,limit:N}),children:[e.jsx("span",{className:`block w-1.5 h-1.5 rounded-full ${m>0?"bg-emerald-500 shadow-[0_0_6px_rgba(16,185,129,0.4)]":"bg-red-500"}`}
1),e.jsx("span",{className:"text-foreground/80",children:m}),e.jsx("span",{className:"text-muted-foreground/70 text-[10px] uppercase tracking-wider",children:i("app_header.posts",{count:m})})]}),e.jsx(T,{variant:"ghost",size:"sm",onClick:()=>f(!0),className:"hidden md:flex h-8 w-8 p-0 md:hover:bg-primary/10 md:hover:text-primary rounded-full",title:i("app_header.create_post"),"aria-label":i("app_header.create_post"),children:e.jsx(we,{className:"w-4 h-4"})})]}),e.jsxs(ue,{children:[e.jsx(he,{asChild:!0,children:e.jsx(T,{variant:"ghost",size:"sm",className:"h-9 w-9 p-0 rounded-full md:hover:bg-surface-elevated/50",title:i("app_header.menu"),"aria-label":i("app_header.menu"),children:e.jsx(ke,{className:"w-4 h-4"})})}),e.jsxs(xe,{side:"right",className:"w-80 bg-surface-card border-border/50 z-[50] overflow-hidden flex flex-col",children:[e.jsx(fe,{className:"flex-shrink-0",children:e.jsx(ge,{className:"flex items-center gap-2 text-left",children:i("app_header.menu")})}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:e.jsx(ve,{onCreatePost:()=>f(!0),user:_,planType:A,planName:y,imagesLeft:m,subscribed:M,isAnnualPlan:I,onUpgrade:h,onManageSubscription:j,onSignOut:S})})]})]})]})]}),e.jsx(be,{isOpen:P,onClose:()=>f(!1)})]})});J.displayName="AgencyHeader";const G=[{status:"pending",titleKey:"approvals.column.pending",icon:qe,accent:"border-amber-500/40"},{status:"changes_requested",titleKey:"approvals.column.changes_requested",icon:Le,accent:"border-orange-500/40"},{status:"approved",titleKey:"approvals.column.approved",icon:$,accent:"border-emerald-500/40"}],O="__all__",Da=()=>{const C=W(),{t:r}=V(),{user:n}=Z(),{profiles:x}=te(),[i,_]=p.useState([]),[S,l]=p.useState({}),[m,j]=p.useState(!0),[h,P]=p.useState(O),f=p.useCallback(async()=>{if(n!=null&&n.id){j(!0);try{let a=z.from("posts").select("id, title, caption, thumbnail_url, slide_images, content_type, instagram_profile_id, approval_status, approval_history, approval_revision_count, approval_publish_at, approval_auto_publish, updated_at, created_at").eq("user_id",n.id).in("approval_status",["pending","changes_requested","approved"]);h!==O&&(a=a.eq("instagram_profile_id",h));const{data:s,error:o}=await a.order("updated_at",{ascending:!1}).limit(200);if(o)throw o;const t=s??[];_(t);const v=t.filter(u=>u.approval_status==="approved").map(u=>u.id);if(v.length>0){const{data:u,error:b}=await z.from("scheduled_posts").select("post_id, status, scheduled_at, published_at, publish_mode, created_at").in("post_id",v).order("created_at",{ascending:!1});if(b)console.error("[Approvals] Error loading publications:",b),l({});else{const g={};(u??[]).forEach(d=>{d.post_id&&!g[d.post_id]&&(g[d.post_id]={status:d.status,scheduled_at:d.scheduled_at,published_at:d.published_at,publish_mode:d.publish_mode})}),l(g)}}else l({})}catch(a){console.error("[Approvals] Error loading posts:",a),_([]),l({})}finally{j(!1)}}},[n==null?void 0:n.id,h]);p.useEffect(()=>{f()},[f]);const N=p.useMemo(()=>{const a=new Map;return x.forEach(s=>{a.set(s.id,{username:s.username,profile_pic_url:s.profile_pic_url})}),a},[x]),M=p.useMemo(()=>{const a={pending:[],changes_requested:[],approved:[],cancelled:[]};return i.forEach(s=>{a[s.approval_status]&&a[s.approval_status].push(s)}),a},[i]),A=i.length,y=re.language==="en"?Me:Ae,I=a=>{C(`/dashboard/post/${a}`,{state:{from:"/dashboard/approvals"}})},q=a=>a.thumbnail_url?a.thumbnail_url:a.slide_images&&a.slide_images.length>0?a.slide_images[0]:null,w=a=>{if(!a.approval_history||a.approval_history.length===0)return null;for(let s=a.approval_history.length-1;s>=0;s--){const o=a.approval_history[s];if(o.type==="client_changes_requested"&&o.message)return o.message}return null},U=a=>{try{return Ee(new Date(a),{locale:y,addSuffix:!1})}catch{return""}},Q=a=>{if(a.approval_status!=="pending"||!a.approval_publish_at)return!1;const s=new Date(a.approval_publish_at).getTime(),o=Date.now(),t=(s-o)/(1e3*60*60);return t>0&&t<48},D=a=>{try{return Oe(new Date(a),"dd/MM/yyyy HH:mm",{locale:y})}catch{return""}},X=a=>{if(a.approval_status!=="approved")return null;const s=S[a.id];if((s==null?void 0:s.status)==="published"&&s.published_at)return{kind:"published",label:r("approvals.card.published_on",{date:D(s.published_at)}),icon:$};const o=(s==null?void 0:s.scheduled_at)??a.approval_publish_at;return o?{kind:"scheduled",label:r("approvals.card.scheduled_for",{date:D(o)}),icon:He}:a.approval_auto_publish===!1?{kind:"manual",label:r("approvals.card.manual_publish"),icon:Te}:(s==null?void 0:s.publish_mode)==="immediate"||s?{kind:"immediate",label:r("approvals.card.publishing_now"),icon:pe}:{kind:"pending_publish",label:r("approvals.card.immediate_publish"),icon:me}};return e.jsxs(Ce,{header:e.jsx(J,{}),maxWidth:"7xl",bottomNav:e.jsx(Pe,{}),children:[e.jsx(Se,{title:r("approvals.page_title"),subtitle:r("approvals.page_subtitle"),icon:K,backTo:"/dashboard"}),e.jsxs("div",{className:"flex items-center gap-2 mb-6",children:[e.jsx(Ie,{className:"w-4 h-4 text-muted-foreground"}),e.jsxs(le,{value:h,onValueChange:P,children:[e.jsx(ie,{className:"w-[260px] h-9",children:e.jsx(oe,{placeholder:r("approvals.filter_profile")})}),e.jsxs(ne,{children:[e.jsx(F,{value:O,children:r("approvals.all_profiles")}),x.map(a=>e.jsxs(F,{value:a.id,children:["@",a.username]},a.id))]})]})]}),m?e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:G.map(a=>e.jsxs("div",{className:"space-y-3",children:[e.jsx(H,{className:"h-10 w-full rounded-lg"}),e.jsx(H,{className:"h-32 w-full rounded-lg"}),e.jsx(H,{className:"h-32 w-full rounded-lg"})]},a.status))}):A===0?e.jsxs("div",{className:"text-center py-16",children:[e.jsx(K,{className:"w-16 h-16 mx-auto mb-4 text-muted-foreground
1/40"}),e.jsx("h2",{className:"text-lg font-medium mb-2",children:r("approvals.empty_state_title")}),e.jsx("p",{className:"text-muted-foreground max-w-md mx-auto",children:r("approvals.empty_state_desc")})]}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:G.map(a=>{const s=M[a.status],o=a.icon;return e.jsxs("div",{className:B("rounded-lg border bg-surface-elevated/30 backdrop-blur-sm flex flex-col min-h-[200px]",a.accent),children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border/40",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(o,{className:"w-4 h-4 text-muted-foreground"}),e.jsx("h2",{className:"font-semibold text-sm",children:r(a.titleKey)})]}),e.jsx(E,{variant:"secondary",className:"text-xs",children:s.length})]}),e.jsx("div",{className:"flex-1 p-3 space-y-3 overflow-y-auto max-h-[calc(100vh-280px)]",children:s.length===0?e.jsx("p",{className:"text-xs text-muted-foreground text-center py-8",children:r("approvals.empty_column")}):s.map(t=>{const v=q(t),u=N.get(t.instagram_profile_id),b=w(t),g=Q(t),d=(t.approval_status==="approved",t.updated_at),L=U(d);let k="";t.approval_status==="pending"?k=r("approvals.card.waiting_for",{time:L}):t.approval_status==="changes_requested"?k=r("approvals.card.requested_ago",{time:L}):k=r("approvals.card.approved_ago",{time:L});const c=X(t),R=c==null?void 0:c.icon;return e.jsxs(de,{onClick:()=>I(t.id),className:B("group cursor-pointer overflow-hidden transition-all duration-200 hover:shadow-md hover:border-primary/40 active:scale-[0.99] border",g&&"ring-2 ring-red-500/40"),children:[e.jsxs("div",{className:"flex gap-3 p-3",children:[e.jsx("div",{className:"relative w-16 h-16 flex-shrink-0 rounded-md overflow-hidden bg-muted",children:v?e.jsx("img",{src:v,alt:t.title||"Post",className:"w-full h-full object-cover",loading:"lazy"}):e.jsx("div",{className:"w-full h-full flex items-center justify-center",children:e.jsx(Be,{className:"w-5 h-5 text-muted-foreground/50"})})}),e.jsxs("div",{className:"flex-1 min-w-0 space-y-1",children:[u&&e.jsxs("p",{className:"text-[11px] text-muted-foreground truncate",children:["@",u.username]}),e.jsx("p",{className:"text-sm font-medium line-clamp-2 leading-tight",children:t.title||t.caption||r("approvals.card.open")}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap pt-0.5",children:[e.jsx("span",{className:"text-[11px] text-muted-foreground",children:k}),c&&R&&e.jsxs("span",{className:B("inline-flex items-center gap-1 text-[11px] font-medium",c.kind==="published"&&"text-emerald-600 dark:text-emerald-400",c.kind==="scheduled"&&"text-blue-600 dark:text-blue-400",(c.kind==="immediate"||c.kind==="pending_publish")&&"text-amber-600 dark:text-amber-400"),children:[e.jsx(R,{className:"w-3 h-3"}),c.label]}),t.approval_revision_count>0&&e.jsx(E,{variant:"outline",className:"text-[10px] h-4 px-1.5",children:r("approvals.card.revision_count",{count:t.approval_revision_count})}),g&&e.jsxs(E,{variant:"destructive",className:"text-[10px] h-4 px-1.5 gap-1",children:[e.jsx(ce,{className:"w-2.5 h-2.5"}),U(t.approval_publish_at)]})]})]})]}),b&&t.approval_status==="changes_requested"&&e.jsx("div",{className:"px-3 pb-3",children:e.jsxs("div",{className:"bg-orange-500/10 border border-orange-500/20 rounded-md p-2",children:[e.jsx("p",{className:"text-[10px] uppercase font-medium text-orange-600 dark:text-orange-400 mb-1",children:r("approvals.card.feedback_label")}),e.jsx("p",{className:"text-xs text-foreground/90 line-clamp-3",children:b})]})})]},t.id)})})]},a.status)})})]})};export{Da 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.