(()=>{var e={};e.id=2433,e.ids=[2433],e.modules={7849:e=>{"use strict";e.exports=require("next/dist/client/components/action-async-storage.external")},2934:e=>{"use strict";e.exports=require("next/dist/client/components/action-async-storage.external.js")},5403:e=>{"use strict";e.exports=require("next/dist/client/components/request-async-storage.external")},4580:e=>{"use strict";e.exports=require("next/dist/client/components/request-async-storage.external.js")},4749:e=>{"use strict";e.exports=require("next/dist/client/components/static-generation-async-storage.external")},5869:e=>{"use strict";e.exports=require("next/dist/client/components/static-generation-async-storage.external.js")},399:e=>{"use strict";e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},7147:e=>{"use strict";e.exports=require("fs")},1017:e=>{"use strict";e.exports=require("path")},5259:(e,s,t)=>{"use strict";t.r(s),t.d(s,{GlobalError:()=>n.a,__next_app__:()=>m,originalPathname:()=>x,pages:()=>c,routeModule:()=>p,tree:()=>d});var a=t(482),r=t(9108),i=t(2563),n=t.n(i),o=t(8300),l={};for(let e in o)0>["default","tree","pages","GlobalError","originalPathname","__next_app__","routeModule"].indexOf(e)&&(l[e]=()=>o[e]);t.d(s,l);let d=["",{children:["(dashboard)",{children:["dashboard",{children:["sites",{children:["__PAGE__",{},{page:[()=>Promise.resolve().then(t.bind(t,16)),"C:\\xampp\\htdocs\\AI Woo Chat\\src\\app\\(dashboard)\\dashboard\\sites\\page.tsx"]}]},{}]},{}]},{layout:[()=>Promise.resolve().then(t.bind(t,1824)),"C:\\xampp\\htdocs\\AI Woo Chat\\src\\app\\(dashboard)\\layout.tsx"]}]},{layout:[()=>Promise.resolve().then(t.bind(t,1342)),"C:\\xampp\\htdocs\\AI Woo Chat\\src\\app\\layout.tsx"],"not-found":[()=>Promise.resolve().then(t.bind(t,8206)),"C:\\xampp\\htdocs\\AI Woo Chat\\src\\app\\not-found.tsx"]}],c=["C:\\xampp\\htdocs\\AI Woo Chat\\src\\app\\(dashboard)\\dashboard\\sites\\page.tsx"],x="/(dashboard)/dashboard/sites/page",m={require:t,loadChunk:()=>Promise.resolve()},p=new a.AppPageRouteModule({definition:{kind:r.x.APP_PAGE,page:"/(dashboard)/dashboard/sites/page",pathname:"/dashboard/sites",bundlePath:"",filename:"",appPaths:[]},userland:{loaderTree:d}})},5682:(e,s,t)=>{Promise.resolve().then(t.bind(t,2666))},2666:(e,s,t)=>{"use strict";t.r(s),t.d(s,{default:()=>l});var a=t(5344),r=t(3729),i=t(6506),n=t(3890),o=t(7374);function l(){let[e,s]=(0,r.useState)([]),[t,l]=(0,r.useState)(!0),[d,c]=(0,r.useState)(null),[x,m]=(0,r.useState)(null),[p,u]=(0,r.useState)(null),[h,g]=(0,r.useState)(""),[b,y]=(0,r.useState)(null);async function f(){try{l(!0),c(null);let e=(0,n.e)(),{data:{user:t},error:a}=await e.auth.getUser();if(a||!t)throw Error("User not authenticated");let{data:r,error:i}=await e.from("user_tenants").select("tenant_id").eq("user_id",t.id);if(i)throw console.error("Error loading user tenants:",i),Error(`Failed to load user tenants: ${i.message}`);if(!r||0===r.length){console.warn("No tenant found for user:",t.id),s([]),l(!1);return}let o=r[0].tenant_id,{data:d,error:x}=await e.from("sites").select(`
          *,
          license:licenses (
            id,
            license_key,
            status,
            expires_at,
            max_sites,
            plan_limits
          )
        `).eq("tenant_id",o).order("last_paired_at",{ascending:!1,nullsFirst:!1});if(x)throw Error(x.message||"Failed to load sites");s(d||[])}catch(e){c(e instanceof Error?e.message:"Failed to load sites"),console.error("Error loading sites:",e)}finally{l(!1)}}async function j(e){if(confirm("Are you sure you want to detach this site? This will disable chat for this domain."))try{m(e),c(null);let s=await fetch("/api/sites/detach",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({site_id:e})});if(!s.ok){let e=await s.json();throw Error(e.error?.message||"Failed to detach site")}await f()}catch(e){c(e instanceof Error?e.message:"Failed to detach site")}finally{m(null)}}async function _(e,s){if(!s||!s.startsWith("http")){c("Please enter a valid URL (must start with http:// or https://)");return}try{u(e),c(null);let t=await fetch("/api/sites/promote",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({site_id:e,new_site_url:s,new_environment:"production"})});if(!t.ok){let e=await t.json();throw Error(e.error?.message||"Failed to promote site")}let a=await t.json();y(null),g(""),await f(),a.site_secret&&alert(`Site promoted successfully! New site secret: ${a.site_secret}

Update your WordPress plugin with this new secret.`)}catch(e){c(e instanceof Error?e.message:"Failed to promote site")}finally{u(null)}}return((0,r.useEffect)(()=>{f()},[]),t)?(0,a.jsxs)("div",{className:"p-6",children:[a.jsx("h1",{className:"text-2xl font-bold text-gray-900 mb-4",children:"Sites"}),a.jsx("p",{className:"text-gray-600",children:"Loading sites..."})]}):(0,a.jsxs)("div",{className:"p-6 max-w-7xl mx-auto",children:[(0,a.jsxs)("div",{className:"flex justify-between items-center mb-6",children:[a.jsx("h1",{className:"text-2xl font-bold text-gray-900",children:"Sites"}),a.jsx("button",{onClick:f,className:"px-4 py-2 bg-indigo-600 text-white rounded-md hover:bg-indigo-700 transition-colors",children:"Refresh"})]}),d&&a.jsx("div",{className:"mb-4 p-4 bg-red-100 border border-red-400 text-red-700 rounded-lg",children:d}),0===e.length?(0,a.jsxs)("div",{className:"bg-white rounded-lg shadow p-8 text-center",children:[a.jsx("p",{className:"text-gray-600 text-lg",children:"No sites found."}),a.jsx("p",{className:"text-gray-500 text-sm mt-2",children:"Activate a license to add your first site."})]}):a.jsx("div",{className:"space-y-4",children:e.map(e=>(0,a.jsxs)("div",{className:"border border-gray-200 rounded-lg p-6 bg-white shadow-sm hover:shadow-md transition-shadow",children:[(0,a.jsxs)("div",{className:"flex justify-between items-start",children:[(0,a.jsxs)("div",{className:"flex-1",children:[(0,a.jsxs)("div",{className:"flex items-center gap-3 mb-3",children:[a.jsx("h3",{className:"font-semibold text-lg text-gray-900",children:e.site_url}),a.jsx("span",{className:`px-3 py-1 text-xs font-semibold rounded-full ${"active"===e.status?"bg-green-100 text-green-800":"bg-gray-100 text-gray-800"}`,children:e.status}),a.jsx("span",{className:`px-3 py-1 text-xs font-semibold rounded-full ${"production"===e.environment?"bg-blue-100 text-blue-800":"bg-yellow-100 text-yellow-800"}`,children:e.environment})]}),(0,a.jsxs)("div",{className:"space-y-1 text-sm text-gray-600",children:[e.site_name&&(0,a.jsxs)("p",{children:[a.jsx("span",{className:"font-medium",children:"Name:"})," ",e.site_name]}),e.last_paired_at&&(0,a.jsxs)("p",{children:[a.jsx("span",{className:"font-medium",children:"Last Paired:"})," ",(0,o.o0)(e.last_paired_at)]}),e.disabled_at&&(0,a.jsxs)("p",{className:"text-red-600",children:[a.jsx("span",{className:"font-medium",children:"Disabled:"})," ",(0,o.o0)(e.disabled_at)]}),(0,a.jsxs)("p",{children:[a.jsx("span",{className:"font-medium",children:"Site ID:"})," ",a.jsx("code",{className:"text-xs bg-gray-100 px-2 py-1 rounded",children:e.id})]}),(0,a.jsxs)("p",{children:[a.jsx("span",{className:"font-medium",children:"Created:"})," ",(0,o.o0)(e.created_at)]}),e.allowed_origins&&e.allowed_origins.length>0&&(0,a.jsxs)("div",{className:"mt-2",children:[a.jsx("p",{className:"text-xs font-semibold text-gray-700 mb-1",children:"Allowed Origins (CORS):"}),a.jsx("div",{className:"space-y-0.5",children:e.allowed_origins.map((e,s)=>a.jsx("code",{className:"block text-xs bg-gray-100 px-2 py-1 rounded text-gray-800",children:e},s))})]}),e.license&&(0,a.jsxs)("div",{className:"mt-4 pt-4 border-t border-gray-200",children:[a.jsx("p",{className:"text-sm font-semibold text-gray-900 mb-2",children:"License Information"}),(0,a.jsxs)("div",{className:"space-y-1 text-sm text-gray-600",children:[(0,a.jsxs)("p",{children:[a.jsx("span",{className:"font-medium",children:"License Key:"})," ",(0,a.jsxs)("code",{className:"text-xs bg-gray-100 px-2 py-1 rounded",children:[e.license.license_key.substring(0,20),"..."]})]}),(0,a.jsxs)("p",{children:[a.jsx("span",{className:"font-medium",children:"Status:"})," ",a.jsx("span",{className:`px-2 py-1 text-xs font-semibold rounded-full ${"active"===e.license.status?"bg-green-100 text-green-800":"expired"===e.license.status?"bg-red-100 text-red-800":"revoked"===e.license.status?"bg-gray-100 text-gray-800":"bg-yellow-100 text-yellow-800"}`,children:e.license.status})]}),e.license.expires_at?(0,a.jsxs)("p",{children:[a.jsx("span",{className:"font-medium",children:"Expires:"})," ",(0,a.jsxs)("span",{className:new Date(e.license.expires_at)<new Date?"text-red-600 font-semibold":new Date(e.license.expires_at)<new Date(Date.now()+2592e6)?"text-yellow-600 font-semibold":"text-gray-900",children:[(0,o.o0)(e.license.expires_at),new Date(e.license.expires_at)<new Date&&" (Expired)",new Date(e.license.expires_at)>=new Date&&new Date(e.license.expires_at)<new Date(Date.now()+2592e6)&&" (Expires soon)"]})]}):(0,a.jsxs)("p",{children:[a.jsx("span",{className:"font-medium",children:"Expires:"})," ",a.jsx("span",{className:"text-gray-500",children:"Never (Lifetime license)"})]}),e.license.plan_limits&&(0,a.jsxs)("div",{className:"mt-2 pt-2 border-t border-gray-100",children:[a.jsx("p",{className:"text-xs font-semibold text-gray-700 mb-1",children:"Plan Limits:"}),(0,a.jsxs)("div",{className:"text-xs text-gray-600 space-y-0.5",children:[e.license.plan_limits.max_tokens_per_day&&(0,a.jsxs)("p",{children:["• Tokens/day: ",e.license.plan_limits.max_tokens_per_day.toLocaleString()]}),e.license.plan_limits.max_chat_requests_per_day&&(0,a.jsxs)("p",{children:["• Requests/day: ",e.license.plan_limits.max_chat_requests_per_day.toLocaleString()]}),e.license.plan_limits.max_sites&&(0,a.jsxs)("p",{children:["• Max Sites: ",e.license.max_sites]})]})]})]})]})]})]}),(0,a.jsxs)("div",{className:"flex flex-col gap-2 ml-4",children:[(0,a.jsxs)("div",{className:"flex gap-2 flex-wrap",children:[a.jsx(i.default,{href:`/dashboard/conversations?site_id=${e.id}`,className:"px-3 py-1.5 text-xs font-medium text-indigo-600 bg-indigo-50 rounded-md hover:bg-indigo-100 transition-colors",title:"View Conversations",children:"\uD83D\uDCAC Conversations"}),a.jsx(i.default,{href:`/dashboard/analytics?site_id=${e.id}`,className:"px-3 py-1.5 text-xs font-medium text-purple-600 bg-purple-50 rounded-md hover:bg-purple-100 transition-colors",title:"View Analytics",children:"\uD83D\uDCCA Analytics"}),a.jsx(i.default,{href:`/dashboard/settings/voice?site_id=${e.id}`,className:"px-3 py-1.5 text-xs font-medium text-gray-600 bg-gray-50 rounded-md hover:bg-gray-100 transition-colors",title:"Settings",children:"⚙️ Settings"}),a.jsx("button",{onClick:()=>{navigator.clipboard.writeText(e.id),alert("Site ID copied to clipboard!")},className:"px-3 py-1.5 text-xs font-medium text-blue-600 bg-blue-50 rounded-md hover:bg-blue-100 transition-colors",title:"Copy Site ID",children:"\uD83D\uDCCB Copy ID"})]}),"active"===e.status&&(0,a.jsxs)(a.Fragment,{children:[a.jsx("button",{onClick:()=>y(e.id),className:"px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700 text-sm font-medium transition-colors",disabled:p===e.id,children:"Promote"}),a.jsx("button",{onClick:()=>j(e.id),className:"px-4 py-2 bg-red-600 text-white rounded-md hover:bg-red-700 text-sm font-medium transition-colors",disabled:x===e.id,children:x===e.id?"Detaching...":"Detach"})]})]})]}),b===e.id&&(0,a.jsxs)("div",{className:"mt-4 p-4 bg-gray-50 rounded-lg border border-gray-200",children:[a.jsx("h4",{className:"font-semibold text-gray-900 mb-2",children:"Promote to Production"}),(0,a.jsxs)("div",{className:"flex gap-2",children:[a.jsx("input",{type:"url",value:h,onChange:e=>g(e.target.value),placeholder:"https://example.com",className:"flex-1 px-3 py-2 border border-gray-300 rounded-md text-gray-900 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500"}),a.jsx("button",{onClick:()=>_(e.id,h),className:"px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700 transition-colors",disabled:p===e.id,children:p===e.id?"Promoting...":"Promote"}),a.jsx("button",{onClick:()=>{y(null),g("")},className:"px-4 py-2 bg-gray-200 text-gray-700 rounded-md hover:bg-gray-300 transition-colors",children:"Cancel"})]})]})]},e.id))})]})}},16:(e,s,t)=>{"use strict";t.r(s),t.d(s,{$$typeof:()=>i,__esModule:()=>r,default:()=>n});let a=(0,t(6843).createProxy)(String.raw`C:\xampp\htdocs\AI Woo Chat\src\app\(dashboard)\dashboard\sites\page.tsx`),{__esModule:r,$$typeof:i}=a,n=a.default}};var s=require("../../../../webpack-runtime.js");s.C(e);var t=e=>s(s.s=e),a=s.X(0,[1638,9989,665,1476,6040,867,9599],()=>t(5259));module.exports=a})();