import{a as C}from"./chunk-O2T5X7XL.js";import{D as E,b,c,h as u}from"./chunk-7YTVARFL.js";import{a as A}from"./chunk-JDEOJ6RY.js";import{z as S}from"./chunk-GQAU5ACB.js";import{Ac as g,Bc as v,Ib as p,K as l,Mb as m,Qa as h,U as d,qa as s,zc as f}from"./chunk-ISMRT7VU.js";var B=["productAutocomplete"],H=(()=>{class a extends A{constructor(){super(...arguments),this.nomenclatureService=s(E),this.cabinetUserService=s(C),this.enableAutocompleteEnterEvent=!0}ngOnInit(){this.products=this.nomenclatureService.initDataSourceAutocomplete(),this.initNomenclatureState(),this.cabinetUserService.isOpenSidebar$$.next(!1)}openCreateProductDialog(e){let o=this.productAutocomplete?.searchValue()&&!this.productAutocomplete?.options.length&&c(this.productAutocomplete?.searchValue());this.productAutocomplete?.close(),this.nomenclatureService.fastCreateProduct(o||e||null).subscribe(r=>{this.products.load().then(i=>{this.addProduct(i.data.find(t=>t.id===r.id))})})}initNomenclatureState(){this.nomenclatureService.nomenlactureState$.pipe(l(e=>!!e.searchValue),d(),S(this.destroyRef)).subscribe(e=>{let o=e.data,r=e.loading,i=e.searchValue;if(o.length===1&&o[0]?.isArchive&&r===u.Loaded&&i?.length){let t=c(i);t&&this.nomenclatureService.previousSearchValue()!==t&&(this.openCreateProductDialog(t),this.nomenclatureService.previousSearchValue.set(t))}if(o.length===0&&r===u.Loaded&&i?.length){let t=c(i);t&&this.nomenclatureService.previousSearchValue()!==t&&(this.openCreateProductDialog(t),this.nomenclatureService.previousSearchValue.set(t))}})}parseWeightBarcode(e){let o=e.target.value.startsWith("27")&&e.target.value.length===13;if(b(e.target.value,o)&&o){this.enableAutocompleteEnterEvent=!1;let r=e.target.value.slice(0,7),i=this.nomenclatureService.toWeightFormatFromBarcode(e.target.value.slice(7,12));this.products.load({searchValue:r}).then(t=>{t.data.length===1&&(this.addProduct(t.data[0],i),this.productAutocomplete.close(!1)),t.data.length>1&&t.data.forEach(n=>{(n.barcode===r||n.additionalBarcodes.includes(r))&&(this.addProduct(n,i),this.productAutocomplete.close(!1))}),this.enableAutocompleteEnterEvent=!0})}}static{this.\u0275fac=(()=>{let e;return function(r){return(e||(e=h(a)))(r||a)}})()}static{this.\u0275cmp=p({type:a,selectors:[["tis-operation-base"]],viewQuery:function(o,r){if(o&1&&f(B,5),o&2){let i;g(i=v())&&(r.productAutocomplete=i.first)}},features:[m],decls:0,vars:0,template:function(o,r){},encapsulation:2})}}return a})();export{H as a};
//# sourceMappingURL=chunk-42PXGZFV.js.map
