import{a as he,b as pe,c as de,d as _e}from"./chunk-HP6ZWKMP.js";import{a as v}from"./chunk-V6D2LXXI.js";import{a as ce}from"./chunk-YJGIDTCI.js";import{a as V}from"./chunk-DV3DSI3N.js";import{a as P}from"./chunk-YGRCRXXK.js";import{a as G}from"./chunk-ZWHIYZH7.js";import"./chunk-EGRHWZRV.js";import{a as j}from"./chunk-OAUPJA66.js";import{a as le}from"./chunk-WH5RBXYQ.js";import{b as me}from"./chunk-YQRXO7LU.js";import"./chunk-HBSPKYMF.js";import"./chunk-GF5II5JA.js";import"./chunk-D77MCZOO.js";import"./chunk-4WBIDQ26.js";import"./chunk-ZVQ5RRLK.js";import"./chunk-R7MAHTDS.js";import{e as O}from"./chunk-2MNVXWEX.js";import{Ea as re,Ha as B,_a as se,ta as L}from"./chunk-YFBLRBP4.js";import{a as F,b as x}from"./chunk-VXSBHXCN.js";import"./chunk-VCKZUP7X.js";import{c as H}from"./chunk-XUSKVTJP.js";import"./chunk-JOFGKPLY.js";import"./chunk-B6U47PXC.js";import"./chunk-CC7H2Q52.js";import"./chunk-ZAOXB7JK.js";import"./chunk-RESH3J2M.js";import"./chunk-X6G2MEQP.js";import"./chunk-NUCOBKMO.js";import"./chunk-B3CI2H5S.js";import"./chunk-LEOOAH45.js";import"./chunk-IFY4UZPR.js";import"./chunk-Y4KZVCMP.js";import"./chunk-BYOG7O4N.js";import"./chunk-DVHWBY5K.js";import{a as ue}from"./chunk-4QCIIFWS.js";import{n as ae}from"./chunk-DC6G5OHZ.js";import"./chunk-JUPKAJPM.js";import"./chunk-PDYJ5OYY.js";import{s as oe,u as R,v as ne}from"./chunk-Z2AWIQRI.js";import{Y as ie,ua as M}from"./chunk-3OWC7J4L.js";import{$c as te,Bb as U,Bc as Y,Cc as K,Cd as A,Dc as X,Ea as N,Gb as d,Gc as C,L as q,Lc as w,Mc as Z,Nc as ee,fc as r,gc as a,hc as s,ic as y,nb as c,nd as E,oa as J,pc as W,tb as u,vc as g,wa as _,xa as f,xc as m}from"./chunk-C2QKZJOP.js";import"./chunk-AKP2VPKK.js";import"./chunk-ML3VIXIY.js";import{d as S,n as $}from"./chunk-INB5GR2I.js";import{a as Q}from"./chunk-B7YGBANW.js";$();var fe=[{dataField:"name",caption:"\u0421\u043A\u043B\u0430\u0434"},{dataField:"address",caption:"\u0410\u0434\u0440\u0435\u0441",width:"40%"},{dataField:"custom",caption:"\u0414\u043E\u0441\u0442\u0443\u043F\u0435\u043D \u0434\u043B\u044F \u0442\u043E\u0440\u0433\u043E\u0432\u044B\u0445 \u0442\u043E\u0447\u0435\u043A",width:"25%",isCustom:!0}];function ge(i,t,e){let Ce=b=>i%10===1&&i%100!==11?b.one:i%10>1&&i%10<5&&!(i%100>=11&&i%100<=14)?b.several:b.many,D=t;return e.forEach((b,we)=>{let z=new RegExp(`{{ #${we+1} }}`,"g");if(D.match(z)){let Ee=Ce(b);D=D.replace(z,Ee)}}),D}var ye=["table"],We=i=>({custom:i});function xe(i,t){if(i&1&&y(0,"wk-button",9),i&2){let e=m(2);r("icon",e.icons.Plus)}}function Ie(i,t){if(i&1&&d(0,xe,1,1,"wk-button",8),i&2){let e=m();r("ngIf",e.canCreateWarehouse)}}function ke(i,t){if(i&1){let e=W();a(0,"wk-button",18),g("clicked",function(){_(e);let n=m(2);return f(n.editWarehouse(n.mainWarehouse))}),s()}if(i&2){let e=m(2);r("icon",e.icons.Edit)}}function Te(i,t){if(i&1&&(a(0,"wk-card",10)(1,"div",11)(2,"div")(3,"div",12),w(4,"\u041E\u0441\u043D\u043E\u0432\u043D\u043E\u0439 \u0441\u043A\u043B\u0430\u0434 \u0442\u0435\u043A\u0443\u0449\u0435\u0439 \u0442\u043E\u0440\u0433\u043E\u0432\u043E\u0439 \u0442\u043E\u0447\u043A\u0438"),s(),a(5,"div",13),w(6),s()()(),a(7,"div",14)(8,"div",15),y(9,"wk-badge",16)(10,"wk-badge",16),s(),d(11,ke,1,1,"wk-button",17),s()()),i&2){let e=m();c(6),Z(e.mainWarehouse.name),c(3),r("icon",e.icons.Location)("text",e.mainWarehouse.address)("tooltipPosition","bottom"),c(),r("icon",e.icons.Store)("text",e.getStoreCount(e.mainWarehouse.stores.length))("tooltipPosition","bottom"),c(),r("ngIf",e.canEditWarehouse)}}function De(i,t){i&1&&(a(0,"div",19),w(1,"\u0421\u043F\u0438\u0441\u043E\u043A \u043E\u0441\u0442\u0430\u043B\u044C\u043D\u044B\u0445 \u0441\u043A\u043B\u0430\u0434\u043E\u0432"),s())}function Ne(i,t){i&1&&(a(0,"div",19),w(1,"\u0421\u043F\u0438\u0441\u043E\u043A \u0441\u043A\u043B\u0430\u0434\u043E\u0432"),s())}function Ue(i,t){if(i&1&&w(0),i&2){let e=t.$implicit,o=m();ee(" ",o.getStoreCount(e.stores.length),`
`)}}var l,I=(l=class{constructor(t,e,o,n){this._router=t,this._cdr=e,this._permissionService=o,this._warehouseService=n,this.warehouses$=J(ae).select(H.warehouses),this.icons=O,this.columns=fe,this.mainWarehouse=null,this.otherWarehouses=[],this.tableItems=[{text:"\u0420\u0435\u0434\u0430\u043A\u0442\u0438\u0440\u043E\u0432\u0430\u0442\u044C",visible:()=>this.canEditWarehouse,action:p=>this.editWarehouse(p)}]}ngOnInit(){this._initWarehouses(),this.canCreateWarehouse=this._permissionService.hasPermissions(v.CreateWarehouse),this.canEditWarehouse=this._permissionService.hasPermissions(v.EditWarehouse)}editWarehouse(t){t?.id&&this._router.navigate(["/cabinet/company/warehouses/edit"],{queryParams:{id:t.id},state:{name:t.name,address:t.address}})}getStoreCount(t){return t===0?"\u041D\u0435\u0442 \u0442\u043E\u0440\u0433\u043E\u0432\u044B\u0445 \u0442\u043E\u0447\u0435\u043A":ge(t,`${t} \u0442\u043E\u0440\u0433\u043E\u0432{{ #1 }} \u0442\u043E\u0447{{ #2 }}`,[{one:"\u0430\u044F",several:"\u044B\u0435",many:"\u044B\u0445"},{one:"\u043A\u0430",several:"\u043A\u0438",many:"\u0435\u043A"}])}_initWarehouses(){this.table?.dataGrid.instance.beginCustomLoading(""),this._warehouseService.getWarehouseAll().pipe(x(this)).subscribe(t=>{this.mainWarehouse=t.find(e=>e.id===this.mainWarehouseId)??null,this.otherWarehouses=t.filter(e=>e.id!==this.mainWarehouseId),this.table?.dataGrid.instance.endCustomLoading(),this._cdr.detectChanges()})}},l.\u0275fac=function(e){return new(e||l)(u(R),u(A),u(me),u(j))},l.\u0275cmp=U({type:l,selectors:[["tis-warehouse-list"]],viewQuery:function(e,o){if(e&1&&Y(ye,5),e&2){let n;K(n=X())&&(o.table=n.first)}},decls:12,vars:15,consts:[["headerTmpl",""],["table",""],["allWarehouse",""],["customColumn",""],[1,"header",3,"showBackButton","actionTemplate","title"],["stylingMode","outline",4,"ngIf"],["class","font-st2",4,"ngIf","ngIfElse"],[3,"allowColumnResizing","data","columns","menuItems","enableSpinner","enableContextMenu","customTemplates"],["routerLink","/cabinet/company/warehouses/create","token","create-warehouse","label","\u041D\u043E\u0432\u044B\u0439 \u0441\u043A\u043B\u0430\u0434",3,"icon",4,"ngIf"],["routerLink","/cabinet/company/warehouses/create","token","create-warehouse","label","\u041D\u043E\u0432\u044B\u0439 \u0441\u043A\u043B\u0430\u0434",3,"icon"],["stylingMode","outline"],[1,"active-warehouse-header"],[1,"font-b1-secondary"],[1,"font-st1","warehouse-name"],[1,"active-warehouse-info"],[1,"active-warehouse-badges"],["size","large","variant","secondary",3,"icon","text","tooltipPosition"],["stylingMode","outlined","variant","secondary","label","\u0420\u0435\u0434\u0430\u043A\u0442\u0438\u0440\u043E\u0432\u0430\u0442\u044C",3,"icon","clicked",4,"ngIf"],["stylingMode","outlined","variant","secondary","label","\u0420\u0435\u0434\u0430\u043A\u0442\u0438\u0440\u043E\u0432\u0430\u0442\u044C",3,"clicked","icon"],[1,"font-st2"]],template:function(e,o){if(e&1&&(y(0,"tis-subheader",4),d(1,Ie,1,1,"ng-template",null,0,E),a(3,"tis-main-layout"),d(4,Te,12,8,"wk-card",5)(5,De,2,0,"div",6),y(6,"tis-table",7,1),s(),d(8,Ne,2,0,"ng-template",null,2,E)(10,Ue,1,1,"ng-template",null,3,E)),e&2){let n=C(2),p=C(9),T=C(11);r("showBackButton",!1)("actionTemplate",n)("title","\u0421\u043A\u043B\u0430\u0434\u044B"),c(4),r("ngIf",o.mainWarehouse),c(),r("ngIf",o.mainWarehouse)("ngIfElse",p),c(),r("allowColumnResizing",!0)("data",o.otherWarehouses)("columns",o.columns)("menuItems",o.tableItems)("enableSpinner",!0)("enableContextMenu",o.canEditWarehouse)("customTemplates",te(13,We,T))}},dependencies:[M,ie,re,L,B,P,ne,V,le],styles:[`[_nghost-%COMP%]{display:flex;flex-direction:column;min-height:100%}.header[_ngcontent-%COMP%]{top:0;position:sticky;z-index:10}.active-warehouse-header[_ngcontent-%COMP%]{display:flex;gap:var(--space-horizontal-l);justify-content:space-between;margin-bottom:var(--space-vertical-l)}.warehouse-name[_ngcontent-%COMP%]{display:-webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp:1;overflow:hidden;text-overflow:ellipsis;word-break:break-word;text-decoration:none}.active-warehouse-info[_ngcontent-%COMP%]{display:flex;justify-content:space-between;align-items:center;gap:var(--space-horizontal-l)}.active-warehouse-badges[_ngcontent-%COMP%]{display:flex;gap:var(--space-horizontal-l)}
/*# sourceMappingURL=warehouse-list.component-QUCH4D66.css.map */`],changeDetection:0}),l);S([ue(H.mainWarehouseId)],I.prototype,"mainWarehouseId",void 0);I=S([F()],I);$();function Ae(i,t){if(i&1){let e=W();a(0,"wk-button",5),g("clicked",function(){_(e);let n=m();return f(n.submit())}),s()}if(i&2){let e=m();r("icon",e.icons.Save)}}var h,k=(h=class{constructor(t,e,o,n,p){this._cdr=t,this._router=e,this._route=o,this._warehouseService=n,this._toastService=p,this.icons=O,this.warehouseId=N(null),this.warehouseName=N(null),this.warehouseAddress=N(null),this.isEditForm=!1,this.warehouseAddress.set(this._router.getCurrentNavigation()?.extras.state?.address??null),this.warehouseName.set(this._router.getCurrentNavigation()?.extras.state?.name??null)}ngOnInit(){this._checkWarehouseId()}initForm(t){this.warehouseUpsertForm=t,this._updateForm()}submit(){if(this.warehouseUpsertForm.markAllAsTouched(),this._cdr.detectChanges(),this.warehouseUpsertForm.valid){let t=Q({},this.warehouseUpsertForm.value);if(this.isEditForm){this._editWarehouse(t);return}this._createWarehouse(t)}}back(){this._router.navigate(["cabinet/company/warehouses"])}_checkWarehouseId(){this._route.queryParams.pipe(q(1)).subscribe(t=>{this.warehouseId.set(t.id),this.isEditForm=!!this.warehouseId(),this.isEditForm||this._router.navigate(["/cabinet/company/warehouses/create"]),this.warehouseId()&&!this.warehouseName()&&!this.warehouseAddress()&&(this._toastService.add(_e),this.back())})}_updateForm(){this.warehouseUpsertForm.patchValue({name:this.warehouseName()??"",address:this.warehouseAddress()??""})}_createWarehouse(t){this._warehouseService.createWarehouse(t).pipe(x(this)).subscribe(()=>{this._toastService.add(pe),this._router.navigate(["/cabinet/company/warehouses"])})}_editWarehouse(t){let e=this.warehouseId();e&&this._warehouseService.editWarehouse(t,e).pipe(x(this)).subscribe(()=>{this._toastService.add(de),this._router.navigate(["/cabinet/company/warehouses"])})}},h.\u0275fac=function(e){return new(e||h)(u(A),u(R),u(oe),u(j),u(se))},h.\u0275cmp=U({type:h,selectors:[["tis-warehouse-upsert"]],decls:6,vars:4,consts:[["headerTmpl",""],[1,"header",3,"backButtonClicked","actionTemplate","title"],["background","secondary"],["header","\u0414\u0430\u043D\u043D\u044B\u0435 \u043E \u0441\u043A\u043B\u0430\u0434\u0435","tisColumns","1/6"],[3,"formReady","initialValue","isEdit"],["token","submit","variant","success","label","\u0421\u043E\u0445\u0440\u0430\u043D\u0438\u0442\u044C",3,"clicked","icon"]],template:function(e,o){if(e&1){let n=W();a(0,"tis-subheader",1),g("backButtonClicked",function(){return _(n),f(o.back())}),s(),d(1,Ae,1,1,"ng-template",null,0,E),a(3,"tis-main-layout",2)(4,"wk-card",3)(5,"tis-warehouse-upsert-form",4),g("formReady",function(T){return _(n),f(o.initForm(T))}),s()()()}if(e&2){let n=C(2);r("actionTemplate",n)("title",o.isEditForm?"\u0420\u0435\u0434\u0430\u043A\u0442\u0438\u0440\u043E\u0432\u0430\u043D\u0438\u0435 \u0441\u043A\u043B\u0430\u0434\u0430":"\u041D\u043E\u0432\u044B\u0439 \u0441\u043A\u043B\u0430\u0434"),c(5),r("initialValue",o.initialFormValue)("isEdit",o.isEditForm)}},dependencies:[M,L,B,he,P,V,ce],styles:[`[_nghost-%COMP%]{display:flex;flex-direction:column;min-height:100%}.header[_ngcontent-%COMP%]{top:0;position:sticky;z-index:10}
/*# sourceMappingURL=warehouse-upsert.component-CD5GRJDY.css.map */`],changeDetection:0}),h);k=S([F()],k);var kt=[{path:"",component:I,pathMatch:"full"},{path:"create",component:k,canActivate:[G],data:{permissions:[v.CreateWarehouse]}},{path:"edit",component:k,canActivate:[G],data:{permissions:[v.EditWarehouse]}},{path:"**",redirectTo:""}];export{kt as routes};
//# sourceMappingURL=warehouse.routes-K7AML6VO.js.map
