1import{Y as G,c as R,u as z,r as d,C as J,D as B,T as L,j as r,L as W,S as X,i as K,B as j,k as H,q as Z,z as ee,U as h,ao as re,v as te}from"./index-qc8x9XuO.js";import{I as se}from"./InquiryModal-BuG01UBI.js";import{S as ae}from"./StoreProductEditor-CEQsOQ-9.js";import{u as ne,i as P,c as oe}from"./StoreCard-H06fpSzw.js";import{S as ie,a as le,b as ce,c as de,d as F}from"./select-DasM9AUZ.js";import{r as q}from"./useStoreCatalog-CrUtqWMp.js";import"./textarea-25tLH04w.js";import"./checkbox-BEP9drW0.js";import"./search-DG3rFfW7.js";const k=Z;function ue({option:e}){const{values:c}=te("artwork_print_option",e.id,{owner_label:{source:e.owner_label,zh:e.owner_label_zh}});return r.jsx(r.Fragment,{children:c.owner_label||e.owner_label})}function be(){const{kind:e,id:c}=G(),{user:a,loading:s}=R(),{t:l}=z(),[f,u]=d.useState(!1),p=!s&&(!!a||J());d.useEffect(()=>{!s&&!p&&(B({kind:"feed_gate"}),u(!0))},[s,p]);const i=L({queryKey:["store-product",e,c,(a==null?void 0:a.id)??"anonymous"],enabled:p&&["print","merchandise"].includes(e||""),staleTime:0,refetchInterval:3e4,queryFn:async({signal:E})=>{const{data:x,error:y}=await k.from("store_catalog").select("*").eq("id",`${e}:${c}`).maybeSingle().abortSignal(E);if(y)throw y;return x}});return r.jsxs(W,{children:[r.jsx(X,{title:`${l("store","store")} | Artology`,description:l("store","intro"),path:`/store/${e}/${c}`,noindex:!0}),r.jsxs("div",{className:"mx-auto max-w-6xl px-6 pb-20 pt-28",children:[r.jsx(K,{to:"/store",className:"mb-8 inline-block text-sm underline underline-offset-4",children:l("store","backToStore")}),p&&(i.isLoading?r.jsx("p",{role:"status",children:l("store","loading")}):i.isError?r.jsxs("div",{role:"alert",children:[r.jsx("p",{children:l("store","loadError")}),r.jsx(j,{variant:"outline",className:"mt-3",onClick:()=>i.refetch(),children:l("store","retry")})]}):i.data?r.jsx(pe,{item:i.data,refresh:i.refetch},i.data.id):r.jsx("p",{children:l("store","unavailable")}))]}),r.jsx(H,{open:f,onOpenChange:u})]})}function pe({item:e,refresh:c}){const{t:a}=z(),{user:s}=R(),{values:l}=ne(e),[f,u]=ee(),[p,i]=d.useState(!1),[E,x]=d.useState(!1),[y,N]=d.useState(!1),[A,_]=d.useState(!1),m=l.title||e.title,g=(f.get("options")||"").split(",").filter(Boolean),b=L({queryKey:["store-print-options",e.id,s==null?void 0:s.id],enabled:e.kind==="print",staleTime:0,refetchInterval:3e4,queryFn:async({signal:t})=>{const{data:o,error:n}=await k.from("artwork_print_options").select("*").eq("artwork_id",e.entity_id).eq("is_active",!0).order("sort_order").abortSignal(t);if(n)throw n;return o||[]}}),w=b.data||[],M=[...new Set(w.map(t=>t.option_group))],v=w.filter(t=>g.includes(t.id)),O=e.kind!=="print"||!b.isLoading&&!b.isError&&v.length===g.length&&v.some(t=>["size","media"].includes(t.option_group))&&v.every(t=>P(t.inventory_quantity,t.made_to_order)),S=L({queryKey:["store-saved",e.id,s==null?void 0:s.id],enabled:!!s,queryFn:async()=>{const{data:t,error:o}=await k.from("store_interactions").select("item_id").eq("item_id",e.id).eq("user_id",s.id).eq("event_type","save").maybeSingle();if(o)throw o;return!!t}});d.useEffect(()=>{s&&e.available&&q(e.id,"view").catch(()=>{})}
1,[s==null?void 0:s.id,e.id,e.available]);const C=()=>u(t=>{const o=new URLSearchParams(t);return o.delete("action"),o},{replace:!0});d.useEffect(()=>{if(!s)return;const t=f.get("action");t==="inquire"&&O&&e.available&&(C(),x(!0),i(!1)),t==="save"&&e.available&&(C(),q(e.id,"save").then(()=>S.refetch()).catch(()=>h.error(a("store","saveError"))),i(!1))},[s==null?void 0:s.id,f,O,e.available]);const T=t=>{u(o=>{const n=new URLSearchParams(o);return n.set("action",t),n},{replace:!0}),B({kind:"other"}),i(!0)},Q=async()=>{if(!s){T("inquire");return}_(!0);try{await c();const{data:t,error:o}=await k.from("store_catalog").select("available").eq("id",e.id).maybeSingle();if(o)throw o;if(!(t!=null&&t.available)){h.error(a("store","unavailable"));return}x(!0)}catch{h.error(a("store","loadError"))}finally{_(!1)}},V=async()=>{try{const t=new URL(window.location.href);t.searchParams.delete("action"),navigator.share?await navigator.share({title:m,url:t.href}):(await navigator.clipboard.writeText(t.href),h.success(a("store","linkCopied"))),s&&q(e.id,"share").catch(()=>{})}catch(t){t.name!=="AbortError"&&h.error(a("store","shareError"))}};return r.jsxs("div",{className:"grid gap-10 md:grid-cols-2",children:[r.jsx("div",{className:"flex aspect-square items-center justify-center bg-muted",children:e.image_url?r.jsx("img",{src:e.image_url,alt:m,className:"h-full w-full object-contain"}):r.jsx("p",{className:"p-6 font-serif text-2xl",children:m})}),r.jsxs("div",{children:[r.jsx("p",{className:"text-xs uppercase tracking-widest text-muted-foreground",children:a("store",e.category)}),r.jsx("h1",{className:"mt-3 font-serif text-3xl",children:m}),r.jsx("p",{className:"mt-3 text-muted-foreground",children:e.creator}),r.jsx("p",{className:"mt-5 font-serif text-xl",children:r.jsx(oe,{item:e})}),l.description&&r.jsx("p",{className:"mt-6 whitespace-pre-line text-sm leading-7 text-muted-foreground",children:l.description}),e.kind==="print"&&r.jsxs("div",{className:"mt-6 space-y-4",children:[r.jsx("p",{className:"text-sm text-muted-foreground",children:a("store","printHelp")}),b.isError&&r.jsx("p",{role:"alert",children:a("store","loadError")}),M.map(t=>{var o;return r.jsxs("div",{children:[r.jsx(re,{htmlFor:`print-${t}`,children:a("store",`option_${t}`)}),r.jsxs(ie,{value:((o=v.find(n=>n.option_group===t))==null?void 0:o.id)||"none",onValueChange:n=>u(D=>{const $=new URLSearchParams(D),I=g.filter(Y=>!w.some(U=>U.id===Y&&U.option_group===t));return n!=="none"&&I.push(n),$.set("options",I.join(",")),$},{replace:!0}),children:[r.jsx(le,{id:`print-${t}`,className:"mt-2",children:r.jsx(ce,{})}),r.jsxs(de,{children:[r.jsx(F,{value:"none",children:a("store","selectOption")}),w.filter(n=>n.option_group===t).map(n=>r.jsxs(F,{value:n.id,disabled:!P(n.inventory_quantity,n.made_to_order),children:[r.jsx(ue,{option:n}),P(n.inventory_quantity,n.made_to_order)?"":` · ${a("store","soldOut")}`]},n.id))]})]})]},t)})]}),r.jsx("p",{className:"mt-6 text-sm text-muted-foreground",children:a("store","inquiryHelp")}),e.made_to_order&&r.jsx("p",{className:"mt-2 text-sm",children:a("store","madeToOrder")}),r.jsxs("div",{className:"mt-6 flex flex-wrap gap-3",children:[r.jsx(j,{disabled:!e.available||!O||A||e.seller_id===(s==null?void 0:s.id),onClick:Q,children:a("store","inquire")}),r.jsx(j,{variant:"outline",disabled:!e.available||A||e.seller_id===(s==null?void 0:s.id),onClick:async()=>{if(!s){T("save");return}_(!0);try{await q(e.id,"save",!!S.data),await S.refetch()}catch{h.error(a("store","saveError"))}finally{_(!1)}},children:a("store",S.data?"unsave":"save")}),r.jsx(j,{variant:"outline",onClick:V,children:a("store","share")})]}),e.seller&&r.jsxs("p",{className:"mt-6 text-sm text-muted-foreground",children:[a("store","seller"),": ",e.seller]}),e.kind==="print"&&r.jsx(K,{to:`/art/${e.entity_id}`,className:"mt-6 inline-block text-sm underline underline-offset-4",children:a("store","sourceArtwork")})]}),e.seller_id===(s==null?void 0:s.id)&&e.kind==="merchandise"&&r.jsx(j,{variant:"outline",onClick:()=>N(!0),children:a("store","editProduct")}),y&&r.jsx(ae,{id:e.entity_id,onClose:()=>N(!1),onSaved:()=>{N(!1),c()}}),r.jsx(H,{open:p,onOpenChange:t=>{i(t),!t&&!s&&C()}}),E&&s&&r.jsx(se,{context:{type:e.kind==="print"?"store_print":"store_merchandise",id:e.entity_id},previewTitle:m,previewSubtitle:v.map(t=>t.owner_label).join(", ")||e.creator||"",previewImageUrl:e.image_url,storeOptionIds:g,onClose:()=>x(!1)})]})}export{be 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.