import{a as he,b as pe,c as de,d as _e}from"./chunk-VRNO5TYT.js";import{a as me}from"./chunk-NLTW5I4K.js";import{a as V}from"./chunk-AMAS4Z3P.js";import{a as P}from"./chunk-RDILTRSG.js";import{a as G}from"./chunk-6IHNMCNK.js";import"./chunk-EGRHWZRV.js";import{a as j}from"./chunk-5SXN6XJU.js";import{a as le}from"./chunk-6X6346LN.js";import"./chunk-ZJ56VDA3.js";import"./chunk-JWB3UQDY.js";import"./chunk-ZVQ5RRLK.js";import"./chunk-GVW75DLG.js";import{f as O}from"./chunk-XSARCGYY.js";import{Ca as re,Fa as B,Ya as se,ra as L}from"./chunk-HE5QLLAI.js";import"./chunk-2MCAID7M.js";import{a as F,b as x}from"./chunk-2RGQU2W2.js";import{a as v}from"./chunk-V7DSNPC4.js";import{d as ce}from"./chunk-CZPAHUJN.js";import"./chunk-CPQV7SBX.js";import"./chunk-KDOCYYUQ.js";import"./chunk-AV5HDXJZ.js";import{c as H}from"./chunk-Z6SV7MD7.js";import"./chunk-JOFGKPLY.js";import"./chunk-DQKXTCBX.js";import"./chunk-CCKSEROE.js";import"./chunk-FTPWLRQ4.js";import"./chunk-CC7H2Q52.js";import"./chunk-FWAWZDGH.js";import"./chunk-OXEFBKMX.js";import"./chunk-WUNNKW5D.js";import"./chunk-IFY4UZPR.js";import"./chunk-Y4KZVCMP.js";import"./chunk-SRKRR7GV.js";import"./chunk-C2ZF4U5U.js";import"./chunk-PDYJ5OYY.js";import"./chunk-ICDY5Q2H.js";import{a as ue}from"./chunk-TWAW6QQO.js";import{o as ae}from"./chunk-AEEDSABA.js";import{s as oe,u as R,v as ne}from"./chunk-JLM6CY35.js";import{Y as ie,ua as M}from"./chunk-KCGGIUK4.js";import{Ac as X,Ba as N,Cb as U,Dc as C,Hb as d,Ic as w,J as q,Jc as Z,Kc as ee,Xc as te,cc as r,dc as a,ec as s,fc as y,jd as E,kb as c,la as J,mc as W,sc as g,ta as _,ua as f,uc as m,vb as u,yc as Y,yd as A,zc as K}from"./chunk-4HRPSKID.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(ce),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,me],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-YZ23HMGR.js.map
