1import{r as d,aw as k,u as P,j as e,B as p,L as T,s as x,t as f}from"./index-Cnb_tvF-.js";import{C as g}from"./card-BOdJQzWn.js";import{T as S}from"./textarea-DI8BNDK1.js";import{B as o}from"./badge-W1VJbzMS.js";import{L as N}from"./label-CxkzGLev.js";import{p as _}from"./csv-CzXUclED.js";import{A as I}from"./arrow-left-D5d9wjK-.js";import{P as U}from"./play-CMpIoyCv.js";import{U as B}from"./upload-BWhJL4_N.js";function O(){const[c,m]=d.useState(""),[t,v]=d.useState(null),[h,n]=d.useState(!1),{user:l}=k(),w=P(),y=async()=>{const{data:s}=await x.from("pos_products").select("sku"),a=new Set((s??[]).map(i=>i.sku));v(_(c,a))},b=async s=>{if(!s)return;const a=await s.text();m(a)},C=async()=>{if(!t)return;n(!0);const s=t.rows.filter(i=>!i.isCategoryHeader);let a=0;for(let i=0;i<s.length;i+=200){const u=s.slice(i,i+200).map(r=>({sku:r.sku,display_name:r.description||r.sku.split(":").pop()||r.sku,category:r.category,subcategory:r.subcategory,item_type:r.type,taxable:r.taxable,price:r.price,cost:r.cost,unit:"each",active:!0})),{error:j}=await x.from("pos_products").upsert(u,{onConflict:"sku"});if(j){f({title:"Import error",description:j.message,variant:"destructive"}),n(!1);return}a+=u.length}await x.from("pos_audit_log").insert({actor_id:l==null?void 0:l.id,action:"products.import",details:{total:s.length,new:t.newCount,updated:t.updateCount}}),f({title:`Imported ${a} products`}),n(!1),w("/admin/pos/products")};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(p,{variant:"outline",size:"sm",asChild:!0,children:e.jsxs(T,{to:"/admin/pos/products",children:[e.jsx(I,{className:"h-4 w-4 mr-1"}),"Back"]})}),e.jsx("h1",{className:"text-2xl font-bold",children:"Import Products"})]}),e.jsxs(g,{className:"p-4 space-y-3",children:[e.jsxs("div",{className:"text-sm text-muted-foreground",children:["Pipe-delimited format. Header: ",e.jsx("code",{className:"bg-muted px-1",children:"sku|description|type|tax|price|cost"}),e.jsx("br",{}),"Type codes: ",e.jsx("b",{children:"Dis"}),"=discount, ",e.jsx("b",{children:"Non"}),"=non-inventory, ",e.jsx("b",{children:"Ser"}),"=service, ",e.jsx("b",{children:"Oth"}),"=other charge, ",e.jsx("b",{children:"Pay"}),"=payment. Tax: ",e.jsx("b",{children:"Tax"})," or blank/Non.",e.jsx("br",{}),"Rows with only a SKU (no description/price) are treated as categories and skipped."]}),e.jsxs("div",{children:[e.jsx(N,{children:"Upload file"}),e.jsx("input",{type:"file",accept:".txt,.csv,.iif",onChange:s=>{var a;return b(((a=s.target.files)==null?void 0:a[0])??null)},className:"block text-sm"})]}),e.jsxs("div",{children:[e.jsx(N,{children:"Or paste content"}),e.jsx(S,{rows:10,value:c,onChange:s=>m(s.target.value),className:"font-mono text-xs"})]}),e.jsx("div",{className:"flex gap-2",children:e.jsxs(p,{onClick:y,disabled:!c.trim(),children:[e.jsx(U,{className:"h-4 w-4 mr-1"}),"Preview"]})})]}),t&&e.jsxs(g,{className:"p-4 space-y-3",children:[e.jsxs("div",{className:"flex gap-3 flex-wrap",children:[e.jsxs(o,{variant:"default",children:["Total rows: ",t.rows.length]}),e.jsxs(o,{variant:"secondary",children:["New: ",t.newCount]}),e.jsxs(o,{variant:"outline",children:["Update: ",t.updateCount]}),e.jsxs(o,{variant:"outline",children:["Category headers skipped: ",t.skippedCategories]}),t.errors>0&&e.jsxs(o,{variant:"destructive",children:["Errors: ",t.errors]})]}),e.jsxs("div",{className:"max-h-80 overflow-auto border rounded",children:[e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{className:"bg-muted sticky top-0",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-left p-1",children:"SKU"}),e.jsx("th",{className:"text-left p-1",children:"Name"}),e.jsx("th",{className:"p-1",children:"Type"}),e.jsx("th",{className:"p-1",children:"Tax"}),e.jsx("th",{className:"text-right p-1",children:"Price"}),e.jsx("th",{className:"p-1"})]})}),e.jsx("tbody",{children:t.rows.slice(0,200).map((s,a)=>e.jsxs("tr",{className:`border-t ${s.isCategoryHeader?"opacity-50":""}`,children:[e.jsx("td",{className:"p-1 font-mono",children:s.sku}),e.jsx("td",{className:"p-1",children:s.description||e.jsx("em",{className:"text-muted-foreground",children:"(no desc)"})}),e.jsx("td",{className:"p-1",children:s.type}),e.jsx("td",{className:"p-1",children:s.taxable?"Y":"N"}),e.jsxs("td",{className:"p-1 text-right",children:["$",s.price.toFixed(2)]}),e.jsx("td",{className:"p-1",children:s.isCategoryHeader&&e.jsx(o,{variant:"outline",className:"text-[10px]",children:"cat"})})]},a))})]}),t.rows.length>200&&e.jsxs("div",{className:"p-2 text-center text-muted-foreground",children:["â¦",t.rows.length-200," more rows"]})]}),e.jsxs(p,{onClick:C,disabled:h,size:"lg",children:[e.jsx(B,{className:"h-4 w-4 mr-1"}),h?"Importingâ¦":`Commit Import (${t.newCount+t.updateCount} products)`]})]})]})}export{O 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.