2 lines
8.3 KiB
JavaScript
2 lines
8.3 KiB
JavaScript
import{j as t,r as a}from"./chunk-UIGDSWPH-BhuNDbxn.js";import{u as V,T as K}from"./TablePageTemplate-BEWe6AkV.js";import{u as U,d as G,l as H,Q as O}from"./main-af3pcbZa.js";import{S as W}from"./file-CeG1FbGg.js";import{t as Q,s as q,w as J,a as X,b as Y,f as P,u as Z,P as ee}from"./date-Cc7ORwbK.js";import{B as k}from"./Badge-DM3morB7.js";import{P as te}from"./PageHeader-iXTYKDGo.js";import"./SelectDropdown-C8sZwHi_.js";import"./AlertModal-BhtTtzZV.js";import"./index-ju2wdkG8.js";import"./plus-2WF6_FMG.js";import"./check-circle--AtVWUy0.js";import"./arrow-right-DC7G5FiV.js";import"./pencil-CuC2vg9I.js";import"./angle-left-CYBnq6Pg.js";const j=(n,d)=>n&&n.length>0?n:d?Array.isArray(d)?d:[]:[],S=(n,d="-")=>!n||n.length===0?t.jsx("span",{className:"text-gray-400 dark:text-gray-500",children:d}):t.jsx("div",{className:"flex flex-wrap gap-1",children:n.map((m,s)=>t.jsx(k,{color:"light",size:"sm",variant:"light",children:m},`${m}-${s}`))}),se=n=>{const d=!n.activeSector,m={draft:"warning",review:"info",publish:"success"};return{columns:[{...Q,sortable:!0,sortField:"title",toggleable:!0,toggleContentKey:"html_content",toggleContentLabel:"Generated Content",render:(s,e)=>t.jsxs("div",{children:[t.jsx("div",{className:"font-medium text-gray-900 dark:text-white",children:e.meta_title||e.title||e.task_title||`Task #${e.task_id}`}),e.meta_description&&t.jsx("div",{className:"mt-1 text-sm text-gray-500 dark:text-gray-400 line-clamp-2",children:e.meta_description})]})},...d?[{...q,render:(s,e)=>t.jsx(k,{color:"info",size:"sm",variant:"light",children:e.sector_name||"-"})}]:[],{key:"primary_keyword",label:"Primary Keyword",sortable:!0,sortField:"primary_keyword",width:"150px",render:(s,e)=>e.primary_keyword?t.jsx(k,{color:"info",size:"sm",variant:"light",children:e.primary_keyword}):t.jsx("span",{className:"text-gray-400 dark:text-gray-500",children:"-"})},{key:"secondary_keywords",label:"Secondary Keywords",sortable:!1,width:"200px",render:(s,e)=>{var o;const l=j(e.secondary_keywords,(o=e.metadata)==null?void 0:o.secondary_keywords);return S(l)}},{key:"tags",label:"Tags",sortable:!1,width:"150px",render:(s,e)=>{var o;const l=j(e.tags,(o=e.metadata)==null?void 0:o.tags);return S(l)}},{key:"categories",label:"Categories",sortable:!1,width:"150px",render:(s,e)=>{var o;const l=j(e.categories,(o=e.metadata)==null?void 0:o.categories);return S(l)}},{...J,sortable:!0,sortField:"word_count",render:s=>(s==null?void 0:s.toLocaleString())??"-"},{...X,sortable:!0,sortField:"status",render:s=>{const e=s||"draft",l=m[e]||"primary",o=e.replace("_"," ").replace(/^\w/,h=>h.toUpperCase());return t.jsx(k,{color:l,size:"sm",variant:"light",children:o})}},{...Y,sortable:!0,sortField:"generated_at",label:"Generated",align:"right",render:(s,e)=>{const l=e.has_image_prompts||!1,o=e.has_generated_images||!1;return t.jsxs("div",{className:"flex items-center justify-end gap-3 pr-10",children:[t.jsx("span",{className:"text-gray-700 dark:text-gray-300 whitespace-nowrap",children:P(s)}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("div",{className:`w-5 h-5 flex items-center justify-center flex-shrink-0 ${l?"text-green-500 dark:text-green-400":"text-gray-300 dark:text-gray-600"}`,title:l?"Image prompts generated":"No image prompts",children:t.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"w-4 h-4",children:[t.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),t.jsx("polyline",{points:"14 2 14 8 20 8"}),t.jsx("line",{x1:"16",y1:"13",x2:"8",y2:"13"}),t.jsx("line",{x1:"16",y1:"17",x2:"8",y2:"17"}),t.jsx("polyline",{points:"10 9 9 9 8 9"})]})}),t.jsx("div",{className:`w-5 h-5 flex items-center justify-center flex-shrink-0 ${o?"text-green-500 dark:text-green-400":"text-gray-300 dark:text-gray-600"}`,title:o?"Images generated":"No images generated",children:t.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"w-4 h-4",children:[t.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"}),t.jsx("circle",{cx:"8.5",cy:"8.5",r:"1.5"}),t.jsx("polyline",{points:"21 15 16 10 5 21"})]})})]})]})}},{key:"task_title",label:"Task Title",sortable:!0,sortField:"task_id",defaultVisible:!1,width:"200px",render:(s,e)=>t.jsx("span",{className:"text-sm text-gray-600 dark:text-gray-400 truncate block max-w-[200px]",children:e.task_title||"-"})},{key:"post_url",label:"Post URL",sortable:!1,defaultVisible:!1,width:"200px",render:(s,e)=>{const l=s||e.post_url||null;return l?t.jsx("a",{href:l,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-brand-600 hover:text-brand-700 dark:text-brand-400 dark:hover:text-brand-300 truncate block max-w-[200px]",children:l}):t.jsx("span",{className:"text-sm text-gray-400 dark:text-gray-500",children:"-"})}},{key:"updated_at",label:"Updated",sortable:!0,sortField:"updated_at",defaultVisible:!1,render:s=>P(s)}],filters:[{key:"search",label:"Search",type:"text",placeholder:"Search content..."},{key:"status",label:"Status",type:"select",options:[{value:"",label:"All Status"},{value:"draft",label:"Draft"},{value:"review",label:"Review"},{value:"publish",label:"Publish"}]}],headerMetrics:[{label:"Total Content",value:0,accentColor:"blue",calculate:s=>s.totalCount||0},{label:"Draft",value:0,accentColor:"warning",calculate:s=>s.content.filter(e=>e.status==="draft").length},{label:"Review",value:0,accentColor:"info",calculate:s=>s.content.filter(e=>e.status==="review").length},{label:"Published",value:0,accentColor:"success",calculate:s=>s.content.filter(e=>e.status==="publish").length}]}};function ye(){const n=U(),{activeSector:d}=G(),{pageSize:m}=V(),[s,e]=a.useState([]),[l,o]=a.useState(!0),[h,N]=a.useState(""),[x,T]=a.useState(""),[F,L]=a.useState([]),[f,y]=a.useState(1),[M,I]=a.useState(1),[w,$]=a.useState(0),[b,E]=a.useState("generated_at"),[v,R]=a.useState("desc"),[z,C]=a.useState(!1),i=Z(),_=a.useRef(!1),g=a.useCallback(async()=>{o(!0),C(!1);try{const r=b?`${v==="desc"?"-":""}${b}`:"-generated_at",u={...h&&{search:h},...x&&{status:x},page:f,page_size:m,ordering:r},c=await H(u);e(c.results||[]),$(c.count||0),I(Math.ceil((c.count||0)/m)),setTimeout(()=>{C(!0),o(!1)},100)}catch(r){console.error("Error loading content:",r),n.error(`Failed to load content: ${r.message}`),C(!0),o(!1)}},[f,x,b,v,h,d,m,n]);a.useEffect(()=>{g()},[g]),a.useEffect(()=>{const r=()=>{g()},u=()=>{g()};return window.addEventListener("siteChanged",r),window.addEventListener("sectorChanged",u),()=>{window.removeEventListener("siteChanged",r),window.removeEventListener("sectorChanged",u)}},[g]),a.useEffect(()=>{y(1)},[m]),a.useEffect(()=>{const r=setTimeout(()=>{f===1?g():y(1)},500);return()=>clearTimeout(r)},[h,f,g]);const B=(r,u)=>{E(r||"generated_at"),R(u),y(1)},p=a.useMemo(()=>se({activeSector:d}),[d,h,x]),D=a.useMemo(()=>p!=null&&p.headerMetrics?p.headerMetrics.map(r=>({label:r.label,value:r.calculate({content:s,totalCount:w}),accentColor:r.accentColor})):[],[p==null?void 0:p.headerMetrics,s,w]),A=a.useCallback(async(r,u)=>{if(r==="generate_image_prompts")try{const c=await O([u.id]);c.success?c.task_id?i.openModal(c.task_id,"Smart Image Prompts","ai-generate-image-prompts-01-desktop"):(n.success(`Image prompts generated: ${c.prompts_created||0} prompt${(c.prompts_created||0)===1?"":"s"} created`),g()):n.error(c.error||"Failed to generate image prompts")}catch(c){n.error(`Failed to generate prompts: ${c.message}`)}},[n,i,g]);return t.jsxs(t.Fragment,{children:[t.jsx(te,{title:"Content",badge:{icon:t.jsx(W,{}),color:"purple"}}),t.jsx(K,{columns:p.columns,data:s,loading:l,showContent:z,filters:p.filters,filterValues:{search:h,status:x},onFilterChange:(r,u)=>{r==="search"?N(u):r==="status"&&(T(u),y(1))},pagination:{currentPage:f,totalPages:M,totalCount:w,onPageChange:y},sorting:{sortBy:b,sortDirection:v,onSort:B},selection:{selectedIds:F,onSelectionChange:L},headerMetrics:D,onRowAction:A,getItemDisplayName:r=>r.meta_title||r.title||`Content #${r.id}`}),t.jsx(ee,{isOpen:i.isOpen,title:i.title,percentage:i.progress.percentage,status:i.progress.status,message:i.progress.message,details:i.progress.details,taskId:i.taskId||void 0,functionId:i.functionId,onClose:()=>{const r=i.progress.status==="completed";i.closeModal(),r&&!_.current&&(_.current=!0,g(),setTimeout(()=>{_.current=!1},1e3))}})]})}export{ye as default};
|