2 lines
13 KiB
JavaScript
2 lines
13 KiB
JavaScript
import{j as t,r as n}from"./chunk-UIGDSWPH-BhuNDbxn.js";import{B as d,u as te,aj as se,ah as ae,P as re,ak as V,at as M,au as ie,av as ne,aw as le,ax as oe}from"./main-af3pcbZa.js";import{S as ce}from"./Switch-BQnuu7S6.js";import{B as D}from"./Badge-DM3morB7.js";import{F as $}from"./FormModal-DkhE3zPR.js";import{A as de}from"./Alert-BeBw6uu9.js";import"./index-ju2wdkG8.js";import"./SelectDropdown-C8sZwHi_.js";function ue({site:s,icon:g,onToggle:N,onSettings:L,onDetails:v,isToggling:r=!1}){const l=x=>{N(s.id,x)},_=()=>s.is_active?"bg-green-500 dark:bg-green-600":"bg-gray-400 dark:bg-gray-500",p=s.is_active?{text:"Active",color:"text-green-600 dark:text-green-400",bold:!0}:{text:"Inactive",color:"text-gray-400 dark:text-gray-500",bold:!1};return t.jsxs("article",{className:"rounded-2xl border border-gray-200 bg-white dark:border-gray-800 dark:bg-white/3",children:[t.jsxs("div",{className:"relative p-5 pb-9",children:[t.jsx("div",{className:"mb-5 inline-flex h-10 w-10 items-center justify-center",children:g}),t.jsx("h3",{className:"mb-3 text-lg font-semibold text-gray-800 dark:text-white/90",children:s.name}),t.jsx("p",{className:"max-w-xs text-sm text-gray-500 dark:text-gray-400 mb-2",children:s.description||"No description"}),s.domain&&t.jsx("p",{className:"text-xs text-gray-400 dark:text-gray-500 mb-2",children:s.domain}),t.jsxs("div",{className:"flex items-center gap-2 mb-2 flex-wrap",children:[s.industry_name&&t.jsx(D,{variant:"light",color:"info",className:"text-xs",children:s.industry_name}),t.jsxs(D,{variant:"light",color:"info",className:"text-xs",children:[s.active_sectors_count," / 5 Sectors"]}),s.status&&t.jsx(D,{variant:"light",color:s.status==="active"?"success":"dark",className:"text-xs",children:s.status})]}),t.jsxs("div",{className:"absolute top-5 right-5 flex items-center gap-2",children:[t.jsx("span",{className:`text-sm ${p.color} ${p.bold?"font-bold":""} transition-colors duration-200`,children:p.text}),t.jsx("div",{className:`w-[25px] h-[25px] rounded-full ${_()} transition-colors duration-200`,title:s.is_active?"Active site":"Inactive site"})]})]}),t.jsxs("div",{className:"flex items-center justify-between border-t border-gray-200 p-5 dark:border-gray-800",children:[t.jsxs("div",{className:"flex gap-3",children:[t.jsx(d,{variant:"outline",size:"md",onClick:()=>L(s),className:"shadow-theme-xs inline-flex h-11 w-11 items-center justify-center rounded-lg border border-gray-300 text-gray-700 dark:border-gray-700 dark:text-gray-400",children:t.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",children:[t.jsx("path",{d:"M5.64615 4.59906C5.05459 4.25752 4.29808 4.46015 3.95654 5.05171L2.69321 7.23986C2.35175 7.83128 2.5544 8.58754 3.14582 8.92899C3.97016 9.40493 3.97017 10.5948 3.14583 11.0707C2.55441 11.4122 2.35178 12.1684 2.69323 12.7598L3.95657 14.948C4.2981 15.5395 5.05461 15.7422 5.64617 15.4006C6.4706 14.9247 7.50129 15.5196 7.50129 16.4715C7.50129 17.1545 8.05496 17.7082 8.73794 17.7082H11.2649C11.9478 17.7082 12.5013 17.1545 12.5013 16.4717C12.5013 15.5201 13.5315 14.9251 14.3556 15.401C14.9469 15.7423 15.7029 15.5397 16.0443 14.9485L17.3079 12.7598C17.6494 12.1684 17.4467 11.4121 16.8553 11.0707C16.031 10.5948 16.031 9.40494 16.8554 8.92902C17.4468 8.58757 17.6494 7.83133 17.3079 7.23992L16.0443 5.05123C15.7029 4.45996 14.9469 4.25737 14.3556 4.59874C13.5315 5.07456 12.5013 4.47961 12.5013 3.52798C12.5013 2.84515 11.9477 2.2915 11.2649 2.2915L8.73795 2.2915C8.05496 2.2915 7.50129 2.84518 7.50129 3.52816C7.50129 4.48015 6.47059 5.07505 5.64615 4.59906Z",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"}),t.jsx("path",{d:"M12.5714 9.99977C12.5714 11.4196 11.4204 12.5706 10.0005 12.5706C8.58069 12.5706 7.42969 11.4196 7.42969 9.99977C7.42969 8.57994 8.58069 7.42894 10.0005 7.42894C11.4204 7.42894 12.5714 8.57994 12.5714 9.99977Z",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]})}),t.jsx(d,{variant:"outline",size:"md",onClick:()=>v(s),className:"shadow-theme-xs inline-flex h-11 items-center justify-center rounded-lg border border-gray-300 px-4 py-3 text-sm font-medium text-gray-700 dark:border-gray-700 dark:text-gray-400",children:"Details"})]}),t.jsx(ce,{label:"",checked:s.is_active,disabled:r,onChange:l})]})]})}const H=()=>t.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"40",height:"40",viewBox:"0 0 40 40",fill:"none",children:[t.jsx("rect",{width:"40",height:"40",rx:"8",fill:"#3B82F6"}),t.jsx("path",{d:"M12 16L20 10L28 16V28C28 28.5304 27.7893 29.0391 27.4142 29.4142C27.0391 29.7893 26.5304 30 26 30H14C13.4696 30 12.9609 29.7893 12.5858 29.4142C12.2107 29.0391 12 28.5304 12 28V16Z",stroke:"white",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),t.jsx("path",{d:"M16 30V20H24V30",stroke:"white",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]});function ve(){var P;const s=te(),[g,N]=n.useState([]),[L,v]=n.useState(!0),[r,l]=n.useState(null),[_,j]=n.useState(!1),[p,x]=n.useState(!1),[I,S]=n.useState(!1),[h,w]=n.useState(!1),[T,A]=n.useState(null),[k,O]=n.useState([]),[o,F]=n.useState(""),[c,C]=n.useState([]),[b,B]=n.useState(!1),[i,u]=n.useState({name:"",domain:"",description:"",is_active:!0});n.useEffect(()=>{f(),Z()},[]);const f=async()=>{try{v(!0);const e=await se();N(e.results||[])}catch(e){s.error(`Failed to load sites: ${e.message}`)}finally{v(!1)}},Z=async()=>{try{const e=await ae();O(e.industries||[])}catch(e){s.error(`Failed to load industries: ${e.message}`)}},K=async(e,a)=>{if(T!==null){s.error("Please wait for the current operation to complete");return}try{A(e),a?(await V(e),s.success("Site activated successfully")):g.find(y=>y.id===e)&&(await M(e,{is_active:!1}),s.success("Site deactivated successfully")),await f()}catch(m){s.error(`Failed to update site: ${m.message}`)}finally{A(null)}},R=e=>{l(e),x(!0),U(e)},U=async e=>{try{const m=(await ie(e.id)).map(y=>y.slug);if(C(m),e.industry_slug)F(e.industry_slug);else for(const y of k)if(y.sectors.filter(ee=>m.includes(ee.slug)).length>0){F(y.slug);break}}catch(a){console.error("Failed to load site sectors:",a)}},G=e=>{l(e),u({name:e.name||"",domain:e.domain||"",description:e.description||"",is_active:e.is_active||!1}),S(!0)},E=async()=>{if(r)try{w(!0);const e={...i,domain:i.domain?z(i.domain):i.domain};await M(r.id,e),s.success("Site updated successfully"),S(!1),await f()}catch(e){s.error(`Failed to update site: ${e.message}`)}finally{w(!1)}},W=()=>{l(null),u({name:"",domain:"",description:"",is_active:!0}),j(!0)},z=e=>{if(!e||!e.trim())return e;const a=e.trim();return a.startsWith("https://")?a:a.startsWith("http://")?a.replace("http://","https://"):`https://${a}`},J=async()=>{try{w(!0);const e={...i,domain:i.domain?z(i.domain):i.domain};if(r)await M(r.id,e),s.success("Site updated successfully");else{const a=await ne({...e,is_active:e.is_active||!1});s.success("Site created successfully"),(g.length===0||e.is_active)&&await V(a.id)}j(!1),l(null),u({name:"",domain:"",description:"",is_active:!1}),await f()}catch(e){s.error(`Failed to save site: ${e.message}`)}finally{w(!1)}},Q=async()=>{if(!r||!o||c.length===0){s.error("Please select an industry and at least one sector");return}if(c.length>5){s.error("Maximum 5 sectors allowed per site");return}try{B(!0);const e=await le(r.id,o,c);s.success(e.message||"Sectors selected successfully"),x(!1),await f()}catch(e){s.error(`Failed to select sectors: ${e.message}`)}finally{B(!1)}},X=async e=>{if(window.confirm(`Are you sure you want to delete "${e.name}"? This action cannot be undone.`))try{await oe(e.id),s.success("Site deleted successfully"),await f(),I&&S(!1)}catch(a){s.error(`Failed to delete site: ${a.message}`)}},q=()=>[{key:"name",label:"Site Name",type:"text",value:i.name,onChange:e=>u({...i,name:e}),required:!0,placeholder:"Enter site name"},{key:"domain",label:"Domain",type:"text",value:i.domain,onChange:e=>u({...i,domain:e}),required:!1,placeholder:"example.com (https:// will be added automatically)"},{key:"description",label:"Description",type:"textarea",value:i.description,onChange:e=>u({...i,description:e}),required:!1,placeholder:"Enter site description",rows:4},{key:"is_active",label:"Set as Active Site",type:"select",value:i.is_active?"true":"false",onChange:e=>u({...i,is_active:e==="true"}),required:!1,options:[{value:"true",label:"Active"},{value:"false",label:"Inactive"}]}],Y=()=>{if(!o)return[];const e=k.find(a=>a.slug===o);return(e==null?void 0:e.sectors)||[]};return L?t.jsx("div",{className:"flex h-screen items-center justify-center",children:t.jsxs("div",{className:"text-center",children:[t.jsx("div",{className:"mb-4 h-8 w-8 animate-spin rounded-full border-4 border-gray-300 border-t-blue-600 mx-auto"}),t.jsx("p",{className:"text-gray-600 dark:text-gray-400",children:"Loading sites..."})]})}):t.jsxs(t.Fragment,{children:[t.jsx(re,{title:"Sites Management",description:"Manage your sites and configure industries and sectors"}),t.jsxs("div",{className:"space-y-8",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsxs("div",{children:[t.jsx("h1",{className:"text-2xl font-bold text-gray-900 dark:text-white",children:"Sites Management"}),t.jsx("p",{className:"mt-1 text-sm text-gray-500 dark:text-gray-400",children:"Manage your sites, configure industries, and select sectors. Multiple sites can be active simultaneously."})]}),t.jsx(d,{onClick:W,variant:"primary",children:"+ Add Site"})]}),t.jsx(de,{variant:"info",title:"Sites Configuration",message:"Each site can have up to 5 sectors selected from 15 major industries. Keywords and clusters are automatically associated with sectors. Multiple sites can be active simultaneously."}),g.length===0?t.jsxs("div",{className:"rounded-2xl border border-gray-200 bg-white p-12 text-center dark:border-gray-800 dark:bg-white/3",children:[t.jsx(H,{}),t.jsx("h3",{className:"mt-4 text-lg font-semibold text-gray-900 dark:text-white",children:"No sites yet"}),t.jsx("p",{className:"mt-2 text-sm text-gray-500 dark:text-gray-400",children:"Create your first site to get started"}),t.jsx(d,{onClick:W,variant:"primary",className:"mt-4",children:"Create Site"})]}):t.jsx("div",{className:"grid grid-cols-1 gap-6 sm:grid-cols-2 xl:grid-cols-3",children:g.map(e=>t.jsx(ue,{site:e,icon:t.jsx(H,{}),onToggle:K,onSettings:R,onDetails:G,isToggling:T===e.id},e.id))}),t.jsx($,{isOpen:_,onClose:()=>{j(!1),l(null),u({name:"",domain:"",description:"",is_active:!1})},onSubmit:J,title:r?"Edit Site":"Create New Site",submitLabel:r?"Update Site":"Create Site",fields:q(),isLoading:h}),t.jsx($,{isOpen:p,onClose:()=>x(!1),onSubmit:Q,title:r?`Configure Sectors for ${r.name}`:"Configure Sectors",submitLabel:b?"Saving...":"Save Sectors",cancelLabel:"Cancel",isLoading:b,className:"max-w-2xl",customBody:t.jsxs("div",{className:"space-y-6",children:[t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:"Select Industry"}),t.jsxs("select",{value:o,onChange:e=>{F(e.target.value),C([])},className:"h-9 w-full rounded-lg border border-gray-300 bg-transparent px-3 py-2 text-sm shadow-theme-xs text-gray-800 placeholder:text-gray-400 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:placeholder:text-white/30 dark:focus:border-brand-800",children:[t.jsx("option",{value:"",children:"Select an industry..."}),k.map(e=>t.jsx("option",{value:e.slug,children:e.name},e.slug))]}),o&&t.jsx("p",{className:"mt-1 text-xs text-gray-500 dark:text-gray-400",children:(P=k.find(e=>e.slug===o))==null?void 0:P.description})]}),o&&t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:"Select Sectors (max 5)"}),t.jsx("div",{className:"space-y-2 max-h-64 overflow-y-auto border border-gray-200 rounded-lg p-4 dark:border-gray-700",children:Y().map(e=>t.jsxs("label",{className:"flex items-start space-x-3 p-3 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-800 cursor-pointer",children:[t.jsx("input",{type:"checkbox",checked:c.includes(e.slug),onChange:a=>{if(a.target.checked){if(c.length>=5){s.error("Maximum 5 sectors allowed per site");return}C([...c,e.slug])}else C(c.filter(m=>m!==e.slug))},className:"mt-1 h-4 w-4 rounded border-gray-300 text-blue-600 focus:ring-blue-500"}),t.jsxs("div",{className:"flex-1",children:[t.jsx("div",{className:"font-medium text-sm text-gray-900 dark:text-white",children:e.name}),t.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400 mt-1",children:e.description})]})]},e.slug))}),t.jsxs("p",{className:"mt-2 text-xs text-gray-500 dark:text-gray-400",children:["Selected: ",c.length," / 5 sectors"]})]})]}),customFooter:t.jsxs("div",{className:"flex justify-end gap-3 pt-4 border-t border-gray-200 dark:border-gray-700",children:[t.jsx(d,{type:"button",variant:"outline",onClick:()=>x(!1),disabled:b,children:"Cancel"}),t.jsx(d,{type:"submit",variant:"primary",disabled:!o||c.length===0||b,children:b?"Saving...":"Save Sectors"})]})}),r&&t.jsx($,{isOpen:I,onClose:()=>{S(!1),l(null)},onSubmit:E,title:`Edit Site: ${r.name}`,submitLabel:"Save Changes",fields:q(),isLoading:h,customFooter:t.jsxs("div",{className:"flex justify-between items-center pt-4 border-t border-gray-200 dark:border-gray-700",children:[t.jsx(d,{variant:"danger",onClick:()=>{r&&X(r)},disabled:h,children:"Delete Site"}),t.jsxs("div",{className:"flex gap-3",children:[t.jsx(d,{variant:"outline",onClick:()=>{S(!1),l(null)},disabled:h,children:"Cancel"}),t.jsx(d,{variant:"primary",onClick:E,disabled:h,children:h?"Saving...":"Save Changes"})]})]})})]})]})}export{ve as default};
|