Files
igny8/frontend/dist/assets/js/page-dashboard-DxYTR5eF.js
Gitea Deploy 961362e088 Add SEO fields to Tasks model, improve content generation response handling, and enhance progress bar animation
- Added primary_keyword, secondary_keywords, tags, and categories fields to Tasks model
- Updated generate_content function to handle full JSON response with all SEO fields
- Improved progress bar animation: smooth 1% increments every 300ms
- Enhanced step detection for content generation vs clustering vs ideas
- Fixed progress modal to show correct messages for each function type
- Added comprehensive logging to Keywords and Tasks pages for AI functions
- Fixed error handling to show meaningful error messages instead of generic failures
2025-11-09 21:22:34 +00:00

2 lines
27 KiB
JavaScript

import{r as A,j as d}from"./vendor-react-core-DjsjKnCi.js";import{C as R,P as J}from"./page-analytics.tsx-1KCk8AGD.js";import{c as D}from"./vendor-state-CYwAWrAU.js";const B="modulepreload",z=function(e){return"/"+e},L={},k=function(t,n,a){let r=Promise.resolve();if(n&&n.length>0){document.getElementsByTagName("link");const s=document.querySelector("meta[property=csp-nonce]"),c=(s==null?void 0:s.nonce)||(s==null?void 0:s.getAttribute("nonce"));r=Promise.allSettled(n.map(p=>{if(p=z(p),p in L)return;L[p]=!0;const i=p.endsWith(".css"),g=i?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${p}"]${g}`))return;const l=document.createElement("link");if(l.rel=i?"stylesheet":B,i||(l.as="script"),l.crossOrigin="",l.href=p,c&&l.setAttribute("nonce",c),document.head.appendChild(l),i)return new Promise((m,h)=>{l.addEventListener("load",m),l.addEventListener("error",()=>h(new Error(`Unable to preload CSS for ${p}`)))})}))}function u(s){const c=new Event("vite:preloadError",{cancelable:!0});if(c.payload=s,window.dispatchEvent(c),!c.defaultPrevented)throw s}return r.then(s=>{for(const c of s||[])c.status==="rejected"&&u(c.reason);return t().catch(u)})},x=D((e,t)=>({logs:[],maxLogs:20,addLog:n=>{const a={...n,id:`${Date.now()}-${Math.random().toString(36).substr(2,9)}`,timestamp:new Date,requestSteps:[],responseSteps:[]};return e(r=>({logs:[a,...r.logs].slice(0,r.maxLogs)})),a.id},updateLog:(n,a)=>{e(r=>({logs:r.logs.map(s=>s.id===n?{...s,...a}:s)}))},addRequestStep:(n,a)=>{e(r=>({logs:r.logs.map(s=>{if(s.id===n){const c={...a,timestamp:new Date};return{...s,requestSteps:[...s.requestSteps,c]}}return s})}))},addResponseStep:(n,a)=>{e(r=>({logs:r.logs.map(s=>{if(s.id===n){const c={...a,timestamp:new Date};return{...s,responseSteps:[...s.responseSteps,c]}}return s})}))},clearLogs:()=>{e({logs:[]})}})),j=Object.freeze(Object.defineProperty({__proto__:null,useAIRequestLogsStore:x},Symbol.toStringTag,{value:"Module"}));function M(){const e=window.location.origin;return e.includes("localhost")||e.includes("127.0.0.1")||/^\d+\.\d+\.\d+\.\d+/.test(e)?e.includes(":3000")?e.replace(":3000",":8011")+"/api":e.includes(":7921")?e.replace(":7921",":7911")+"/api":e.split(":")[0]+":8011/api":"https://api.igny8.com/api"}const E=M();function P(){var e;try{const t=localStorage.getItem("site-storage");if(t){const n=JSON.parse(t),a=(e=n==null?void 0:n.state)==null?void 0:e.activeSite;if(a&&a.id)return a.id}return null}catch(t){return console.warn("Failed to get active site ID from storage:",t),null}}function N(){var e;try{const t=localStorage.getItem("sector-storage");if(t){const n=JSON.parse(t),a=(e=n==null?void 0:n.state)==null?void 0:e.activeSector;if(a&&a.id)return a.id}return null}catch(t){return console.warn("Failed to get active sector ID from storage:",t),null}}const K=()=>{var e;try{const t=localStorage.getItem("auth-storage");if(t){const n=JSON.parse(t);return((e=n==null?void 0:n.state)==null?void 0:e.token)||null}}catch{}return null},F=()=>{var e;try{const t=localStorage.getItem("auth-storage");if(t){const n=JSON.parse(t);return((e=n==null?void 0:n.state)==null?void 0:e.refreshToken)||null}}catch{}return null};async function o(e,t){var u,s,c,p,i,g;const n=(t==null?void 0:t.timeout)||3e4,a=new AbortController,r=setTimeout(()=>a.abort(),n);try{const l=K(),m={"Content-Type":"application/json",...t==null?void 0:t.headers};l&&(m.Authorization=`Bearer ${l}`);const h=await fetch(`${E}${e}`,{headers:m,credentials:"include",signal:a.signal,...t});clearTimeout(r);const w=h.headers.get("content-type")||"",v=h.headers.get("content-length"),f=await h.text();if(h.status===401){const S=F();if(S)try{const _=await fetch(`${E}/v1/auth/refresh/`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({refresh:S}),credentials:"include"});if(_.ok){const y=await _.json();if(y.success&&y.access){try{const I=localStorage.getItem("auth-storage");if(I){const $=JSON.parse(I);$.state.token=y.access,localStorage.setItem("auth-storage",JSON.stringify($))}}catch{}const T={...m,Authorization:`Bearer ${y.access}`},O=await fetch(`${E}${e}`,{headers:T,credentials:"include",...t}),b=await O.text();if(O.ok){if(b&&b.trim())try{return JSON.parse(b)}catch{return b}return null}}}}catch{}}if(!h.ok){let S=h.statusText,_="HTTP_ERROR",y=null;try{if(w.includes("application/json"))try{if(y=JSON.parse(f),S=y.error||y.message||y.detail||S,y.success===!1&&y.error)return y;(u=y.error)!=null&&u.includes("OperationalError")?_="DATABASE_ERROR":(s=y.error)!=null&&s.includes("ValidationError")?_="VALIDATION_ERROR":(c=y.error)!=null&&c.includes("PermissionDenied")?_="PERMISSION_ERROR":(p=y.error)!=null&&p.includes("NotFound")?_="NOT_FOUND_ERROR":(i=y.error)!=null&&i.includes("IntegrityError")?_="DATABASE_ERROR":(g=y.error)!=null&&g.includes("RelatedObjectDoesNotExist")&&(_="RELATED_OBJECT_ERROR")}catch{S=f.substring(0,200)}else if(f.includes("<!DOCTYPE html>")){const O=f.match(/<title>([^<]+) at ([^<]+)<\/title>/);if(O)_=O[1].trim(),S=`${_} at ${O[2].trim()}`;else{const b=f.match(/<h1[^>]*>([^<]+)<\/h1>/);b?(S=b[1].trim(),_=S.split(" ")[0]):S=`HTTP ${h.status} Error`}}else S=f.substring(0,200)}catch{S=h.statusText}console.error("API Error:",{status:h.status,type:_,message:S,endpoint:e,errorData:y});const T=new Error(`API Error (${h.status}): ${_} - ${S}`);throw T.response=y,T.status=h.status,T}if(h.status===204||v==="0"||!f||f.trim()===""||w&&!w.includes("application/json"))return;try{return JSON.parse(f)}catch{return f}}catch(l){throw clearTimeout(r),l.name==="AbortError"?new Error(`Request timeout after ${n}ms: ${E}${e}`):l instanceof TypeError&&l.message.includes("Failed to fetch")?new Error(`Network Error: Unable to reach API at ${E}${e}. Check CORS and network connectivity.`):l}}async function G(e={}){const t=new URLSearchParams;if(!e.site_id){const r=P();r&&(e.site_id=r)}if(e.sector_id===void 0){const r=N();r!=null&&(e.sector_id=r)}e.search&&t.append("search",e.search),e.status&&t.append("status",e.status),e.cluster_id&&t.append("cluster_id",e.cluster_id),e.intent&&t.append("intent",e.intent),e.difficulty_min!==void 0&&t.append("difficulty_min",e.difficulty_min.toString()),e.difficulty_max!==void 0&&t.append("difficulty_max",e.difficulty_max.toString()),e.volume_min!==void 0&&t.append("volume_min",e.volume_min.toString()),e.volume_max!==void 0&&t.append("volume_max",e.volume_max.toString()),e.site_id&&t.append("site_id",e.site_id.toString()),e.sector_id&&t.append("sector_id",e.sector_id.toString()),e.page&&t.append("page",e.page.toString()),e.page_size!==void 0&&e.page_size!==null&&t.append("page_size",e.page_size.toString()),e.ordering&&t.append("ordering",e.ordering);const n=t.toString(),a=`/v1/planner/keywords/${n?`?${n}`:""}`;return o(a)}async function V(e){return o("/v1/planner/keywords/",{method:"POST",body:JSON.stringify(e)})}async function W(e,t){return o(`/v1/planner/keywords/${e}/`,{method:"PUT",body:JSON.stringify(t)})}async function H(e){return o(`/v1/planner/keywords/${e}/`,{method:"DELETE"})}async function Y(e){return o("/v1/planner/keywords/bulk_delete/",{method:"POST",body:JSON.stringify({ids:e})})}async function Q(e,t){return o("/v1/planner/keywords/bulk_update/",{method:"POST",body:JSON.stringify({ids:e,status:t})})}async function X(e={}){const t=new URLSearchParams;if(!e.site_id){const r=P();r&&(e.site_id=r)}if(e.sector_id===void 0){const r=N();r!=null&&(e.sector_id=r)}e.search&&t.append("search",e.search),e.status&&t.append("status",e.status),e.difficulty_min!==void 0&&t.append("difficulty_min",e.difficulty_min.toString()),e.difficulty_max!==void 0&&t.append("difficulty_max",e.difficulty_max.toString()),e.volume_min!==void 0&&t.append("volume_min",e.volume_min.toString()),e.volume_max!==void 0&&t.append("volume_max",e.volume_max.toString()),e.site_id&&t.append("site_id",e.site_id.toString()),e.sector_id&&t.append("sector_id",e.sector_id.toString()),e.page&&t.append("page",e.page.toString()),e.page_size!==void 0&&e.page_size!==null&&t.append("page_size",e.page_size.toString()),e.ordering&&t.append("ordering",e.ordering);const n=t.toString(),a=`/v1/planner/clusters/${n?`?${n}`:""}`;return o(a)}async function Z(e){return o("/v1/planner/clusters/",{method:"POST",body:JSON.stringify(e)})}async function ee(e,t){return o(`/v1/planner/clusters/${e}/`,{method:"PUT",body:JSON.stringify(t)})}async function te(e){return o(`/v1/planner/clusters/${e}/`,{method:"DELETE"})}async function ne(e){return o("/v1/planner/clusters/bulk_delete/",{method:"POST",body:JSON.stringify({ids:e})})}async function ae(e,t){return o("/v1/planner/clusters/bulk_update/",{method:"POST",body:JSON.stringify({ids:e,status:t})})}async function re(e,t){const n=Date.now(),a=x.getState().addLog,r="/v1/planner/keywords/auto_cluster/",u={ids:e,sector_id:t},s=a({function:"autoClusterKeywords",endpoint:r,request:{method:"POST",body:u},status:"pending"});try{const c=await o(r,{method:"POST",body:JSON.stringify(u)}),p=Date.now()-n,i=x.getState().updateLog;return s&&c&&i(s,{response:{status:200,data:c},status:c.success===!1?"error":"success",duration:p}),c&&c.success===!1,c}catch(c){const p=Date.now()-n;let i=null,g=null;c.response||c.data?(i=c.response||c.data,g=i==null?void 0:i.request_steps):c.response&&(i=c.response,g=i==null?void 0:i.request_steps);let l="UNKNOWN_ERROR",m=c.message||"Unknown error";if(c.message&&c.message.includes("API Error")){const v=c.message.match(/API Error \(\d+\): ([^-]+) - (.+)/);v&&(l=v[1].trim(),m=v[2].trim())}m.includes("OperationalError")?(l="DATABASE_ERROR",m=m.replace(/API Error \(\d+\): /,"").replace(/ - .*OperationalError.*/," - Database operation failed")):m.includes("ValidationError")?l="VALIDATION_ERROR":m.includes("PermissionDenied")?l="PERMISSION_ERROR":m.includes("NotFound")?l="NOT_FOUND_ERROR":m.includes("IntegrityError")?l="DATABASE_ERROR":m.includes("RelatedObjectDoesNotExist")&&(l="RELATED_OBJECT_ERROR",m=m.replace(/API Error \(\d+\): [^-]+ - /,"").trim());const h=x.getState().updateLog,w=x.getState().addRequestStep;if(s)h(s,{response:{status:(i==null?void 0:i.status)||500,error:m,errorType:l,data:i},status:"error",duration:p}),g&&Array.isArray(g)&&g.forEach(v=>{w(s,v)});else{const v=a({function:"autoClusterKeywords",endpoint:r,request:{method:"POST",body:u},response:{status:(i==null?void 0:i.status)||500,error:m,errorType:l,data:i},status:"error",duration:p});v&&g&&Array.isArray(g)&&g.forEach(f=>{w(v,f)})}return{success:!1,error:m,errorType:l}}}async function se(e){const t=Date.now(),{useAIRequestLogsStore:n}=await k(async()=>{const{useAIRequestLogsStore:s}=await Promise.resolve().then(()=>j);return{useAIRequestLogsStore:s}},void 0).catch(()=>({useAIRequestLogsStore:null})),a=n==null?void 0:n.getState().addLog,r="/v1/planner/clusters/auto_generate_ideas/",u={ids:e};a==null||a({function:"autoGenerateIdeas",endpoint:r,request:{method:"POST",body:u},status:"pending"});try{const s=await o(r,{method:"POST",body:JSON.stringify(u)}),c=Date.now()-t;return a({function:"autoGenerateIdeas",endpoint:r,request:{method:"POST",body:u},response:{status:200,data:s},status:"success",duration:c}),s}catch(s){const c=Date.now()-t;let p="UNKNOWN_ERROR",i=s.message||"Unknown error";if(i.includes("OperationalError"))p="DATABASE_ERROR",i=i.replace(/API Error \(\d+\): /,"").replace(/ - .*OperationalError.*/," - Database operation failed");else if(i.includes("ValidationError"))p="VALIDATION_ERROR";else if(i.includes("PermissionDenied"))p="PERMISSION_ERROR";else if(i.match(/API Error \(\d+\): ([^-]+)/)){const g=i.match(/API Error \(\d+\): ([^-]+)/);g&&(p=g[1].trim(),i=i.replace(/API Error \(\d+\): [^-]+ - /,""))}throw a==null||a({function:"autoGenerateIdeas",endpoint:r,request:{method:"POST",body:u},response:{status:500,error:i,errorType:p},status:"error",duration:c}),s}}async function oe(e={}){const t=new URLSearchParams;if(!e.site_id){const r=P();r&&(e.site_id=r)}if(e.sector_id===void 0){const r=N();r!=null&&(e.sector_id=r)}e.search&&t.append("search",e.search),e.status&&t.append("status",e.status),e.keyword_cluster_id&&t.append("keyword_cluster_id",e.keyword_cluster_id),e.content_structure&&t.append("content_structure",e.content_structure),e.content_type&&t.append("content_type",e.content_type),e.site_id&&t.append("site_id",e.site_id.toString()),e.sector_id&&t.append("sector_id",e.sector_id.toString()),e.page&&t.append("page",e.page.toString()),e.page_size!==void 0&&e.page_size!==null&&t.append("page_size",e.page_size.toString()),e.ordering&&t.append("ordering",e.ordering);const n=t.toString(),a=`/v1/planner/ideas/${n?`?${n}`:""}`;return o(a)}async function ie(e){return o("/v1/planner/ideas/",{method:"POST",body:JSON.stringify(e)})}async function ce(e,t){return o(`/v1/planner/ideas/${e}/`,{method:"PUT",body:JSON.stringify(t)})}async function de(e){return o(`/v1/planner/ideas/${e}/`,{method:"DELETE"})}async function ue(e){return o("/v1/planner/ideas/bulk_delete/",{method:"POST",body:JSON.stringify({ids:e})})}async function pe(e,t){return o("/v1/planner/ideas/bulk_update/",{method:"POST",body:JSON.stringify({ids:e,status:t})})}async function le(e){return o("/v1/planner/ideas/bulk_queue_to_writer/",{method:"POST",body:JSON.stringify({ids:e})})}async function ge(e={}){const t=new URLSearchParams;if(!e.site_id){const r=P();r&&(e.site_id=r)}if(e.sector_id===void 0){const r=N();r!=null&&(e.sector_id=r)}e.search&&t.append("search",e.search),e.status&&t.append("status",e.status),e.cluster_id&&t.append("cluster_id",e.cluster_id),e.content_type&&t.append("content_type",e.content_type),e.content_structure&&t.append("content_structure",e.content_structure),e.site_id&&t.append("site_id",e.site_id.toString()),e.sector_id&&t.append("sector_id",e.sector_id.toString()),e.page&&t.append("page",e.page.toString()),e.page_size!==void 0&&e.page_size!==null&&t.append("page_size",e.page_size.toString()),e.ordering&&t.append("ordering",e.ordering);const n=t.toString(),a=`/v1/writer/tasks/${n?`?${n}`:""}`;return o(a)}async function me(e){return o("/v1/writer/tasks/",{method:"POST",body:JSON.stringify(e)})}async function ye(e,t){return o(`/v1/writer/tasks/${e}/`,{method:"PUT",body:JSON.stringify(t)})}async function he(e){return o(`/v1/writer/tasks/${e}/`,{method:"DELETE"})}async function Se(e){return o("/v1/writer/tasks/bulk_delete/",{method:"POST",body:JSON.stringify({ids:e})})}async function _e(e,t){return o("/v1/writer/tasks/bulk_update/",{method:"POST",body:JSON.stringify({ids:e,status:t})})}async function fe(e){const t=Date.now(),{useAIRequestLogsStore:n}=await k(async()=>{const{useAIRequestLogsStore:s}=await Promise.resolve().then(()=>j);return{useAIRequestLogsStore:s}},void 0).catch(()=>({useAIRequestLogsStore:null})),a=n==null?void 0:n.getState().addLog,r="/v1/writer/tasks/auto_generate_content/",u={ids:e};a==null||a({function:"autoGenerateContent",endpoint:r,request:{method:"POST",body:u},status:"pending"});try{const s=await o(r,{method:"POST",body:JSON.stringify(u)}),c=Date.now()-t;return a({function:"autoGenerateContent",endpoint:r,request:{method:"POST",body:u},response:{status:200,data:s},status:"success",duration:c}),s}catch(s){const c=Date.now()-t;let p="UNKNOWN_ERROR",i=s.message||"Unknown error";if(i.includes("OperationalError"))p="DATABASE_ERROR",i=i.replace(/API Error \(\d+\): /,"").replace(/ - .*OperationalError.*/," - Database operation failed");else if(i.includes("ValidationError"))p="VALIDATION_ERROR";else if(i.match(/API Error \(\d+\): ([^-]+)/)){const g=i.match(/API Error \(\d+\): ([^-]+)/);g&&(p=g[1].trim(),i=i.replace(/API Error \(\d+\): [^-]+ - /,""))}throw a==null||a({function:"autoGenerateContent",endpoint:r,request:{method:"POST",body:u},response:{status:500,error:i,errorType:p},status:"error",duration:c}),s}}async function ve(e){const t=Date.now(),{useAIRequestLogsStore:n}=await k(async()=>{const{useAIRequestLogsStore:s}=await Promise.resolve().then(()=>j);return{useAIRequestLogsStore:s}},void 0).catch(()=>({useAIRequestLogsStore:null})),a=n==null?void 0:n.getState().addLog,r="/v1/writer/tasks/auto_generate_images/",u={task_ids:e};a==null||a({function:"autoGenerateImages",endpoint:r,request:{method:"POST",body:u},status:"pending"});try{const s=await o(r,{method:"POST",body:JSON.stringify(u)}),c=Date.now()-t;return a({function:"autoGenerateImages",endpoint:r,request:{method:"POST",body:u},response:{status:200,data:s},status:"success",duration:c}),s}catch(s){const c=Date.now()-t;let p="UNKNOWN_ERROR",i=s.message||"Unknown error";if(i.includes("OperationalError"))p="DATABASE_ERROR",i=i.replace(/API Error \(\d+\): /,"").replace(/ - .*OperationalError.*/," - Database operation failed");else if(i.includes("ValidationError"))p="VALIDATION_ERROR";else if(i.match(/API Error \(\d+\): ([^-]+)/)){const g=i.match(/API Error \(\d+\): ([^-]+)/);g&&(p=g[1].trim(),i=i.replace(/API Error \(\d+\): [^-]+ - /,""))}throw a==null||a({function:"autoGenerateImages",endpoint:r,request:{method:"POST",body:u},response:{status:500,error:i,errorType:p},status:"error",duration:c}),s}}async function Oe(e={}){const t=new URLSearchParams;e.task_id&&t.append("task_id",e.task_id),e.image_type&&t.append("image_type",e.image_type),e.status&&t.append("status",e.status),e.page&&t.append("page",e.page.toString()),e.ordering&&t.append("ordering",e.ordering||"task,position,-created_at");const n=t.toString(),a=`/v1/writer/images/${n?`?${n}`:""}`;return o(a)}async function be(e){return o(`/v1/writer/images/${e}/`,{method:"DELETE"})}async function we(){return o("/v1/auth/sites/")}async function Ee(e){return o("/v1/auth/sites/",{method:"POST",body:JSON.stringify(e)})}async function Te(e,t){return o(`/v1/auth/sites/${e}/`,{method:"PATCH",body:JSON.stringify(t)})}async function xe(e){return o(`/v1/auth/sites/${e}/`,{method:"DELETE"})}async function Re(e){return o(`/v1/auth/sites/${e}/set_active/`,{method:"POST"})}async function Pe(e,t,n){return o(`/v1/auth/sites/${e}/select_sectors/`,{method:"POST",body:JSON.stringify({industry_slug:t,sector_slugs:n})})}async function Ne(e){return o(`/v1/auth/sites/${e}/sectors/`)}async function Ie(){return o("/v1/auth/industries/")}async function Ae(){return o("/v1/system/settings/account/")}async function ke(e){return o(`/v1/system/settings/account/${e}/`)}async function je(e){return o("/v1/system/settings/account/",{method:"POST",body:JSON.stringify(e)})}async function $e(e,t){return o(`/v1/system/settings/account/${e}/`,{method:"PUT",body:JSON.stringify(t)})}async function Le(e){return(await o(`/v1/system/settings/modules/module/${e}/`)).results||[]}async function De(e){return o("/v1/system/settings/modules/",{method:"POST",body:JSON.stringify(e)})}async function qe(e,t,n){return o(`/v1/system/settings/modules/${t}/?module_name=${e}`,{method:"PUT",body:JSON.stringify(n)})}async function q(){return o("/v1/billing/credits/balance/balance/")}async function Ce(e){const t=new URLSearchParams;e!=null&&e.operation_type&&t.append("operation_type",e.operation_type),e!=null&&e.start_date&&t.append("start_date",e.start_date),e!=null&&e.end_date&&t.append("end_date",e.end_date),e!=null&&e.page&&t.append("page",e.page.toString());const n=t.toString();return o(`/v1/billing/credits/usage/${n?`?${n}`:""}`)}async function C(e,t){const n=new URLSearchParams;e&&n.append("start_date",e),t&&n.append("end_date",t);const a=n.toString();return o(`/v1/billing/credits/usage/summary/${a?`?${a}`:""}`)}async function Ue(){console.log("Fetching usage limits from:","/v1/billing/credits/usage/limits/");try{const e=await o("/v1/billing/credits/usage/limits/");return console.log("Usage limits API response:",e),e}catch(e){throw console.error("Error fetching usage limits:",e),e}}async function Je(e){const t=new URLSearchParams;e!=null&&e.transaction_type&&t.append("transaction_type",e.transaction_type),e!=null&&e.page&&t.append("page",e.page.toString());const n=t.toString();return o(`/v1/billing/credits/transactions/${n?`?${n}`:""}`)}async function Be(e){const t=new URLSearchParams;e!=null&&e.industry&&(t.append("industry",e.industry.toString()),t.append("industry_id",e.industry.toString())),e!=null&&e.sector&&(t.append("sector",e.sector.toString()),t.append("sector_id",e.sector.toString())),e!=null&&e.intent&&t.append("intent",e.intent),e!=null&&e.search&&t.append("search",e.search),e!=null&&e.page&&t.append("page",e.page.toString()),e!=null&&e.page_size&&t.append("page_size",e.page_size.toString());const n=t.toString();return o(`/v1/auth/seed-keywords/${n?`?${n}`:""}`)}async function ze(e,t,n){return o("/v1/planner/keywords/bulk_add_from_seed/",{method:"POST",body:JSON.stringify({seed_keyword_ids:e,site_id:t,sector_id:n})})}async function Me(e){const n=new URLSearchParams().toString();return o(`/v1/system/author-profiles/${n?`?${n}`:""}`)}async function Ke(e){return o("/v1/system/author-profiles/",{method:"POST",body:JSON.stringify(e)})}async function Fe(e,t){return o(`/v1/system/author-profiles/${e}/`,{method:"PUT",body:JSON.stringify(t)})}async function Ge(e){return o(`/v1/system/author-profiles/${e}/`,{method:"DELETE"})}async function Ve(e){const n=new URLSearchParams().toString();return o(`/v1/writer/content/${n?`?${n}`:""}`)}const et=Object.freeze(Object.defineProperty({__proto__:null,API_BASE_URL:E,addSeedKeywordsToWorkflow:ze,autoClusterKeywords:re,autoGenerateContent:fe,autoGenerateIdeas:se,autoGenerateImages:ve,bulkDeleteClusters:ne,bulkDeleteContentIdeas:ue,bulkDeleteKeywords:Y,bulkDeleteTasks:Se,bulkQueueIdeasToWriter:le,bulkUpdateClustersStatus:ae,bulkUpdateContentIdeasStatus:pe,bulkUpdateKeywordsStatus:Q,bulkUpdateTasksStatus:_e,createAccountSetting:je,createAuthorProfile:Ke,createCluster:Z,createContentIdea:ie,createKeyword:V,createModuleSetting:De,createSite:Ee,createTask:me,deleteAuthorProfile:Ge,deleteCluster:te,deleteContentIdea:de,deleteKeyword:H,deleteSite:xe,deleteTask:he,deleteTaskImage:be,fetchAPI:o,fetchAccountSetting:ke,fetchAccountSettings:Ae,fetchAuthorProfiles:Me,fetchClusters:X,fetchContent:Ve,fetchContentIdeas:oe,fetchCreditBalance:q,fetchCreditTransactions:Je,fetchCreditUsage:Ce,fetchIndustries:Ie,fetchKeywords:G,fetchModuleSettings:Le,fetchSeedKeywords:Be,fetchSiteSectors:Ne,fetchSites:we,fetchTaskImages:Oe,fetchTasks:ge,fetchUsageLimits:Ue,fetchUsageSummary:C,selectSectorsForSite:Pe,setActiveSite:Re,updateAccountSetting:$e,updateAuthorProfile:Fe,updateCluster:ee,updateContentIdea:ce,updateKeyword:W,updateModuleSetting:qe,updateSite:Te,updateTask:ye},Symbol.toStringTag,{value:"Module"})),U=D((e,t)=>({balance:null,usageSummary:null,loading:!1,error:null,loadBalance:async()=>{e({loading:!0,error:null});try{const n=await q();e({balance:n,loading:!1})}catch(n){e({error:n.message,loading:!1})}},loadUsageSummary:async(n,a)=>{e({loading:!0,error:null});try{const r=await C(n,a);e({usageSummary:r,loading:!1})}catch(r){e({error:r.message,loading:!1})}},reset:()=>{e({balance:null,usageSummary:null,loading:!1,error:null})}}));function We(){const{balance:e,loading:t,loadBalance:n}=U();if(A.useEffect(()=>{n()},[n]),t&&!e)return d.jsx(R,{title:"Credit Balance",desc:"Loading...",children:d.jsx("div",{className:"animate-pulse",children:"Loading credit balance..."})});if(!e)return null;const a=e.plan_credits_per_month>0?e.credits_used_this_month/e.plan_credits_per_month*100:0;return d.jsx(R,{title:"Credit Balance",desc:"Current credit status and usage",children:d.jsxs("div",{className:"space-y-4",children:[d.jsx("div",{children:d.jsxs("div",{className:"flex justify-between items-center mb-2",children:[d.jsx("span",{className:"text-sm text-gray-600 dark:text-gray-400",children:"Current Credits"}),d.jsx("span",{className:"text-2xl font-bold text-primary",children:e.credits})]})}),d.jsxs("div",{children:[d.jsxs("div",{className:"flex justify-between items-center mb-2",children:[d.jsx("span",{className:"text-sm text-gray-600 dark:text-gray-400",children:"Used This Month"}),d.jsxs("span",{className:"text-sm font-medium",children:[e.credits_used_this_month," / ",e.plan_credits_per_month]})]}),d.jsx("div",{className:"w-full bg-gray-200 rounded-full h-2.5 dark:bg-gray-700",children:d.jsx("div",{className:"bg-primary h-2.5 rounded-full transition-all",style:{width:`${Math.min(a,100)}%`}})})]}),d.jsx("div",{className:"pt-2 border-t border-gray-200 dark:border-gray-700",children:d.jsxs("div",{className:"flex justify-between items-center",children:[d.jsx("span",{className:"text-sm text-gray-600 dark:text-gray-400",children:"Remaining"}),d.jsx("span",{className:"text-sm font-medium text-success",children:e.credits_remaining})]})})]})})}function He(){const{usageSummary:e,loading:t,loadUsageSummary:n}=U(),[a,r]=A.useState("month");return A.useEffect(()=>{const u=new Date;let s;a==="week"?s=new Date(u.getTime()-6048e5).toISOString().split("T")[0]:a==="month"?s=new Date(u.getFullYear(),u.getMonth(),1).toISOString().split("T")[0]:s=new Date(u.getFullYear(),0,1).toISOString().split("T")[0];const c=u.toISOString().split("T")[0];n(s,c)},[a,n]),t&&!e?d.jsx(R,{title:"Usage Summary",desc:"Loading...",children:d.jsx("div",{className:"animate-pulse",children:"Loading usage data..."})}):e?d.jsx(R,{title:"Usage Summary",desc:"Credit usage breakdown by operation and model",children:d.jsxs("div",{className:"space-y-4",children:[d.jsx("div",{className:"flex justify-end items-center mb-4",children:d.jsxs("select",{className:"h-9 rounded-lg border border-gray-300 bg-transparent px-3 py-2 text-sm shadow-theme-xs text-gray-800 focus:border-brand-300 focus:outline-hidden focus:ring-3 focus:ring-brand-500/10 dark:border-gray-700 dark:bg-gray-900 dark:text-white/90 dark:focus:border-brand-800",value:a,onChange:u=>r(u.target.value),children:[d.jsx("option",{value:"week",children:"Last 7 Days"}),d.jsx("option",{value:"month",children:"This Month"}),d.jsx("option",{value:"year",children:"This Year"})]})}),d.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[d.jsxs("div",{children:[d.jsx("div",{className:"text-sm text-gray-600 dark:text-gray-400",children:"Total Credits Used"}),d.jsx("div",{className:"text-2xl font-bold",children:e.total_credits_used})]}),d.jsxs("div",{children:[d.jsx("div",{className:"text-sm text-gray-600 dark:text-gray-400",children:"Total Cost"}),d.jsxs("div",{className:"text-2xl font-bold",children:["$",(Number(e.total_cost_usd)||0).toFixed(2)]})]})]}),d.jsxs("div",{children:[d.jsx("h4",{className:"text-sm font-semibold mb-2",children:"By Operation"}),d.jsxs("div",{className:"space-y-2",children:[Object.entries(e.by_operation).map(([u,s])=>d.jsxs("div",{className:"flex justify-between items-center text-sm",children:[d.jsx("span",{className:"capitalize",children:u.replace("_"," ")}),d.jsxs("span",{className:"font-medium",children:[s.credits," credits ($",(Number(s.cost)||0).toFixed(2),")"]})]},u)),Object.keys(e.by_operation).length===0&&d.jsx("div",{className:"text-sm text-gray-500 dark:text-gray-400",children:"No usage data available"})]})]})]})}):null}function Ye(){return d.jsxs(d.Fragment,{children:[d.jsx(J,{title:"Dashboard - IGNY8",description:"IGNY8 Dashboard"}),d.jsxs("div",{className:"grid grid-cols-12 gap-4 md:gap-6",children:[d.jsx("div",{className:"col-span-12 xl:col-span-4",children:d.jsx(We,{})}),d.jsx("div",{className:"col-span-12 xl:col-span-8",children:d.jsx(He,{})})]})]})}const tt=Object.freeze(Object.defineProperty({__proto__:null,default:Ye},Symbol.toStringTag,{value:"Module"}));export{Se as $,E as A,ue as B,de as C,ce as D,ie as E,ze as F,qe as G,De as H,Le as I,$e as J,je as K,ke as L,Ae as M,Re as N,Te as O,Ee as P,Pe as Q,xe as R,Me as S,Fe as T,Ke as U,Ge as V,ge as W,_e as X,fe as Y,ve as Z,k as _,Be as a,he as a0,ye as a1,me as a2,Ve as a3,Oe as a4,be as a5,j as a6,et as a7,tt as a8,q as b,Je as c,Ce as d,Ue as e,Ie as f,we as g,Ne as h,o as i,G as j,re as k,Q as l,Y as m,H as n,X as o,V as p,ae as q,se as r,ne as s,te as t,W as u,ee as v,Z as w,oe as x,pe as y,le as z};