1import{u as C,b as E,r as a,j as e,s as h}from"./site-C5SUB8ov.js";import{u as _,z as I,L as T,a6 as q,a0 as f}from"./main-_fPdXjGG.js";import{a as $}from"./useCanEdit-ChYkI6QT.js";import{w as K}from"./knowledgeCategories-McCxRudB.js";import{K as L}from"./KnowledgeEditor-DnHyMgXr.js";import{S as R}from"./share-2-BxiV3BDx.js";import"./index-DQRrCrNJ.js";import"./link-f4RoI0U4.js";import"./youtube-CxCa10BM.js";import"./more-horizontal-Bn16KeUJ.js";function J(){const{t}=_(),c=C(),{companyId:r,baseId:o}=E(),[n,y]=a.useState(""),[m,k]=a.useState(null),[v,j]=a.useState(""),[i,g]=a.useState(!1),[u,l]=a.useState(null),d=`/${r}/knowledge/${o}`,S=$("knowledge",d),x=async(p=!1)=>{if(S){if(!n.trim()){l(t("knowledge.errors.titleRequired"));return}l(null),g(!0);try{const{data:{session:s}}=await h.auth.getSession();if(!s)throw new Error(t("knowledge.errors.notAuthenticated"));const b=new Date().toISOString(),{data:N,error:w}=await h.from("knowledge_items").insert([{knowledge_base_id:o,company_id:r,question:n.trim(),answer:v,tags:K(null,m),created_by:s.user.id,created_at:b,updated_at:b,is_published:p}]).select("id").single();if(w)throw w;p?(await navigator.clipboard.writeText(`${window.location.origin}/public/knowledge/${N.id}`),f.success(t("knowledge.success.published"))):f.success(t("knowledge.success.saved")),c(d)}catch(s){console.error("Failed to save knowledge item:",s),l(s instanceof Error?s.message:String(s))}finally{g(!1)}}};return e.jsxs("div",{className:"min-h-screen bg-white",children:[e.jsx("div",{className:"sticky top-0 z-30 border-b border-gray-200 bg-white/95 backdrop-blur",children:e.jsxs("div",{className:"max-w-3xl mx-auto px-4 h-14 flex items-center justify-between gap-3",children:[e.jsxs("button",{type:"button",onClick:()=>c(d),className:"inline-flex items-center gap-2 text-sm text-gray-500 hover:text-gray-900 transition-colors",children:[e.jsx(I,{className:"w-4 h-4"}),t("knowledge.backToBase")]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>x(),disabled:i,className:"inline-flex items-center gap-2 rounded-lg border border-gray-200 px-3 py-1.5 text-sm font-medium text-gray-700 hover:bg-gray-50 disabled:opacity-60",children:[i?e.jsx(T,{className:"w-4 h-4 animate-spin"}):e.jsx(q,{className:"w-4 h-4"}),t("common.save")]}),e.jsxs("button",{type:"button",onClick:()=>x(!0),disabled:i,className:"inline-flex items-center gap-2 rounded-lg bg-indigo-600 px-3 py-1.5 text-sm font-medium text-white hover:bg-indigo-700 disabled:opacity-60",children:[e.jsx(R,{className:"w-4 h-4"}),t("knowledge.publish")]})]})]})}),e.jsxs("div",{className:"max-w-3xl mx-auto px-4 py-10",children:[u&&e.jsx("div",{className:"mb-6 rounded-xl border border-red-200 bg-red-50 px-4 py-3 text-sm text-red-700",children:u}),e.jsx(L,{title:n,onTitleChange:y,category:m,onCategoryChange:k,onContentChange:j,companyId:r||"",baseId:o||""})]})]})}export{J as CreateKnowledgeItemPage,J 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.