1import{j as e,r,L as P,a as D}from"./app-Vm5ePdMG.js";import{t as $,S as E}from"./SwitchModal-a_1VrIks.js";/* empty css */import"./use-resolve-button-type-qR7fzKAw.js";import"./portal-Bfa2P73q.js";import"./use-server-handoff-complete-BSFtZuWv.js";import"./transition-DysxTPJG.js";import"./dialog-_CJWmfbp.js";const m=({title:c,onClick:o,sortDirection:n})=>e.jsxs("th",{scope:"col",className:"px-6 py-3 cursor-pointer",onClick:o,children:[c," ",n==="asc"?e.jsx("span",{className:"ml-1",children:"â²"}):e.jsx("span",{className:"ml-1",children:"â¼"})]}),H=({products:c})=>{const[o,n]=r.useState(c),[l,f]=r.useState("asc"),[d,g]=r.useState("name"),[p,h]=r.useState("enabled"),[y,u]=r.useState(!1),[j,k]=r.useState(""),[N,_]=r.useState(""),[w,C]=r.useState(()=>{}),S=(t,i,s)=>{k(t),_(i),C(()=>s),u(!0)},b=()=>u(!1);r.useEffect(()=>{n(c)},[c]);const x=t=>{const i=[...o].sort((s,a)=>{if(l==="asc"){if(t==="name")return s.name.localeCompare(a.name);if(t==="category")return s.product_category.localeCompare(a.product_category);if(t==="price")return s.price-a.price;if(t==="id")return(s.id||0)-(a.id||0);if(t==="id_from_api")return(s.amp_id||0)-(a.amp_id||0)}else{if(t==="name")return a.name.localeCompare(s.name);if(t==="category")return a.product_category.localeCompare(s.product_category);if(t==="price")return a.price-s.price;if(t==="id")return(a.amp_id||0)-(s.amp_id||0)}});f(l==="asc"?"desc":"asc"),n(i),g(t)},v=t=>{S("Change Public Status",`Are you sure you want to change the public status of "${t.name}"?`,()=>{D.patch(`/admin/products/${t.id}/public`,{isPublic:!t.is_public}),b()})},M=o.filter(t=>p==="enabled"?t.is_enabled:!t.is_enabled);return e.jsxs("div",{className:"relative overflow-x-auto shadow-md sm:rounded-lg",children:[e.jsxs("div",{className:"flex justify-end items-center mb-4",children:[e.jsx("button",{className:`h-12 px-4 py-2 ${p==="enabled"?"bg-blue-500 text-white":"bg-gray-200 text-gray-700"}`,onClick:()=>h("enabled"),children:"Enabled"}),e.jsx("button",{className:`h-12 px-4 py-2 ml-2 ${p==="disabled"?"bg-blue-500 text-white":"bg-gray-200 text-gray-700"}`,onClick:()=>h("disabled"),children:"Disabled"})]}),e.jsxs("table",{className:"w-full text-sm text-left rtl:text-right",children:[e.jsx("thead",{className:"text-xs text-gray-700 uppercase bg-gray-50 border-stroke dark:border-strokedark dark:bg-boxdark",children:e.jsxs("tr",{children:[e.jsx(m,{title:"ID",onClick:()=>x("id"),sortDirection:d==="id"?l:void 0}),e.jsx(m,{title:"AMP ID",onClick:()=>x("id_from_api"),sortDirection:d==="id_from_api"?l:void 0}),e.jsx(m,{title:"Name",onClick:()=>x("name"),sortDirection:d==="name"?l:void 0}),e.jsx(m,{title:"Category",onClick:()=>x("category"),sortDirection:d==="category"?l:void 0}),e.jsx("th",{scope:"col",className:"px-6 py-3",children:"Prices"}),e.jsx("th",{scope:"col",className:"px-6 py-3",children:"Edit"}),e.jsx("th",{scope:"col",className:"px-6 py-3",children:"View"}),e.jsx("th",{scope:"col",className:"px-6 py-3",children:"Public"})]})}),e.jsx("tbody",{children:M.map(t=>e.jsxs("tr",{className:"border-b border-t border-stroke dark:border-strokedark dark:bg-boxdark",children:[e.jsx("td",{className:"px-6 py-4 text-black dark:text-white",children:t.id}),e.jsx("td",{className:"px-6 py-4 text-black dark:text-white",children:t.id_from_api||"-"}),e.jsx("td",{scope:"row",className:"px-6 py-4 font-medium text-gray-900 whitespace-nowrap text-black dark:text-white",children:t.name}),e.jsx("td",{className:"px-6 py-4 text-black dark:text-white"}),e.jsx("td",{className:"px-6 py-4",children:e.jsx("ul",{className:"list-disc list-inside",children:t.prices&&t.prices.map(i=>e.jsx("li",{className:"text-black text-xs",children:`${i.label} (${i.price_id_from_api})`},i.id))})}),e.jsx("td",{className:"px-6 py-4",children:e.jsx(P,{className:"font-medium text-blue-600 dark:text-blue-500 hover:underline",href:`/admin/products/${t.id}/edit`,children:"Edit"})}),e.jsx("td",{className:"px-6 py-4",children:t.slug&&e.jsx("a",{className:"font-medium text-green-600 dark:text-green-500 hover:underline",href:"/"+t.slug,target:"_blank",children:"View"})}),e.jsx("td",{className:"px-6 py-4",children:e.jsx($,{checked:t.is_public||!1,onChange:()=>{v(t)},className:`${t.is_public?"bg-blue-500":"bg-graydark"} relative inline-flex h-6 w-11 items-center rounded-full`,children:e.jsx("span",{className:`${t.is_public?"translate-x-6":"translate-x-1"} inline-block h-4 w-4 transform rounded-full bg-white transition-transform`})})})]},t.id))})]}),e.jsx(E,{isOpen:y,closeModal:b,confirmAction:w,title:j,message:N})]})};export{H as ProductTable};
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.