2 lines
18 KiB
JavaScript
2 lines
18 KiB
JavaScript
import{r as i,j as e,d as E,a as O}from"./vendor-react-core-DRQGgXXF.js";import{u as P,P as M,j as W}from"./page-authpages-BaiNliVr.js";import{u as S,a as F,b as K,f as D,s as H,c as V,d as _}from"./page-dashboard-CuOyqq-s.js";import{D as I,a as w,C as A}from"./page-components.tsx-4vErPdxY.js";import{B}from"./page-clusters.config.tsx-FJ8SgY77.js";const G=({children:m,text:a,placement:g="top",className:p=""})=>{const[l,c]=i.useState(!1),t=i.useRef(null),d=i.useRef(null),o=()=>{if(!t.current)return{};const s=t.current.getBoundingClientRect();let u=0,x=0,h="";switch(g){case"top":u=s.top-8,x=s.left+s.width/2,h="translate(-50%, -100%)";break;case"bottom":u=s.bottom+8,x=s.left+s.width/2,h="translateX(-50%)";break;case"left":u=s.top+s.height/2,x=s.left-8,h="translate(-100%, -50%)";break;case"right":u=s.top+s.height/2,x=s.right+8,h="translateY(-50%)";break}return{top:`${u}px`,left:`${x}px`,transform:h}};return i.useEffect(()=>{if(l&&d.current){const s=setTimeout(()=>{d.current&&(d.current.style.visibility="visible")},0);return()=>clearTimeout(s)}},[l]),e.jsxs(e.Fragment,{children:[e.jsx("div",{ref:t,className:`relative inline-flex ${p}`,onMouseEnter:()=>c(!0),onMouseLeave:()=>c(!1),children:m}),l&&E.createPortal(e.jsxs("span",{ref:d,className:"fixed z-[999999] px-3 py-1.5 text-xs font-medium text-white bg-gray-900 rounded-lg pointer-events-none whitespace-nowrap",style:o(),children:[a,e.jsx("span",{className:`absolute ${g==="top"?"top-full left-1/2 -translate-x-1/2 -mt-1 w-0 h-0 border-l-[6px] border-l-transparent border-r-[6px] border-r-transparent border-t-[6px] border-t-gray-900":g==="bottom"?"bottom-full left-1/2 -translate-x-1/2 -mb-1 w-0 h-0 border-l-[6px] border-l-transparent border-r-[6px] border-r-transparent border-b-[6px] border-b-gray-900":g==="left"?"left-full top-1/2 -translate-y-1/2 -ml-1 w-0 h-0 border-t-[6px] border-t-transparent border-b-[6px] border-b-transparent border-l-[6px] border-l-gray-900":"right-full top-1/2 -translate-y-1/2 -mr-1 w-0 h-0 border-t-[6px] border-t-transparent border-b-[6px] border-b-transparent border-r-[6px] border-r-gray-900"}`})]}),document.body)]})};function X(){var R;const m=S(),{activeSite:a,setActiveSite:g,loadActiveSite:p}=F(),{activeSector:l,sectors:c,setActiveSector:t,loading:d}=K(),{user:o,refreshUser:s,isAuthenticated:u}=P(),[x,h]=i.useState(!1),[r,v]=i.useState([]),[f,y]=i.useState(!0),L=i.useRef(null),[N,k]=i.useState(!1),C=i.useRef(null);i.useEffect(()=>{u&&o&&s().catch(n=>{console.debug("SiteAndSectorSelector: Failed to refresh user (non-critical):",n)})},[u]),i.useEffect(()=>{T(),a||p()},[(R=o==null?void 0:o.account)==null?void 0:R.id]);const T=async()=>{try{y(!0);const b=((await D()).results||[]).filter(j=>j.is_active);v(b)}catch(n){console.error("Failed to load sites:",n),m.error(`Failed to load sites: ${n.message}`)}finally{y(!1)}},z=async n=>{try{await H(n);const b=r.find(j=>j.id===n);b&&(g(b),m.success(`Switched to "${b.name}"`)),h(!1)}catch(b){m.error(`Failed to switch site: ${b.message}`)}},$=n=>{if(n===null)t(null),k(!1);else{const b=c.find(j=>j.id===n);b&&(t(b),k(!1))}};return a?e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"relative inline-block",children:[e.jsxs("button",{ref:L,onClick:()=>h(!x),className:"flex items-center gap-2 px-3 py-2 text-sm font-medium text-gray-700 bg-white border border-brand-200 rounded-lg hover:bg-brand-50 hover:border-brand-300 dark:bg-gray-800 dark:text-gray-300 dark:border-brand-700/50 dark:hover:bg-brand-500/10 dark:hover:border-brand-600/50 transition-colors dropdown-toggle","aria-label":"Switch site",disabled:f||r.length===0,children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("svg",{className:"w-4 h-4 text-brand-500 dark:text-brand-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 21V5a2 2 0 00-2-2H7a2 2 0 00-2 2v16m14 0h2m-2 0h-5m-9 0H3m2 0h5M9 7h1m-1 4h1m4-4h1m-1 4h1m-5 10v-5a1 1 0 011-1h2a1 1 0 011 1v5m-4 0h4"})}),e.jsx("span",{className:"max-w-[150px] truncate",children:f?"Loading...":(a==null?void 0:a.name)||"Select Site"})]}),e.jsx("svg",{className:`w-4 h-4 text-brand-500 dark:text-brand-400 transition-transform ${x?"rotate-180":""}`,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),e.jsx(I,{isOpen:x,onClose:()=>h(!1),anchorRef:L,placement:"bottom-left",className:"w-64 p-2",children:r.map(n=>e.jsxs(w,{onItemClick:()=>z(n.id),className:`flex items-center gap-3 px-3 py-2 font-medium rounded-lg text-sm text-left ${(a==null?void 0:a.id)===n.id?"bg-brand-50 text-brand-700 dark:bg-brand-500/20 dark:text-brand-300":"text-gray-700 hover:bg-gray-100 hover:text-gray-700 dark:text-gray-400 dark:hover:bg-white/5 dark:hover:text-gray-300"}`,children:[e.jsx("span",{className:"flex-1",children:n.name}),(a==null?void 0:a.id)===n.id&&e.jsx("svg",{className:"w-4 h-4 text-brand-600 dark:text-brand-400",fill:"currentColor",viewBox:"0 0 20 20",children:e.jsx("path",{fillRule:"evenodd",d:"M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z",clipRule:"evenodd"})})]},n.id))})]}),!d&&c.length>0&&e.jsxs("div",{className:"relative inline-block",children:[e.jsxs("button",{ref:C,onClick:()=>k(!N),className:"flex items-center gap-2 px-3 py-2 text-sm font-medium text-gray-700 bg-white border border-brand-200 rounded-lg hover:bg-brand-50 hover:border-brand-300 dark:bg-gray-800 dark:text-gray-300 dark:border-brand-700/50 dark:hover:bg-brand-500/10 dark:hover:border-brand-600/50 transition-colors dropdown-toggle","aria-label":"Select sector",disabled:d||c.length===0,children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("svg",{className:"w-4 h-4 text-brand-500 dark:text-brand-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z"})}),e.jsx("span",{className:"max-w-[150px] truncate",children:d?"Loading...":(l==null?void 0:l.name)||"All Sectors"})]}),e.jsx("svg",{className:`w-4 h-4 text-brand-500 dark:text-brand-400 transition-transform ${N?"rotate-180":""}`,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),e.jsxs(I,{isOpen:N,onClose:()=>k(!1),anchorRef:C,placement:"bottom-right",className:"w-64 p-2 overflow-y-auto max-h-[300px]",children:[e.jsxs(w,{onItemClick:()=>$(null),className:`flex items-center gap-3 px-3 py-2 font-medium rounded-lg text-sm text-left ${l?"text-gray-700 hover:bg-gray-100 hover:text-gray-700 dark:text-gray-400 dark:hover:bg-white/5 dark:hover:text-gray-300":"bg-brand-50 text-brand-700 dark:bg-brand-500/20 dark:text-brand-300"}`,children:[e.jsx("span",{className:"flex-1",children:"All Sectors"}),!l&&e.jsx("svg",{className:"w-4 h-4 text-brand-600 dark:text-brand-400",fill:"currentColor",viewBox:"0 0 20 20",children:e.jsx("path",{fillRule:"evenodd",d:"M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z",clipRule:"evenodd"})})]}),c.map(n=>e.jsxs(w,{onItemClick:()=>$(n.id),className:`flex items-center gap-3 px-3 py-2 font-medium rounded-lg text-sm text-left ${(l==null?void 0:l.id)===n.id?"bg-brand-50 text-brand-700 dark:bg-brand-500/20 dark:text-brand-300":"text-gray-700 hover:bg-gray-100 hover:text-gray-700 dark:text-gray-400 dark:hover:bg-white/5 dark:hover:text-gray-300"}`,children:[e.jsx("span",{className:"flex-1",children:n.name}),(l==null?void 0:l.id)===n.id&&e.jsx("svg",{className:"w-4 h-4 text-brand-600 dark:text-brand-400",fill:"currentColor",viewBox:"0 0 20 20",children:e.jsx("path",{fillRule:"evenodd",d:"M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z",clipRule:"evenodd"})})]},n.id))]})]})]}):null}function Y({title:m,lastUpdated:a,showRefresh:g=!1,onRefresh:p,className:l="",badge:c,hideSiteSector:t=!1}){const{activeSite:d}=F(),{activeSector:o}=K(),s={blue:"bg-blue-600 dark:bg-blue-500",green:"bg-green-600 dark:bg-green-500",purple:"bg-purple-600 dark:bg-purple-500",orange:"bg-orange-600 dark:bg-orange-500",red:"bg-red-600 dark:bg-red-500",indigo:"bg-indigo-600 dark:bg-indigo-500"};return e.jsxs("div",{className:`flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4 ${l}`,children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[c&&e.jsx("div",{className:`flex items-center justify-center w-10 h-10 rounded-xl ${s[c.color]} flex-shrink-0`,children:c.icon&&typeof c.icon=="object"&&"type"in c.icon?O.cloneElement(c.icon,{className:"text-white size-5"}):c.icon}),e.jsx("h2",{className:"text-2xl font-bold text-gray-800 dark:text-white/90",children:m})]}),!t&&e.jsxs("div",{className:"flex items-center gap-3 mt-1",children:[a&&e.jsx(e.Fragment,{children:e.jsxs("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:["Last updated: ",a.toLocaleTimeString()]})}),d&&e.jsxs(e.Fragment,{children:[a&&e.jsx("span",{className:"text-sm text-gray-400 dark:text-gray-600",children:"•"}),e.jsxs("p",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:["Site: ",e.jsx("span",{className:"text-brand-600 dark:text-brand-400",children:d.name})]})]}),o&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-sm text-gray-400 dark:text-gray-600",children:"•"}),e.jsxs("p",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:["Sector: ",e.jsx("span",{className:"text-brand-600 dark:text-brand-400",children:o.name})]})]}),!o&&d&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-sm text-gray-400 dark:text-gray-600",children:"•"}),e.jsxs("p",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:["Sector: ",e.jsx("span",{className:"text-brand-600 dark:text-brand-400",children:"All Sectors"})]})]})]}),t&&a&&e.jsx("div",{className:"flex items-center gap-3 mt-1",children:e.jsxs("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:["Last updated: ",a.toLocaleTimeString()]})})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[!t&&e.jsx(X,{}),g&&p&&e.jsx("button",{onClick:p,className:"px-4 py-2 text-sm font-medium text-brand-500 hover:text-brand-600 border border-brand-200 rounded-lg hover:bg-brand-50 dark:border-brand-800 dark:hover:bg-brand-500/10 transition-colors",children:"Refresh"})]})]})}function q(){const m=S(),[a,g]=i.useState([]),[p,l]=i.useState([]),[c,t]=i.useState(!0),[d,o]=i.useState(null),[s,u]=i.useState("");i.useEffect(()=>{x(),h()},[d,s]);const x=async()=>{try{const r=await V();l(r.industries||[])}catch(r){m.error(`Failed to load industries: ${r.message}`)}},h=async()=>{try{t(!0);const r=await _({industry:d||void 0,search:s||void 0});g(r.results||[])}catch(r){m.error(`Failed to load seed keywords: ${r.message}`)}finally{t(!1)}};return e.jsxs("div",{className:"p-6",children:[e.jsx(M,{title:"Seed Keywords"}),e.jsxs("div",{className:"mb-6",children:[e.jsx("h1",{className:"text-2xl font-bold text-gray-900 dark:text-white",children:"Seed Keywords"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mt-1",children:"Global keyword library for reference"})]}),e.jsxs("div",{className:"mb-6 flex gap-4",children:[e.jsxs("select",{className:"px-4 py-2 border border-gray-300 dark:border-gray-700 rounded-lg bg-white dark:bg-gray-800",value:d||"",onChange:r=>o(r.target.value?parseInt(r.target.value):null),children:[e.jsx("option",{value:"",children:"All Industries"}),p.map(r=>e.jsx("option",{value:r.id,children:r.name},r.id))]}),e.jsx("input",{type:"text",placeholder:"Search keywords...",className:"flex-1 px-4 py-2 border border-gray-300 dark:border-gray-700 rounded-lg bg-white dark:bg-gray-800",value:s,onChange:r=>u(r.target.value)})]}),c?e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx("div",{className:"text-gray-500",children:"Loading..."})}):e.jsx(A,{className:"p-6",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-gray-200 dark:border-gray-700",children:[e.jsx("th",{className:"text-left py-3 px-4 text-sm font-medium text-gray-700 dark:text-gray-300",children:"Keyword"}),e.jsx("th",{className:"text-left py-3 px-4 text-sm font-medium text-gray-700 dark:text-gray-300",children:"Industry"}),e.jsx("th",{className:"text-left py-3 px-4 text-sm font-medium text-gray-700 dark:text-gray-300",children:"Sector"}),e.jsx("th",{className:"text-left py-3 px-4 text-sm font-medium text-gray-700 dark:text-gray-300",children:"Volume"}),e.jsx("th",{className:"text-left py-3 px-4 text-sm font-medium text-gray-700 dark:text-gray-300",children:"Difficulty"}),e.jsx("th",{className:"text-left py-3 px-4 text-sm font-medium text-gray-700 dark:text-gray-300",children:"Intent"})]})}),e.jsx("tbody",{children:a.map(r=>e.jsxs("tr",{className:"border-b border-gray-100 dark:border-gray-800",children:[e.jsx("td",{className:"py-3 px-4 text-sm font-medium text-gray-900 dark:text-white",children:r.keyword}),e.jsx("td",{className:"py-3 px-4 text-sm text-gray-600 dark:text-gray-400",children:r.industry_name}),e.jsx("td",{className:"py-3 px-4 text-sm text-gray-600 dark:text-gray-400",children:r.sector_name}),e.jsx("td",{className:"py-3 px-4 text-sm text-gray-900 dark:text-white",children:r.volume.toLocaleString()}),e.jsx("td",{className:"py-3 px-4 text-sm text-gray-900 dark:text-white",children:r.difficulty}),e.jsx("td",{className:"py-3 px-4",children:e.jsx(B,{variant:"light",color:"primary",children:r.intent_display})})]},r.id))})]})})})]})}const se=Object.freeze(Object.defineProperty({__proto__:null,default:q},Symbol.toStringTag,{value:"Module"})),J=m=>m>=1e6?`${(m/1e6).toFixed(1)}m`:m>=1e3?`${(m/1e3).toFixed(1)}k`:m.toString();function Q(){const m=S(),[a,g]=i.useState([]),[p,l]=i.useState(!0);i.useEffect(()=>{c()},[]);const c=async()=>{try{l(!0);const d=(await V()).industries||[];let o=[];try{o=(await _({page_size:1e3})).results||[]}catch(x){console.warn("Failed to fetch keywords, will show without keyword data:",x)}const u=d.map(x=>{const h=o.filter(f=>f.industry_name===x.name),r=[...h].sort((f,y)=>(y.volume||0)-(f.volume||0)).slice(0,5),v=h.reduce((f,y)=>f+(y.volume||0),0);return{...x,keywordsCount:h.length,topKeywords:r,totalVolume:v}}).filter(x=>x.keywordsCount>0);g(u)}catch(t){m.error(`Failed to load industries: ${t.message}`)}finally{l(!1)}};return e.jsxs(e.Fragment,{children:[e.jsx(M,{title:"Industries"}),e.jsx(Y,{title:"Industries",badge:{icon:e.jsx(W,{}),color:"blue"},hideSiteSector:!0}),e.jsxs("div",{className:"p-6",children:[e.jsx("div",{className:"mb-6",children:e.jsx("p",{className:"text-gray-600 dark:text-gray-400",children:"Explore our comprehensive global database of industries, sectors, and high-volume keywords"})}),p?e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx("div",{className:"text-gray-500",children:"Loading industries..."})}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4",children:a.map(t=>{var d;return e.jsxs(A,{className:"p-4 hover:shadow-lg transition-shadow duration-200 border border-gray-200 dark:border-gray-700",children:[e.jsxs("div",{className:"flex justify-between items-start mb-3",children:[e.jsx("h3",{className:"text-base font-bold text-gray-900 dark:text-white leading-tight",children:t.name}),t.totalVolume>0&&e.jsx(G,{text:`Total search volume: ${t.totalVolume.toLocaleString()} monthly searches across all keywords in this industry`,placement:"top",children:e.jsx(B,{variant:"solid",color:"dark",size:"sm",children:J(t.totalVolume)})})]}),t.description&&e.jsx("p",{className:"text-xs text-gray-600 dark:text-gray-400 mb-3 line-clamp-2",children:t.description}),e.jsxs("div",{className:"flex items-center gap-4 mb-3 text-xs",children:[e.jsxs("div",{className:"flex items-center gap-1 text-gray-600 dark:text-gray-400",children:[e.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"})}),e.jsx("span",{className:"font-medium",children:((d=t.sectors)==null?void 0:d.length)||t.sectors_count||0}),e.jsx("span",{className:"text-gray-500",children:"sectors"})]}),e.jsxs("div",{className:"flex items-center gap-1 text-gray-600 dark:text-gray-400",children:[e.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M7 7h.01M7 3h5c.512 0 1.024.195 1.414.586l7 7a2 2 0 010 2.828l-7 7a2 2 0 01-2.828 0l-7-7A1.994 1.994 0 013 12V7a4 4 0 014-4z"})}),e.jsx("span",{className:"font-medium",children:t.keywordsCount||0}),e.jsx("span",{className:"text-gray-500",children:"keywords"})]})]}),t.topKeywords&&t.topKeywords.length>0&&e.jsxs("div",{className:"mt-3 pt-3 border-t border-gray-200 dark:border-gray-700",children:[e.jsx("p",{className:"text-xs font-medium text-gray-700 dark:text-gray-300 mb-2",children:"Top Keywords"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:t.topKeywords.slice(0,5).map((o,s)=>e.jsxs("div",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-md bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800",children:[e.jsx("span",{className:"text-xs font-medium text-blue-700 dark:text-blue-300",children:o.keyword}),e.jsx("span",{className:"text-xs text-blue-600 dark:text-blue-400 font-semibold",children:o.volume?o.volume>=1e3?`${(o.volume/1e3).toFixed(1)}k`:o.volume.toString():"-"})]},o.id||s))})]})]},t.slug)})})]})]})}const ae=Object.freeze(Object.defineProperty({__proto__:null,default:Q},Symbol.toStringTag,{value:"Module"}));export{ae as I,Y as P,se as S,G as T};
|