import{a as A}from"./chunk-DWTLCHRD.js";import{D as C,b,c,g as l}from"./chunk-JV3IW4ED.js";import{a as v,b as S}from"./chunk-EK6YV2TW.js";import{Bb as p,C as d,K as h,ka as s,xc as m,yc as f,zc as g}from"./chunk-DYUFV4HF.js";import{d as u,n as V}from"./chunk-INB5GR2I.js";V();var B=["productAutocomplete"],a,E=(a=class{constructor(){this.nomenclatureService=s(C),this.cabinetUserService=s(A),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),h(),S(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(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({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=function(o){return new(o||a)},a.\u0275cmp=p({type:a,selectors:[["tis-operation-base"]],viewQuery:function(o,r){if(o&1&&m(B,5),o&2){let i;f(i=g())&&(r.productAutocomplete=i.first)}},decls:0,vars:0,template:function(o,r){},encapsulation:2}),a);E=u([v()],E);export{E as a};
//# sourceMappingURL=chunk-TXUAP47P.js.map
