1import{j as e}from"./admin-vendor-B_1xywrZ.js";import{d as t,r as a}from"./react-vendor-DOiMLSFB.js";import{s}from"./supabaseClient-DWlX2bJJ.js";import"./data-vendor-CIxtln5N.js";const r=()=>{const r=t(),[l,i]=a.useState([]),[n,d]=a.useState(!0),[c,o]=a.useState(null),[p,m]=a.useState({title:"",content:"",data_type:"general",source_url:"",is_active:!0,metadata:{page_path:"",page_title:"",page_type:""}});a.useEffect(()=>{u()},[]),a.useEffect(()=>{m(e=>({...e,metadata:{page_path:r.pathname,page_title:document.title,page_type:x(r.pathname)}}))},[r]);const x=e=>e.startsWith("/products/")?"product":e.startsWith("/blog/")?"blog":e.startsWith("/admin/")?"page":e.includes("policy")?"policy":"general",u=async()=>{try{const{data:e,error:t}=await s.from("ai_training_data").select("*").order("created_at",{ascending:!1});if(t)throw t;i(e||[])}catch(e){alert("Failed to load training data. Please check the console for details.")}finally{d(!1)}};return n?e.jsx("div",{children:"Loading..."}):e.jsxs("div",{className:"p-6",children:[e.jsx("h1",{className:"text-2xl font-bold mb-6",children:"AI Training Data Manager"}),e.jsxs("form",{onSubmit:async e=>{e.preventDefault();try{const{data:{user:e}}=await s.auth.getUser(),t={...p,created_by:e?.id,updated_by:e?.id};if(c){const{error:e}=await s.from("ai_training_data").update(t).eq("id",c.id);if(e)throw e}else{const{error:e}=await s.from("ai_training_data").insert([t]);if(e)throw e}m({title:"",content:"",data_type:"general",source_url:"",is_active:!0,metadata:{page_path:r.pathname,page_title:document.title,page_type:x(r.pathname)}}),o(null),u()}catch(t){alert("Failed to save training data. Please check the console for details.")}},className:"mb-8 bg-white p-6 rounded-lg shadow",children:[e.jsx("h2",{className:"text-xl font-semibold mb-4",children:c?"Edit Training Data":"Add New Training Data"}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700",children:"Title"}),e.jsx("input",{type:"text",value:p.title,onChange:e=>m({...p,title:e.target.value}),className:"mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-purple-500 focus:ring-purple-500",required:!0})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700",children:"Content"}),e.jsx("textarea",{value:p.content,onChange:e=>m({...p,content:e.target.value}),className:"mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-purple-500 focus:ring-purple-500",rows:6,required:!0})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700",children:"Type"}
1),e.jsxs("select",{value:p.data_type,onChange:e=>m({...p,data_type:e.target.value}),className:"mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-purple-500 focus:ring-purple-500",children:[e.jsx("option",{value:"product",children:"Product"}),e.jsx("option",{value:"page",children:"Page"}),e.jsx("option",{value:"blog",children:"Blog"}),e.jsx("option",{value:"policy",children:"Policy"}),e.jsx("option",{value:"general",children:"General"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700",children:"Source URL"}),e.jsx("input",{type:"url",value:p.source_url,onChange:e=>m({...p,source_url:e.target.value}),className:"mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-purple-500 focus:ring-purple-500"})]}),e.jsxs("div",{className:"flex items-center",children:[e.jsx("input",{type:"checkbox",checked:p.is_active,onChange:e=>m({...p,is_active:e.target.checked}),className:"h-4 w-4 text-purple-600 focus:ring-purple-500 border-gray-300 rounded"}),e.jsx("label",{className:"ml-2 block text-sm text-gray-900",children:"Active"})]}),e.jsxs("div",{className:"text-sm text-gray-500",children:[e.jsx("p",{children:"Current Page Context:"}),e.jsxs("p",{children:["Path: ",p.metadata.page_path]}),e.jsxs("p",{children:["Title: ",p.metadata.page_title]}),e.jsxs("p",{children:["Type: ",p.metadata.page_type]})]}),e.jsxs("div",{className:"flex justify-end space-x-4",children:[c&&e.jsx("button",{type:"button",onClick:()=>{o(null),m({title:"",content:"",data_type:"general",source_url:"",is_active:!0,metadata:{page_path:r.pathname,page_title:document.title,page_type:x(r.pathname)}})},className:"px-4 py-2 border border-gray-300 rounded-md text-gray-700 hover:bg-gray-50",children:"Cancel"}),e.jsxs("button",{type:"submit",className:"px-4 py-2 bg-purple-600 text-white rounded-md hover:bg-purple-700",children:[c?"Update":"Add"," Training Data"]})]})]})]}),e.jsx("div",{className:"bg-white rounded-lg shadow overflow-hidden",children:e.jsxs("table",{className:"min-w-full divide-y divide-gray-200",children:[e.jsx("thead",{className:"bg-gray-50",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Title"}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Type"}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Status"}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Actions"})]})}),e.jsx("tbody",{className:"bg-white divide-y divide-gray-200",children:l.map(t=>e.jsxs("tr",{children:[e.jsx("td",{className:"px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900",children:t.title}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap text-sm text-gray-500",children:t.data_type}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap text-sm text-gray-500",children:e.jsx("span",{className:"px-2 inline-flex text-xs leading-5 font-semibold rounded-full "+(t.is_active?"bg-green-100 text-green-800":"bg-red-100 text-red-800"),children:t.is_active?"Active":"Inactive"})}),e.jsxs("td",{className:"px-6 py-4 whitespace-nowrap text-sm text-gray-500",children:[e.jsx("button",{onClick:()=>(e=>{o(e),m({title:e.title,content:e.content,data_type:e.data_type,source_url:e.source_url||"",is_active:e.is_active,metadata:e.metadata||{page_path:r.pathname,page_title:document.title,page_type:x(r.pathname)}})})(t),className:"text-purple-600 hover:text-purple-900 mr-4",children:"Edit"}),e.jsx("button",{onClick:()=>(async e=>{if(confirm("Are you sure you want to delete this training data?"))try{const{error:t}=await s.from("ai_training_data").delete().eq("id",e);if(t)throw t;u()}catch(t){alert("Failed to delete training data. Please check the console for details.")}})(t.id),className:"text-red-600 hover:text-red-900",children:"Delete"})]})]},t.id))})]})})]})},l=()=>e.jsxs("div",{className:"container mx-auto px-4 py-8",children:[e.jsx("h1",{className:"text-3xl font-bold mb-8",children:"AI Training Management"}),e.jsx(r,{})]});
1export{l as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.