import{a as x}from"./chunk-V5CW4EY5.js";import{a as fe}from"./chunk-DV3DSI3N.js";import{a as Ce}from"./chunk-YGRCRXXK.js";import{b as De}from"./chunk-YLT5F6J5.js";import"./chunk-AANUGJO2.js";import{a as be}from"./chunk-M63JVBVE.js";import"./chunk-7LB63SXX.js";import"./chunk-JAY45DEO.js";import{a as ge}from"./chunk-WH5RBXYQ.js";import{t as M}from"./chunk-W3BEWLBM.js";import"./chunk-LINAD4CC.js";import{a as me}from"./chunk-DCREHIGF.js";import{f as de,p as he}from"./chunk-ZVQ5RRLK.js";import{b as _e}from"./chunk-R7MAHTDS.js";import{e as E}from"./chunk-2MNVXWEX.js";import{A as te,D as ie,F as oe,Ja as ne,Ka as ae,La as se,Ma as ue,Qa as ce,_a as le,o as D,q as K,r as W,ta as re,v as Z,x as ee}from"./chunk-YFBLRBP4.js";import{a as b,b as l}from"./chunk-VXSBHXCN.js";import"./chunk-RESH3J2M.js";import"./chunk-IFY4UZPR.js";import{n as pe}from"./chunk-DC6G5OHZ.js";import"./chunk-JUPKAJPM.js";import"./chunk-PDYJ5OYY.js";import"./chunk-Z2AWIQRI.js";import{fa as X,ua as J}from"./chunk-3OWC7J4L.js";import{Bb as f,Bc as B,Cc as G,Cd as g,Dc as O,Ea as A,Ec as j,Fc as V,Gb as R,Gc as q,L as P,_b as w,_c as Q,ac as L,fc as c,gc as d,hc as h,ic as p,id as $,jd as z,nb as m,nd as Y,oa as F,pc as U,tb as n,vc as N,wa as T,xa as k,xc as C,yd as H}from"./chunk-C2QKZJOP.js";import"./chunk-AKP2VPKK.js";import"./chunk-ML3VIXIY.js";import{d as _,n as I}from"./chunk-INB5GR2I.js";import"./chunk-B7YGBANW.js";I();I();var a=(function(o){return o[o.Constant=0]="Constant",o[o.Promotional=1]="Promotional",o})(a||{}),Ee={[a.Constant]:"\u041F\u043E\u0441\u0442\u043E\u044F\u043D\u043D\u0430\u044F",[a.Promotional]:"\u0410\u043A\u0446\u0438\u043E\u043D\u043D\u0430\u044F"};var Ie=["datePicker"];function Fe(o,t){if(o&1&&p(0,"wk-date-picker",4,0),o&2){let e=C();c("type","range")("placeholder","\u0434\u0434.\u043C\u043C.\u0433\u0433\u0433\u0433")("endDatePlaceholder","\u0434\u0434.\u043C\u043C.\u0433\u0433\u0433\u0433")("requiredForLabel",!0)("errorMessage",e.errorText())}}var s,y=(s=class{constructor(t,e,i,r){this.data=t,this._dialogRef=e,this._fb=i,this._cdr=r,this.datePicker=H("datePicker"),this.errorText=A(""),this.priceTypeOptions=[{id:a.Constant,name:"\u041F\u043E\u0441\u0442\u043E\u044F\u043D\u043D\u0430\u044F"},{id:a.Promotional,name:"\u0410\u043A\u0446\u0438\u043E\u043D\u043D\u0430\u044F"}],this.priceForm=this._fb.group({name:this._fb.nonNullable.control(this.data?.name??"",[D.required,D.minLength(de.min),D.maxLength(he.max)]),type:this._fb.nonNullable.control({value:this.data?.type??a.Constant,disabled:!!this.data?.id},[me()]),period:this._fb.control({value:this.data?.period??[],disabled:this.data?.type===a.Constant||!this.data?.type},[x.rangeRequired(),x.period()])})}ngOnInit(){this._dialogRef.submitData$$.next(this.priceForm),this._dialogRef.instance?.submitted.pipe(l(this)).subscribe(()=>{this._cdr.markForCheck()}),this.priceForm.controls.type.valueChanges.pipe(l(this)).subscribe(t=>{t===a.Constant?this.priceForm.controls.period.disable():this.priceForm.controls.period.enable()})}},s.\u0275fac=function(e){return new(e||s)(n(se),n(ae),n(ie),n(g))},s.\u0275cmp=f({type:s,selectors:[["tis-upsert-price-dialog"]],viewQuery:function(e,i){e&1&&j(i.datePicker,Ie,5),e&2&&V()},decls:4,vars:5,consts:[["datePicker",""],[1,"form",3,"formGroup"],["label","\u041D\u0430\u0438\u043C\u0435\u043D\u043E\u0432\u0430\u043D\u0438\u0435 \u0446\u0435\u043D\u044B \u043F\u0440\u043E\u0434\u0430\u0436\u0438","formControlName","name","token","name",1,"name"],["label","\u0422\u0438\u043F","formControlName","type","token","type",1,"type",3,"requiredForLabel","options","showClearButton"],["label","\u041F\u0435\u0440\u0438\u043E\u0434","formControlName","period","token","period","helperText","\u0426\u0435\u043D\u0430 \u043F\u0440\u043E\u0434\u0430\u0436\u0438 \u043E\u0442\u043E\u0431\u0440\u0430\u0437\u0438\u0442\u0441\u044F \u0432 \u0440\u0435\u0436\u0438\u043C\u0435 \u043D\u0430 \u0443\u043A\u0430\u0437\u0430\u043D\u043D\u044B\u0439 \u0432\u0430\u043C\u0438 \u043F\u0435\u0440\u0438\u043E\u0434 \u0430\u0432\u0442\u043E\u043C\u0430\u0442\u0438\u0447\u0435\u0441\u043A\u0438",1,"period",3,"type","placeholder","endDatePlaceholder","requiredForLabel","errorMessage"]],template:function(e,i){e&1&&(d(0,"form",1),p(1,"tis-text-field",2)(2,"wk-dropdown",3),w(3,Fe,2,5,"wk-date-picker",4),h()),e&2&&(c("formGroup",i.priceForm),m(2),c("requiredForLabel",!0)("options",i.priceTypeOptions)("showClearButton",!1),m(),L(i.priceForm.controls.type.value?3:-1))},dependencies:[oe,Z,K,W,ee,te,_e,ce,ne],styles:[`.form[_ngcontent-%COMP%]{display:grid;grid-template-columns:repeat(6,1fr);gap:var(--space-vertical-l)}.name[_ngcontent-%COMP%]{grid-column:1/5;margin-bottom:0}.type[_ngcontent-%COMP%]{grid-column:5/7;margin-bottom:0}.period[_ngcontent-%COMP%]{grid-column:1/7;margin-bottom:0}
/*# sourceMappingURL=upsert-price-dialog.component-IOXAXJ5G.css.map */`],changeDetection:0}),s);y=_([b()],y);var ye=[{dataField:"name",caption:"\u041D\u0430\u0438\u043C\u0435\u043D\u043E\u0432\u0430\u043D\u0438\u0435"},{dataField:"type",caption:"\u0422\u0438\u043F",customizeText:({value:o})=>Ee[o],width:"25%"},{dataField:"period",caption:"\u041F\u0435\u0440\u0438\u043E\u0434",calculateCellValue:o=>o.from&&o.to?`${M(new Date(o.from),"dd.MM.yyyy")}-${M(new Date(o.to),"dd.MM.yyyy")}`:"-"}],Se={type:"success",header:"\u0426\u0435\u043D\u0430",message:"\u0426\u0435\u043D\u0430 \u0443\u0441\u043F\u0435\u0448\u043D\u043E \u0441\u043E\u0437\u0434\u0430\u043D\u0430"},ve={type:"success",header:"\u0426\u0435\u043D\u0430",message:"\u0426\u0435\u043D\u0430 \u0443\u0441\u043F\u0435\u0448\u043D\u043E \u0441\u043E\u0445\u0440\u0430\u043D\u0435\u043D\u0430"},Pe={type:"success",header:"\u0426\u0435\u043D\u0430",message:"\u0426\u0435\u043D\u0430 \u0443\u0441\u043F\u0435\u0448\u043D\u043E \u0443\u0434\u0430\u043B\u0435\u043D\u0430"};var Te=["table"],ke=()=>[];function Ae(o,t){if(o&1){let e=U();d(0,"wk-button",4),N("clicked",function(){T(e);let r=C();return k(r.openUpsertDialog())}),h()}if(o&2){let e=C();c("icon",e.plusIcon)}}var u,S=(u=class{constructor(t,e,i,r){this._priceService=t,this._dialogService=e,this._toastService=i,this._cdr=r,this.prices$=F(pe).select(be.prices),this.columns=ye,this.plusIcon=E.Plus,this.menuItem=[{text:"\u0420\u0435\u0434\u0430\u043A\u0442\u0438\u0440\u043E\u0432\u0430\u0442\u044C",action:v=>this.openUpsertDialog(v)},{text:"\u0423\u0434\u0430\u043B\u0438\u0442\u044C",action:v=>this._openDeleteDialog(v.id)}]}ngAfterViewInit(){this.prices$.pipe(l(this)).subscribe(t=>{this.table&&(this.table.dataGrid.height=t.length>10?"392px":"100%",this._cdr.detectChanges())})}openUpsertDialog(t){let e=this._initUpsertDialog(t);e.canceled.pipe(P(1)).subscribe(()=>e.close()),e.additionalAction.pipe(l(e)).subscribe(()=>{this._deletePrice(e,t?.id)}),e.submitted.pipe(l(e)).subscribe(i=>{if(i.markAllAsTouched(),!i.invalid){if(t){this._editPrice(t.id,i.value,e);return}this._createPrice(i.value,e)}})}_initUpsertDialog(t){return this._dialogService.open(y,{data:{id:t?.id,name:t?.name,type:t?.type,period:t?.from&&t?.to?[new Date(t.from),new Date(t.to)]:[]},header:t?.id?"\u0420\u0435\u0434\u0430\u043A\u0442\u0438\u0440\u043E\u0432\u0430\u043D\u0438\u0435 \u0446\u0435\u043D\u044B \u043F\u0440\u043E\u0434\u0430\u0436\u0438":"\u041D\u043E\u0432\u0430\u044F \u0446\u0435\u043D\u0430 \u043F\u0440\u043E\u0434\u0430\u0436\u0438",cancelButton:"\u041E\u0442\u043C\u0435\u043D\u0430",submitButton:{label:"\u0421\u043E\u0445\u0440\u0430\u043D\u0438\u0442\u044C",variant:"success",icon:E.Save},additionalButton:t?.id?{variant:"danger",stylingMode:"outlined",label:"\u0423\u0434\u0430\u043B\u0438\u0442\u044C"}:void 0})}_createPrice(t,e){this._priceService.createPrice(t).subscribe(()=>{e.close(),this._toastService.add(Se),this._cdr.detectChanges()})}_editPrice(t,e,i){this._priceService.updatePrice(t,e).subscribe(()=>{i.close(),this._toastService.add(ve),this._cdr.detectChanges()})}_openDeleteDialog(t){let e=this._dialogService.open(null,{header:"\u0423\u0434\u0430\u043B\u0435\u043D\u0438\u0435 \u0446\u0435\u043D\u044B",text:"\u0412\u044B \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043B\u044C\u043D\u043E \u0445\u043E\u0442\u0438\u0442\u0435 \u0443\u0434\u0430\u043B\u0438\u0442\u044C \u0446\u0435\u043D\u0443?",submitButton:{label:"\u0414\u0430, \u0443\u0434\u0430\u043B\u0438\u0442\u044C",icon:E.Delete,variant:"success"},cancelButton:"\u041D\u0435\u0442"});e.canceled.pipe(P(1)).subscribe(()=>e.close()),e.submitted.pipe(l(e)).subscribe(()=>{this._deletePrice(e,t)})}_deletePrice(t,e){e&&this._priceService.deletePrice(e).subscribe(()=>{this._toastService.add(Pe),this._cdr.detectChanges(),t.close()})}},u.\u0275fac=function(e){return new(e||u)(n(De),n(ue),n(le),n(g))},u.\u0275cmp=f({type:u,selectors:[["tis-price-list"]],viewQuery:function(e,i){if(e&1&&B(Te,5),e&2){let r;G(r=O())&&(i.table=r.first)}},decls:7,vars:10,consts:[["headerActions",""],["table",""],["title","\u0412\u0438\u0434\u044B \u0446\u0435\u043D",1,"header",3,"showBackButton","actionTemplate"],[3,"allowColumnResizing","columns","data","menuItems","enableContextMenu"],["token","sell-price","label","\u0426\u0435\u043D\u0430 \u043F\u0440\u043E\u0434\u0430\u0436\u0438",3,"clicked","icon"]],template:function(e,i){if(e&1&&(p(0,"tis-subheader",2),R(1,Ae,1,1,"ng-template",null,0,Y),d(3,"tis-main-layout"),p(4,"tis-table",3,1),$(6,"async"),h()),e&2){let r=q(2);c("showBackButton",!1)("actionTemplate",r),m(4),c("allowColumnResizing",!0)("columns",i.columns)("data",z(6,7,i.prices$)??Q(9,ke))("menuItems",i.menuItem)("enableContextMenu",!0)}},dependencies:[fe,Ce,re,ge,J,X],styles:[`[_nghost-%COMP%]{display:flex;flex-direction:column;min-height:100%}.header[_ngcontent-%COMP%]{top:0;position:sticky;z-index:10}
/*# sourceMappingURL=price-list.component-QYC6GPAI.css.map */`],changeDetection:0}),u);S=_([b()],S);var bt=[{path:"",component:S,pathMatch:"full"},{path:"**",redirectTo:""}];export{bt as routes};
//# sourceMappingURL=price.routes-ICTEAYW2.js.map
