import{r as $,R as t}from"./app-b4140d27.js";import{a as D}from"./axios-004a8e66.js";import{u as M,S as R,_ as G,A as I}from"./react-select-async.esm-8108584f.js";var N=$.forwardRef(function(l,n){var o=M(l);return $.createElement(R,G({ref:n},o))}),q=N;function B({index:l,work:n,showPriceSelector:o,showWorkSelector:d,selectWorkForIndex:u,selectPriceForIndex:s}){var y,v,S,P;const[h,m]=t.useState(T(n)),[r,i]=t.useState({value:n.selected_price,label:f(n.selected_price)}),[x,C]=t.useState(n.selected_edition?{value:n.selected_edition,label:n.selected_edition.inventory_id+` (${g(n.selected_edition)})`}:null);function T(e){return e.selected_edition?_(e.selected_edition.prices):_(e.prices)}function F(e){if(e.length===0)return"";const a=e[0];return`${a.width} x ${a.height}`+(a.depth>0?` x ${a.depth}`:"")+` ${a.unit}`}function f(e){return e?new Intl.NumberFormat([],{style:"currency",currency:e.currency,minimumFractionDigits:0,useGrouping:!0}).format(e.price):_translations.no_price}function g(e){return e.total_serie===1&&e.type.id===1?"única":"Ed. "+e.num_serie+"/"+e.total_serie+(e.type.id!==1?` ${e.type.code}`:"")}const O=(e,a)=>{D({url:"/get_work_editions",method:"GET",params:{search:e}}).then(b=>{let p=[];b.data.forEach(c=>{typeof p[c.work_id]>"u"&&(p[c.work_id]={label:c.name,options:[]}),p[c.work_id].options.push({value:c,label:c.inventory_id+` (${g(c)})`})}),a(p)})},W=e=>{i(e),s&&s(l,e.value)},A=e=>{let a=e?e.value.prices:n.prices;m(_(a));let b=a.length>0?E(a[0]):{value:"",label:_translations.no_price};i(b),C(e),u&&u(l,e?e.value:null),s&&s(l,a.length>0?a[0]:null)};function E(e){return{value:e,label:f(e)}}function _(e){return!e||e.length===0?[]:e.map(a=>E(a)).concat([{value:"",label:_translations.no_price}])}return t.createElement("tr",null,t.createElement("td",null,t.createElement("img",{src:n.main_image,alt:n.name,style:{width:"60px",height:"60px"}})),t.createElement("td",null,((y=n.selected_edition)==null?void 0:y.name)??n.name),t.createElement("td",null,((v=n.selected_edition)==null?void 0:v.artist_name)??n.artist_name),t.createElement("td",null,((S=n.selected_edition)==null?void 0:S.year)??n.year),t.createElement("td",null,n.technique),t.createElement("td",null,F(((P=n.selected_edition)==null?void 0:P.dimensions)??n.dimensions)),t.createElement("td",null," ",o?t.createElement(q,{options:h,onChange:W,value:r}):f(n.selected_price)),d&&t.createElement("td",null,t.createElement(I,{loadOptions:O,placeholder:"Busque por ID inventario, nombre o artista",onChange:A,value:x,isClearable:!0,styles:{groupHeading:(e,a)=>({...e,color:"black",fontWeight:"bold"})}})))}function J({showWorkSelector:l,showPriceSelector:n,works:o,handleSelectWorkEdition:d,handleSelectPrice:u}){const s=m=>(r,i)=>{d&&d(r,i)},h=m=>(r,i)=>{u&&u(r,i)};return t.createElement("table",{className:"table table-striped table-bordered"},t.createElement("thead",null,t.createElement("tr",null,t.createElement("th",{scope:"col"},"Foto"),t.createElement("th",{scope:"col"},"Título"),t.createElement("th",{scope:"col"},"Artista"),t.createElement("th",{scope:"col"},"Año"),t.createElement("th",{scope:"col"},"Técnica"),t.createElement("th",{scope:"col"},"Dimensiones"),t.createElement("th",{scope:"col"},"Precios"),l&&t.createElement("th",{scope:"col"},"Mi obra en Exhibify/ITGallery"))),t.createElement("tbody",null,o.map((m,r)=>t.createElement(B,{key:r,index:r,work:m,showWorkSelector:l,showPriceSelector:n,selectPriceForIndex:h(),selectWorkForIndex:s()}))))}export{J as W};
