import{a as y}from"./chunk-HV3LHWOZ.js";import{D as B,b as C,c,h as u}from"./chunk-4MCMX46R.js";import{a as E}from"./chunk-KJOFF642.js";import{a as b,b as A}from"./chunk-KXDO3JYP.js";import{C as d,Cb as m,Gb as f,Ia as h,M as p,la as s,tc as g,uc as v,vc as S}from"./chunk-PVUKHE45.js";import{d as l,n as D}from"./chunk-VD6R3735.js";D();var N=["productAutocomplete"],a,V=(a=class extends E{constructor(){super(...arguments),this.nomenclatureService=s(B),this.cabinetUserService=s(y),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(d(e=>!!e.searchValue),p(),A(this)).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(C(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})}}},a.\u0275fac=(()=>{let e;return function(r){return(e||(e=h(a)))(r||a)}})(),a.\u0275cmp=m({type:a,selectors:[["tis-operation-base"]],viewQuery:function(o,r){if(o&1&&g(N,5),o&2){let i;v(i=S())&&(r.productAutocomplete=i.first)}},features:[f],decls:0,vars:0,template:function(o,r){},encapsulation:2}),a);V=l([b()],V);export{V as a};
//# sourceMappingURL=chunk-CT2UFO4Y.js.map
