import{a as y}from"./chunk-T5OYARRX.js";import{C as B,b as C,c,g as l}from"./chunk-YXUFZINL.js";import{a as E}from"./chunk-KYV554O4.js";import{a as b,b as A}from"./chunk-IGFM5CCE.js";import{Ac as v,Bc as S,C as d,Db as m,Hb as f,Ia as h,M as p,ma as s,zc as g}from"./chunk-I3FGJX2C.js";import{d as u,n as V}from"./chunk-INB5GR2I.js";V();var N=["productAutocomplete"],a,D=(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===l.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===l.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({filter: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);D=u([b()],D);export{D as a};
//# sourceMappingURL=chunk-RODSGBZJ.js.map
