!function(){"use strict";var e="/pos/api/catalog",a=localStorage.getItem("pos_token");if(a){var t={Authorization:"Bearer "+a,"Content-Type":"application/json"},n=document.getElementById("breadcrumb"),o=document.getElementById("searchInput"),i=document.getElementById("searchDropdown"),r=document.getElementById("levelTitle"),s=document.getElementById("levelFilter"),l=document.getElementById("loading"),d=document.getElementById("emptyState"),c=document.getElementById("emptyTitle"),u=document.getElementById("emptySubtitle"),p=document.getElementById("navGrid"),m=document.getElementById("partsGrid"),v=document.getElementById("pagination"),g=document.getElementById("pageBody"),y=document.getElementById("detailPanel"),f=document.getElementById("detailOverlay"),_=document.getElementById("detailBody"),h=document.getElementById("detailFooter"),b=document.getElementById("detailClose"),x=document.getElementById("qtyMinus"),E=document.getElementById("qtyPlus"),k=document.getElementById("qtyDisplay"),I=document.getElementById("addToCartBtn"),T=document.getElementById("cartSidebar"),S=document.getElementById("cartOverlay"),L=document.getElementById("cartItems"),C=document.getElementById("cartEmpty"),M=document.getElementById("cartSubtotal"),B=document.getElementById("cartTax"),w=document.getElementById("cartTotal"),N=document.getElementById("cartBadge"),A=document.getElementById("checkoutBtn"),H=document.getElementById("cartFab"),P=document.getElementById("cartCloseBtn"),j={level:"brands",brand:null,model:null,year:null,engine:null,category:null,group:null,partType:null,nxGroup:null,nxSubgroup:null,nxPartType:null},q="local";localStorage.setItem("catalog_mode","local");var O=1,G=null,U=1,R=!1;window.addEventListener("popstate",(function(e){e.state&&(R=!0,j.level=e.state.level||"brands",j.brand=e.state.brand,j.model=e.state.model,j.year=e.state.year,j.engine=e.state.engine,j.category=e.state.category,j.group=e.state.group,j.partType=e.state.partType||null,j.nxGroup=e.state.nxGroup||null,j.nxSubgroup=e.state.nxSubgroup||null,j.nxPartType=e.state.nxPartType||null,O=e.state.page||1,"brands"===j.level?he():"models"===j.level?be():"years"===j.level?xe():"engines"===j.level?Ee():"categories"===j.level?Te():"groups"===j.level?j.nxGroup?Se():ke():"part_types"===j.level?j.nxSubgroup?Le():Ie():"parts"===j.level?Me(O):he(),R=!1)})),history.replaceState(JSON.parse(JSON.stringify(j)),"","/pos/catalog");var $=JSON.parse(localStorage.getItem("pos_cart")||"[]"),V=null;b.addEventListener("click",Ne),f.addEventListener("click",Ne),x.addEventListener("click",(function(){U>1&&(U--,k.textContent=U)})),E.addEventListener("click",(function(){U++,k.textContent=U})),I.addEventListener("click",(function(){if(G){var e=G.part,a=G.local;a&&(qe({id:e.id_part,part_number:e.oem_part_number,name:e.name,brand:"",price:a.price_1,tax_rate:a.tax_rate||.16,unit:a.unit||"PZA",stock:a.stock,source:"local",inventory_id:a.inventory_id},U),Ne())}}));var z=null,J=null;o.addEventListener("input",(function(){clearTimeout(z);var e=this.value.trim();(He(e.length>=3?Ae(e):null),e.length<2)?i.classList.remove("is-visible"):"keyword"===Ae(e)&&(z=setTimeout((function(){je(e)}),350))})),o.addEventListener("keydown",(function(e){if("Enter"===e.key){e.preventDefault(),clearTimeout(z);var a=this.value.trim();a.length>=2&&Pe(a)}"Escape"===e.key&&(i.classList.remove("is-visible"),He(null))})),document.addEventListener("click",(function(e){i.contains(e.target)||e.target===o||i.classList.remove("is-visible")})),L.addEventListener("click",(function(e){var a=e.target.closest("[data-cart-action]");if(a){var t=parseInt(a.dataset.idx),n=a.dataset.cartAction;"dec"===n?Ge(t,$[t].quantity-1):"inc"===n?Ge(t,$[t].quantity+1):"remove"===n&&Oe(t)}})),H.addEventListener("click",$e),P.addEventListener("click",$e),S.addEventListener("click",$e),A.addEventListener("click",Ve);var D="",Z=null;document.addEventListener("keydown",(function(e){if("F1"===e.key)return e.preventDefault(),void o.focus();if("Escape"===e.key)return Ne(),void(T.classList.contains("open")&&$e());if("INPUT"!==document.activeElement.tagName&&"TEXTAREA"!==document.activeElement.tagName){if("Enter"===e.key&&D.length>=4){var a=D.trim();return D="",o.value=a,void je(a)}1===e.key.length&&(D+=e.key,clearTimeout(Z),Z=setTimeout((function(){D=""}),200))}})),document.querySelectorAll("[data-theme-switch]").forEach((function(e){e.addEventListener("click",(function(){var e=this.dataset.themeSwitch;document.documentElement.setAttribute("data-theme",e),localStorage.setItem("pos_theme",e),document.querySelectorAll("[data-theme-switch]").forEach((function(e){e.classList.remove("is-active"),e.setAttribute("aria-pressed","false")})),this.classList.add("is-active"),this.setAttribute("aria-pressed","true")}));var a=localStorage.getItem("pos_theme")||"industrial";e.dataset.themeSwitch===a?(e.classList.add("is-active"),e.setAttribute("aria-pressed","true")):(e.classList.remove("is-active"),e.setAttribute("aria-pressed","false"))}));var F=document.getElementById("vsYear"),Y=document.getElementById("vsBrand"),Q=document.getElementById("vsModel"),W=document.getElementById("vsEngine"),X=document.getElementById("vsClear"),K=document.getElementById("plateInputWrap"),ee=document.getElementById("plateInput"),ae=document.getElementById("plateStatus"),te=document.getElementById("plateToggle");ee&&ee.addEventListener("keydown",(function(e){"Enter"===e.key&&(e.preventDefault(),Fe())}));var ne=document.getElementById("vinInputWrap"),oe=document.getElementById("vinInput"),ie=document.getElementById("vinStatus"),re=document.getElementById("vinToggle");oe&&oe.addEventListener("keydown",(function(e){"Enter"===e.key&&(e.preventDefault(),Ye())})),window.CatalogApp={toggleCart:$e,goToCheckout:Ve,addToCart:qe,removeFromCart:Oe,updateQty:Ge,clearCart:function(){$=[],Ue(),Re()},loadPage:function(e){Me(e)},vsYearChanged:function(){var a=F.value;Y.innerHTML='',Q.innerHTML='',W.innerHTML='',Y.disabled=!0,Q.disabled=!0,W.disabled=!0,X.style.display=a?"":"none",a&&(Y.disabled=!1,de(e+"/brands?year_id="+a+"&mode="+q).then((function(e){var a=e.data||e;a&&(Y.innerHTML=''+a.map((function(e){return'"})).join(""))})))},vsBrandChanged:function(){var a=Y.value,t=F.value;Q.innerHTML='',W.innerHTML='',Q.disabled=!0,W.disabled=!0,a&&(Q.disabled=!1,de(e+"/models?brand_id="+a+(t?"&year_id="+t:"")).then((function(e){var a=e.data||e;a&&(Q.innerHTML=''+a.map((function(e){return'"})).join(""))})))},vsModelChanged:function(){var a=Q.value,t=F.value;W.innerHTML='',W.disabled=!0,a&&t&&(W.disabled=!1,de(e+"/engines?model_id="+a+"&year_id="+t).then((function(e){var a=e.data||e;a&&(W.innerHTML=''+a.map((function(e){var a=e.name_engine+(e.trim_level?" ("+e.trim_level+")":"");return'"})).join(""),1===a.length&&(W.value=a[0].id_mye,Je()))})))},vsEngineChanged:Je,vsClear:De,startBarcodeScan:function(){window.NexusNative?window.NexusNative.scanBarcode().then((function(e){e&&(o.value=e,je(e))})):alert("El modulo de escaneo no esta cargado.")},toggleVin:function(){var e="none"!==ne.style.display;ne.style.display=e?"none":"",re.textContent=e?"Tienes el VIN?":"Ocultar VIN",!e&&oe&&oe.focus()},decodeVin:Ye,togglePlate:function(){var e="none"!==K.style.display;K.style.display=e?"none":"",te.textContent=e?"Tienes las placas?":"Ocultar placas",!e&&ee&&ee.focus()},lookupPlate:Fe,setMode:function(a){if("oem"===a||"local"===a||"supplies"===a)if("oem"!==a){if(a!==q){if(q=a,localStorage.setItem("catalog_mode",a),se(),j.category=j.group=j.partType=null,j.nxGroup=j.nxSubgroup=j.nxPartType=null,O=1,"supplies"===a){try{De()}catch(e){}return j.brand=j.model=j.year=j.engine=null,j.level="categories",j.level="categories",le(),ge(),r.textContent="Shop Supplies (sin vehiculo)",_e(!0),ce(),void de(e+"/shop-supplies/groups").then((function(a){ue(),a&&a.data&&a.data.length?(p.className="nav-grid",p.innerHTML=a.data.map((function(e){return'"})).join(""),p.querySelectorAll(".nav-card").forEach((function(a){a.addEventListener("click",(function(){j.nxGroup={slug:this.dataset.slug,name:this.dataset.name},j.nxSubgroup=null,j.nxPartType=null,j.level="groups",le(),ge(),r.textContent=j.nxGroup.name,_e(!0),ce(),de(e+"/shop-supplies/subgroups?group_slug="+encodeURIComponent(j.nxGroup.slug)).then((function(a){ue(),a&&a.data&&a.data.length?(p.className="nav-grid",p.innerHTML=a.data.map((function(e){return'"})).join(""),p.querySelectorAll(".nav-card").forEach((function(a){a.addEventListener("click",(function(){j.nxSubgroup={slug:this.dataset.slug,name:this.dataset.name},j.nxPartType=null,function(){j.level="part_types",j.nxPartType=null,le(),ge(),r.textContent=j.nxSubgroup.name,_e(!0),ce();var a=e+"/shop-supplies/part-types?group_slug="+encodeURIComponent(j.nxGroup.slug)+"&subgroup_slug="+encodeURIComponent(j.nxSubgroup.slug);de(a).then((function(e){if(ue(),e&&e.data&&e.data.length){if(1===e.data.length){var a=e.data[0];return j.nxPartType={slug:a.slug,name:a.name},void Ce(1)}p.className="nav-grid",p.innerHTML=e.data.map((function(e){var a=e.sample_image?'':"";return'"})).join(""),p.querySelectorAll(".nav-card").forEach((function(e){e.addEventListener("click",(function(){j.nxPartType={slug:this.dataset.slug,name:this.dataset.name},Ce(1)}))}))}else pe("Sin tipos","No hay tipos de parte en este subgrupo.")}))}()}))}))):pe("Sin subgrupos","No hay subgrupos con partes disponibles.")}))}))}))):pe("Sin supplies","No hay grupos de Shop Supplies disponibles.")}))}if(!(!j.engine||!j.engine.id_mye))return j.level="categories",void Te();try{De()}catch(e){}j.level="brands",j.brand=j.model=j.year=j.engine=null,he()}}else alert("Catálogo OEM próximamente. Por favor usa el modo Local o Shop Supplies.")}},Re(),se(),function(){var a="nexus:years-all",t=sessionStorage.getItem(a);if(t){var n=JSON.parse(t),o=n.data||n||[];if(!o.length){o=[];for(var i=2026;i>=1990;i--)o.push({id_year:i,year_car:i})}F.innerHTML=''+o.map((function(e){return'"})).join("")}else de(e+"/years-all").then((function(e){if(e){var t=e.data||e;if(!t||!t.length){t=[];for(var n=2026;n>=1990;n--)t.push({id_year:n,year_car:n})}sessionStorage.setItem(a,JSON.stringify(e)),F.innerHTML=''+t.map((function(e){return'"})).join("")}})).catch((function(){for(var e=[],a=2026;a>=1990;a--)e.push(a);F.innerHTML=''+e.map((function(e){return'"})).join("")}))}(),he()}else window.location.href="/pos/login";function se(){document.querySelectorAll("#modeToggle button").forEach((function(e){e.getAttribute("data-mode")===q?e.classList.add("is-active"):e.classList.remove("is-active")}))}function le(){if(!R){var e=JSON.parse(JSON.stringify(j));e.page=O,history.pushState(e,"","/pos/catalog")}}function de(e){V&&(V.abort(),V=null);var a={headers:t};return(0===e.indexOf("/pos/api/")&&-1!==e.indexOf("mode=")||-1!==e.indexOf("/years")||-1!==e.indexOf("/brands")||-1!==e.indexOf("/models")||-1!==e.indexOf("/engines")||-1!==e.indexOf("/categories")||-1!==e.indexOf("/groups")||-1!==e.indexOf("/part-types")||-1!==e.indexOf("/parts")||-1!==e.indexOf("/search"))&&(V=new AbortController,a.signal=V.signal),fetch(e,a).then((function(e){return 401===e.status?(localStorage.removeItem("pos_token"),window.location.href="/pos/login",null):e.json()})).catch((function(e){return"AbortError"===e.name||console.error("API error:",e),null}))}function ce(){l.classList.add("is-visible"),p.innerHTML="",m.style.display="none",m.innerHTML="",d.classList.remove("is-visible"),v.innerHTML="";var e=document.getElementById("diagLink");e&&"categories"!==j.level&&(e.style.display="none")}function ue(){l.classList.remove("is-visible")}function pe(e,a){c.textContent=e,u.textContent=a||"",d.classList.add("is-visible"),p.innerHTML="",m.style.display="none"}function me(e){return(parseFloat(e)||0).toFixed(2)}function ve(e){if(!e)return"";var a=document.createElement("div");return a.textContent=e,a.innerHTML}function ge(){var e=[];e.push({label:"Catalogo",action:"loadBrands"}),j.brand&&e.push({label:j.brand.name,action:"loadModels"}),j.model&&e.push({label:j.model.name,action:"loadYears"}),j.year&&e.push({label:String(j.year.year),action:"loadEngines"}),j.engine&&e.push({label:j.engine.name,action:"loadCategories"}),j.nxGroup?e.push({label:j.nxGroup.name,action:"loadNxSubgroups"}):j.category&&e.push({label:j.category.name,action:"loadGroups"}),j.nxSubgroup?e.push({label:j.nxSubgroup.name,action:"loadNxPartTypes"}):j.group&&e.push({label:j.group.name,action:"loadPartTypes"}),j.nxPartType?e.push({label:j.nxPartType.name,action:null}):j.partType&&e.push({label:j.partType.name,action:null});for(var a="",t=0;t0&&(a+=''),t'+ve(e[t].label)+"":a+=''+ve(e[t].label)+"";n.innerHTML=a,n.querySelectorAll("[data-bc-action]").forEach((function(e){e.addEventListener("click",(function(){var e=this.dataset.bcAction;"loadBrands"===e?(ye(),he()):"loadModels"===e?(fe("models"),be()):"loadYears"===e?(fe("years"),xe()):"loadEngines"===e?(fe("engines"),Ee()):"loadCategories"===e?(fe("categories"),Te()):"loadGroups"===e?(fe("groups"),ke()):"loadPartTypes"===e?(fe("part_types"),Ie()):"loadNxSubgroups"===e?(fe("groups"),Se()):"loadNxPartTypes"===e&&(fe("part_types"),Le())}))}))}function ye(){j.level="brands",le(),j.brand=j.model=j.year=j.engine=j.category=j.group=j.partType=null,j.nxGroup=j.nxSubgroup=j.nxPartType=null}function fe(e){var a=["brands","models","years","engines","categories","groups","part_types","parts"].indexOf(e);if(a<=0)ye();else{j.level=e;for(var t=[null,["model"],["year"],["engine"],["category","nxGroup"],["group","nxSubgroup"],["partType","nxPartType"],null],n=a;n=0?"":"none"}))}}function he(){j.level="brands",le(),ge(),r.textContent="Selecciona una marca",_e(!0),ce();var a="nexus:brands:"+q,t=sessionStorage.getItem(a);if(t)return ue(),void function(e){if(!e||!e.data||!e.data.length)return e?void pe("Sin marcas","El catalogo no tiene marcas con partes disponibles."):void ze();p.className="nav-grid",p.innerHTML=e.data.map((function(e){return'"})).join(""),p.querySelectorAll(".nav-card").forEach((function(e){e.addEventListener("click",(function(){j.brand={id:parseInt(this.dataset.brandId),name:this.dataset.name},be()}))}))}(JSON.parse(t));de(e+"/brands?mode="+q).then((function(e){if(ue(),e&&e.data&&sessionStorage.setItem(a,JSON.stringify(e)),!e||!e.data||!e.data.length)return e?void pe("Sin marcas","El catalogo no tiene marcas con partes disponibles."):void ze();p.className="nav-grid",p.innerHTML=e.data.map((function(e){return'"})).join(""),p.querySelectorAll(".nav-card").forEach((function(e){e.addEventListener("click",(function(){j.brand={id:parseInt(this.dataset.brandId),name:this.dataset.name},be()}))}))}))}function be(){j.level="models",le(),ge(),r.textContent="Modelos de "+j.brand.name,_e(!0),ce(),de(e+"/models?brand_id="+j.brand.id).then((function(e){ue(),e&&e.data&&e.data.length?(p.className="nav-grid",p.innerHTML=e.data.map((function(e){return'"})).join(""),p.querySelectorAll(".nav-card").forEach((function(e){e.addEventListener("click",(function(){j.model={id:parseInt(this.dataset.modelId),name:this.dataset.name},xe()}))}))):pe("Sin modelos","No hay modelos con partes para "+j.brand.name)}))}function xe(){j.level="years",le(),ge(),r.textContent=j.brand.name+" "+j.model.name+" — Anios",_e(!1),ce(),de(e+"/years?model_id="+j.model.id).then((function(e){ue(),e&&e.data&&e.data.length?(p.className="nav-grid nav-grid--years",p.innerHTML=e.data.map((function(e){return'"})).join(""),p.querySelectorAll(".nav-card").forEach((function(e){e.addEventListener("click",(function(){j.year={id:parseInt(this.dataset.yearId),year:parseInt(this.dataset.year)},Ee()}))}))):pe("Sin anios","No hay anios con partes para este modelo.")}))}function Ee(){j.level="engines",le(),ge(),r.textContent=j.brand.name+" "+j.model.name+" "+j.year.year+" — Motor",_e(!1),ce(),de(e+"/engines?model_id="+j.model.id+"&year_id="+j.year.id).then((function(e){if(ue(),e&&e.data&&e.data.length){if(1===e.data.length){var a=e.data[0];return j.engine={id_mye:a.id_mye,name:a.name_engine+(a.trim_level?" "+a.trim_level:"")},void Te()}p.className="nav-grid",p.innerHTML=e.data.map((function(e){var a=e.name_engine+(e.trim_level?" — "+e.trim_level:"");return'"})).join(""),p.querySelectorAll(".nav-card").forEach((function(e){e.addEventListener("click",(function(){j.engine={id_mye:parseInt(this.dataset.myeId),name:this.dataset.name},Te()}))}))}else pe("Sin motores","No hay configuraciones de motor para esta combinacion.")}))}function ke(){j.level="groups",le(),ge(),r.textContent=j.category.name,_e(!0),ce(),de(e+"/groups?mye_id="+j.engine.id_mye+"&category_id="+j.category.id).then((function(e){ue(),e&&e.data&&e.data.length?(p.className="nav-grid",p.innerHTML=e.data.map((function(e){return'"})).join(""),p.querySelectorAll(".nav-card").forEach((function(e){e.addEventListener("click",(function(){j.group={id:parseInt(this.dataset.groupId),name:this.dataset.name},j.partType=null,Ie()}))}))):pe("Sin subcategorias","No hay subcategorias para "+j.category.name)}))}function Ie(){j.level="part_types",j.partType=null,le(),ge(),r.textContent=j.group.name,_e(!0),ce(),de(e+"/part-types?mye_id="+j.engine.id_mye+"&group_id="+j.group.id).then((function(e){if(ue(),e&&e.data&&e.data.length){if(1===e.data.length){var a=e.data[0];return j.partType={slug:a.slug,name:a.name},void Me(1)}p.className="nav-grid",p.innerHTML=e.data.map((function(e){var a=e.sample_image?'':"";return'"})).join(""),p.querySelectorAll(".nav-card").forEach((function(e){e.addEventListener("click",(function(){j.partType={slug:this.dataset.ptSlug,name:this.dataset.ptName},Me(1)}))}))}else Me(1)}))}function Te(){"local"===q?(j.level="categories",le(),ge(),r.textContent="Categorias (Local)",_e(!0),ce(),de(e+"/categories?mode=local&mye_id="+j.engine.id_mye).then((function(e){ue(),e&&e.data&&e.data.length?(p.className="nav-grid",p.innerHTML=e.data.map((function(e){return'"})).join(""),p.querySelectorAll(".nav-card").forEach((function(e){e.addEventListener("click",(function(){j.nxGroup={slug:this.dataset.slug,name:this.dataset.name},j.nxSubgroup=null,j.nxPartType=null,Se()}))}))):pe("Sin categorias Local","Ninguna parte de este vehiculo mapea al catalogo Local.")}))):(j.level="categories",le(),ge(),r.textContent="Categorias de partes",_e(!0),ce(),de(e+"/categories?mye_id="+j.engine.id_mye).then((function(e){ue(),e&&e.data&&e.data.length?(p.className="nav-grid",p.innerHTML=e.data.map((function(e){return'"})).join(""),p.querySelectorAll(".nav-card").forEach((function(e){e.addEventListener("click",(function(){j.category={id:parseInt(this.dataset.catId),name:this.dataset.name},ke()}))}))):pe("Sin categorias","No hay partes catalogadas para este vehiculo.")})))}function Se(){j.level="groups",le(),ge(),r.textContent=j.nxGroup.name,_e(!0),ce(),de(e+"/groups?mode=local&mye_id="+j.engine.id_mye+"&category_slug="+encodeURIComponent(j.nxGroup.slug)).then((function(e){ue(),e&&e.data&&e.data.length?(p.className="nav-grid",p.innerHTML=e.data.map((function(e){return'"})).join(""),p.querySelectorAll(".nav-card").forEach((function(e){e.addEventListener("click",(function(){j.nxSubgroup={slug:this.dataset.slug,name:this.dataset.name},j.nxPartType=null,Le()}))}))):pe("Sin subcategorias","No hay subcategorias en "+j.nxGroup.name)}))}function Le(){j.level="part_types",j.nxPartType=null,le(),ge(),r.textContent=j.nxSubgroup.name,_e(!0),ce(),de(e+"/part-types?mode=local&mye_id="+j.engine.id_mye+"&group_slug="+encodeURIComponent(j.nxGroup.slug)+"&subgroup_slug="+encodeURIComponent(j.nxSubgroup.slug)).then((function(e){if(ue(),e&&e.data&&e.data.length){if(1===e.data.length){var a=e.data[0];return j.nxPartType={slug:a.slug,name:a.name},void Me(1)}p.className="nav-grid",p.innerHTML=e.data.map((function(e){var a=e.sample_image?'':"";return'"})).join(""),p.querySelectorAll(".nav-card").forEach((function(e){e.addEventListener("click",(function(){j.nxPartType={slug:this.dataset.slug,name:this.dataset.name},Me(1)}))}))}else pe("Sin tipos de parte","No hay tipos de parte en "+j.nxSubgroup.name)}))}function Ce(a){j.level="parts",le(),O=a||1,ge(),r.textContent=j.nxPartType.name,_e(!1),ce(),p.innerHTML="",de(e+"/shop-supplies/parts?group_slug="+encodeURIComponent(j.nxGroup.slug)+"&subgroup_slug="+encodeURIComponent(j.nxSubgroup.slug)+"&part_type_slug="+encodeURIComponent(j.nxPartType.slug)+"&page="+O+"&per_page=30").then((function(e){ue(),e&&e.data&&e.data.length?(m.style.display="",m.innerHTML=e.data.map((function(e){var a;a=e.in_stock_network||e.bodega_count>0?''+e.bodega_count+" bodega"+(e.bodega_count>1?"s":"")+"":'Sin stock';var t=e.image_url?''+ve(e.name)+'':'',n=1===e.priority_tier?" part-card--tier1":2===e.priority_tier?" part-card--tier2":"",o="";if(e.manufacturer){var i=1===e.priority_tier?'':"";o='
'+ve(e.manufacturer)+""+i+"
"}var r=e.part_number?ve(e.part_number)+' · OEM: '+ve(e.oem_part_number||"")+"":ve(e.oem_part_number||"");return'
'+t+'
'+o+'
'+r+'
'+ve(e.name)+'
"})).join(""),m.querySelectorAll(".part-card").forEach((function(e){e.addEventListener("click",(function(){var e=this.dataset.partId;"string"==typeof e&&0===e.indexOf("inv:")||we(parseInt(e))}))})),e.pagination&&Be(e.pagination)):pe("Sin partes","No hay partes en este tipo.")}))}function Me(a){var t;if(j.level="parts",le(),O=a||1,ge(),j.nxPartType?r.textContent=j.nxPartType.name:j.partType?r.textContent=j.partType.name:j.group?r.textContent=j.group.name:r.textContent="Partes",_e(!1),ce(),p.innerHTML="",j.nxGroup&&j.nxSubgroup&&j.nxPartType)t=e+"/parts?mode=local&mye_id="+j.engine.id_mye+"&page="+O+"&per_page=30&nexpart_group="+encodeURIComponent(j.nxGroup.slug)+"&nexpart_subgroup="+encodeURIComponent(j.nxSubgroup.slug)+"&nexpart_part_type="+encodeURIComponent(j.nxPartType.slug);else{var n=j.partType?"&part_type="+encodeURIComponent(j.partType.slug):"";t=e+"/parts?mye_id="+j.engine.id_mye+"&group_id="+j.group.id+"&page="+O+"&per_page=30&mode="+q+n}de(t).then((function(e){if(ue(),e&&e.data&&e.data.length){var a="local"===q;m.style.display="",m.innerHTML=e.data.map((function(e){var t;t=e.local_stock>0?'En stock: '+e.local_stock+"":e.in_stock_network||e.bodega_count>0?''+e.bodega_count+" bodega"+(e.bodega_count>1?"s":"")+"":'Sin stock';var n="local_inventory"===e.source?'Stock Local':"",o=e.image_url?''+ve(e.name)+'':'',i="",r="";if(a&&e.manufacturer){var s="";1===e.priority_tier?(r=" part-card--tier1",s="★"):2===e.priority_tier&&(r=" part-card--tier2",s=""),i='
'+ve(e.manufacturer)+""+(s?''+s+"":"")+"
"}var l=a&&e.part_number?ve(e.part_number)+' · OEM: '+ve(e.oem_part_number)+"":ve(e.oem_part_number);return'
'+o+'
'+i+n+'
'+l+'
'+ve(e.name)+'
"})).join(""),m.querySelectorAll(".part-card").forEach((function(e){e.addEventListener("click",(function(){var e=this.dataset.partId;"string"==typeof e&&0===e.indexOf("inv:")||we(parseInt(e))}))})),e.pagination&&Be(e.pagination)}else pe("Sin partes","No hay partes en este grupo.")}))}function Be(e){if(!e||e.total_pages<=1)v.innerHTML="";else{var a="";e.page<=1?a+='':a+='',function(e,a){if(a<=7){for(var t=[],n=1;n<=a;n++)t.push(n);return t}var o=[1];e>3&&o.push("...");for(var i=Math.max(2,e-1);i<=Math.min(a-1,e+1);i++)o.push(i);e...':t===e.page?a+='":a+='"})),e.page>=e.total_pages?a+='':a+='',v.innerHTML=a,v.querySelectorAll("[data-page]").forEach((function(e){e.addEventListener("click",(function(){g.scrollTo({top:0,behavior:"smooth"}),Me(parseInt(this.dataset.page))}))}))}}function we(a){_.innerHTML='
',h.style.display="none",y.classList.add("is-open"),f.classList.add("is-visible"),U=1,k.textContent="1",de(e+"/part/"+a).then((function(e){if(e&&!e.error){G=e;var a=e.part,t=e.local,n=e.bodegas||[],o=e.alternatives||[],i="";i+='
',a.category_name&&(i+='
'+ve(a.category_name)+" > "+ve(a.group_name)+"
"),i+='
'+ve(a.oem_part_number)+"
",i+='
'+ve(a.name)+"
",a.description&&(i+='
'+ve(a.description)+"
"),a.image_url&&(i+='
'),i+="
",i+='
',i+='
Mi stock
',t&&t.stock>0?(i+='
Cantidad'+t.stock+" "+(t.unit||"PZA")+"
",i+='
Precio publico$'+me(t.price_1)+"
",t.price_2&&(i+='
Precio mayoreo$'+me(t.price_2)+"
"),t.price_3&&(i+='
Precio taller$'+me(t.price_3)+"
"),t.location&&(i+='
Ubicacion'+ve(t.location)+"
")):i+='
No tienes esta parte en inventario.
',i+="
",n.length&&(i+='
',i+='
Disponible en bodegas
',i+='',n.forEach((function(e){i+=""})),i+="
BodegaPrecioStock
"+ve(e.business_name)+""+(e.price?"$"+me(e.price):"--")+""+e.stock+"
"),o.length&&(i+='
',i+='
Alternativas / Cross-references
',o.forEach((function(e){var a=e.local_stock>0?'Stock: '+e.local_stock+"":e.bodega_count>0?''+e.bodega_count+" bod.":"";i+='
'+ve(e.part_number)+'
'+ve(e.manufacturer)+(e.name?" — "+ve(e.name):"")+'
'+a+"
"})),i+="
"),_.innerHTML=i,t&&t.stock>0?h.style.display="":h.style.display="none"}else _.innerHTML='

Error al cargar detalle.

'}))}function Ne(){y.classList.remove("is-open"),f.classList.remove("is-visible"),G=null}function Ae(e){if(!e)return"keyword";var a=e.trim(),t=a.replace(/[\s\-]/g,"").toUpperCase();if(/^[A-HJ-NPR-Z0-9]{17}$/.test(t))return"vin";if(/^[A-Z]{3}[-\s]?\d{3,4}$/.test(a.toUpperCase()))return"plate";if(/[a-z]/.test(a))return"keyword";var n=a.split(/\s+/);if(n.some((function(e){return/^(19|20)\d{2}$/.test(e)}))&&n.length>1)return"keyword";var o=a.toUpperCase();return/^[A-Z0-9]{2,}[\-\/][A-Z0-9]{2,}([\-\/][A-Z0-9]+)*$/.test(o)&&t.length>=6||n.length>=2&&n.every((function(e){return/^[A-Z0-9]{1,}$/.test(e)}))&&t.length>=6||/^[A-Z0-9]{8,}$/.test(t)&&/[A-Z]/.test(t)&&/\d/.test(t)?"part_number":"keyword"}function He(e){var a=J||((J=document.createElement("div")).id="searchHint",J.style.cssText="position:absolute;top:100%;left:0;margin-top:4px;padding:3px 10px;background:var(--color-primary-muted);color:var(--color-text-accent);font-size:var(--text-caption);font-weight:var(--font-weight-semibold);border:1px dashed var(--color-border-accent);border-radius:var(--radius-sm);white-space:nowrap;pointer-events:none;z-index:10;display:none;",o.parentElement.appendChild(J),J),t={vin:"🚗 VIN detectado — decodificando",plate:"🔖 Placa detectada — consultando registro",part_number:"🔩 Numero de parte detectado",keyword:null}[e];t?(a.textContent=t,a.style.display=""):a.style.display="none"}function Pe(e){var a=Ae(e);if("vin"!==a)if("plate"!==a)je(e);else try{!function(e){var a=document.getElementById("plateInput");a?(a.value=e.toUpperCase(),Fe()):je(e)}(e)}catch(a){je(e)}else try{!function(e){var a=document.getElementById("vinInput");a?(a.value=e,Ye()):je(e)}(e)}catch(a){je(e)}}function je(a){de(e+"/search?q="+encodeURIComponent(a)+"&limit=20").then((function(e){if(!e||!e.data||!e.data.length)return i.innerHTML='
Sin resultados para "'+ve(a)+'"
',void i.classList.add("is-visible");i.innerHTML=e.data.map((function(e){var a=e.local_stock>0?'Stock: '+e.local_stock+"":"";return'
'+ve(e.oem_part_number)+'
'+ve(e.name)+"
"+(e.vehicle_info?'
'+ve(e.vehicle_info)+"
":"")+"
"+a+"
"})).join(""),i.classList.add("is-visible"),i.querySelectorAll(".search-result-item").forEach((function(e){e.addEventListener("click",(function(){i.classList.remove("is-visible");var e=this.dataset.partId;"string"==typeof e&&0===e.indexOf("inv:")||we(parseInt(e))}))}))}))}function qe(e,a){a=a||1;var t=$.find((function(a){return a.id===e.id}));t?t.quantity+=a:$.push({id:e.id,part_number:e.part_number,name:e.name,brand:e.brand||"",price:e.price,tax_rate:e.tax_rate||.16,unit:e.unit||"PZA",stock:e.stock,source:e.source||"local",inventory_id:e.inventory_id,quantity:a}),Ue(),Re(),T.classList.contains("open")||$e()}function Oe(e){$.splice(e,1),Ue(),Re()}function Ge(e,a){(a=parseInt(a))<=0?Oe(e):($[e].quantity=a,Ue(),Re())}function Ue(){localStorage.setItem("pos_cart",JSON.stringify($))}function Re(){var e=$.reduce((function(e,a){return e+a.quantity}),0);if(N&&(N.textContent=e,N.style.display=e>0?"flex":"none"),!$.length)return L.innerHTML="",C.style.display="block",A&&(A.disabled=!0),M.textContent="$0.00",B.textContent="$0.00",void(w.textContent="$0.00");C.style.display="none",A&&(A.disabled=!1);var a=0,t=0;L.innerHTML=$.map((function(e,n){var o=e.price*e.quantity,i=o*e.tax_rate;return a+=o,t+=i,'
'+ve(e.name)+'
'+ve(e.part_number)+'
'+e.quantity+'
$'+me(o)+'
'})).join(""),M.textContent="$"+me(a),B.textContent="$"+me(t),w.textContent="$"+me(a+t)}function $e(){var e=T.classList.toggle("open");S.classList.toggle("open",e)}function Ve(){$.length&&(localStorage.setItem("pos_cart",JSON.stringify($)),window.location.href="/pos/sale")}function ze(){document.getElementById("offlineBanner").style.display="",document.getElementById("offlineBannerText").innerHTML="Modo offline — Mostrando solo tu inventario local.",r.textContent="Inventario local",_e(!1),pe("Sin conexion al catalogo","Verifica tu conexion. El catalogo TecDoc requiere acceso al servidor central.")}function Je(){var e=W.value;if(e){var a=F.options[F.selectedIndex].text,t=Y.options[Y.selectedIndex].text,n=Q.options[Q.selectedIndex].text,o=W.options[W.selectedIndex].text;j.brand={id:parseInt(Y.value),name:t},j.model={id:parseInt(Q.value),name:n},j.year={id:parseInt(F.value),year:a},j.engine={id_mye:parseInt(e),name:o},j.level="categories",le(),Te(),setTimeout((function(){var e=document.getElementById("pageBody");e&&e.scrollIntoView({behavior:"smooth",block:"start"})}),300)}}function De(){F.value="",Y.innerHTML='',Q.innerHTML='',W.innerHTML='',Y.disabled=!0,Q.disabled=!0,W.disabled=!0,X.style.display="none",j.level="brands",j.brand=null,j.model=null,j.year=null,j.engine=null,j.category=null,j.group=null,j.partType=null,j.nxGroup=null,j.nxSubgroup=null,j.nxPartType=null,O=1,le(),he()}function Ze(e,a){ae.style.display=e?"":"none",ae.textContent=e,ae.style.color=a?"var(--color-error)":"var(--color-text-muted)"}function Fe(){var a=(ee.value||"").trim().toUpperCase();!a||a.length<5?Ze("Ingresa una placa valida (Ej: ABC-1234).",!0):(Ze("Buscando placa...",!1),de(e+"/plate/"+encodeURIComponent(a)).then((function(e){if(e)if(e.error)Ze(e.error,!0);else{if(!e.found)return ae.style.display="",ae.innerHTML='Placa no registrada. Registrar vehiculo',void(ae.style.color="var(--color-warning, #e6a700)");var a=[];e.year&&a.push(e.year),e.make&&a.push(e.make),e.model&&a.push(e.model);var t=a.join(" ")||"Vehiculo encontrado",n=e.catalog_match;n&&n.brand_id?(Ze(t+" — Cargando catalogo...",!1),Qe(n,e)):Ze(t+" — No encontrado en el catalogo TecDoc.",!1)}else Ze("Error de conexion al buscar placa.",!0)})))}function Ye(){var a=(oe.value||"").trim().toUpperCase();17===a.length?(We("Decodificando VIN...",!1),de(e+"/vin/"+encodeURIComponent(a)).then((function(e){if(e)if(!e.error||e.make){var a=[];e.year&&a.push(e.year),e.make&&a.push(e.make),e.model&&a.push(e.model),e.engine&&a.push(e.engine);var t=a.join(" ")||"Vehiculo no reconocido",n=e.catalog_match;n&&n.brand_id?(We(t+" — Encontrado en catalogo, cargando...",!1),Qe(n,e)):We(t+" — No encontrado en el catalogo TecDoc.",!1)}else We(e.error,!0);else We("Error de conexion al decodificar VIN.",!0)}))):We("El VIN debe tener exactamente 17 caracteres.",!0)}function Qe(a,t){a.year_id&&(F.value=String(a.year_id),de(e+"/brands?year_id="+a.year_id).then((function(t){var n=t&&(t.data||t);n&&(Y.innerHTML=''+n.map((function(e){return'"})).join(""),Y.disabled=!1,X.style.display="",a.brand_id&&(Y.value=String(a.brand_id),de(e+"/models?brand_id="+a.brand_id+"&year_id="+a.year_id).then((function(t){var n=t&&(t.data||t);n&&(Q.innerHTML=''+n.map((function(e){return'"})).join(""),Q.disabled=!1,a.model_id&&(Q.value=String(a.model_id),de(e+"/engines?model_id="+a.model_id+"&year_id="+a.year_id).then((function(e){var t=e&&(e.data||e);t&&(W.innerHTML=''+t.map((function(e){var a=e.name_engine+(e.trim_level?" ("+e.trim_level+")":"");return'"})).join(""),W.disabled=!1,a.id_mye?(W.value=String(a.id_mye),Je(),We("Vehiculo cargado desde VIN.",!1)):1===t.length?(W.value=t[0].id_mye,Je(),We("Vehiculo cargado desde VIN.",!1)):We("Selecciona el motor para continuar.",!1))}))))}))))})))}function We(e,a){ie.style.display=e?"":"none",ie.textContent=e,ie.style.color=a?"var(--color-error)":"var(--color-text-muted)"}}();