import{a as F,b as A,c as Se}from"./chunk-EQOABAHY.js";import{a as be,b as ye}from"./chunk-KPDUR5ZX.js";import{b as j}from"./chunk-BCEICZWK.js";import{a as ce,b as pe}from"./chunk-FYIZFGPM.js";import{Da as V,Lb as O,ab as $,cb as me,db as ue,eb as de,gb as q,ib as fe,kb as he,lb as ve,qb as ge,rb as _e}from"./chunk-LLHT3ZD5.js";import{c as Ce,i as Te}from"./chunk-I7YBTL7H.js";import{Ab as v,Bc as P,Cc as ae,Dc as L,F as Z,Gb as ee,Hb as te,Ib as ie,Jb as ne,K as Y,La as a,Lb as u,Ma as E,Mb as se,Nb as x,Tc as k,Ua as T,Va as S,Wb as re,X as W,Yb as le,Za as b,d as B,da as C,gb as c,ib as X,j as z,k as J,kc as oe,ma as R,na as p,oa as m,oc as I,sb as l,tb as r,ub as N,va as d,vb as g,wb as _,yb as y,zb as h}from"./chunk-6OGPGUKY.js";var Ee=(s,i)=>({"bg-blue-100 font-bold text-red-500":s,"hover:bg-gray-100":i});function xe(s,i){if(s&1){let e=y();g(0),l(1,"div",5)(2,"h3",6),u(3," Resultado da busca "),r(),l(4,"div")(5,"vip-button",7),h("click",function(){p(e);let n=v();return m(n.clearFilter())}),l(6,"span",8),u(7," Limpar "),r(),N(8,"i",9),r()()(),_()}}function Ve(s,i){if(s&1){let e=y();l(0,"li",12),h("click",function(){let n=p(e).$implicit,o=v(2);return m(o.selectItem(n))}),l(1,"span"),u(2),r(),l(3,"span"),u(4),r()()}if(s&2){let e=i.$implicit,t=v(2);c("ngClass",le(3,Ee,e===t.selectedItem,e!==t.selectedItem)),a(2),x("",(e==null?null:e.nome)+" "+(e==null?null:e.sobrenome)," "),a(2),se(e==null?null:e.cpf_formatado)}}function Fe(s,i){if(s&1&&(g(0),l(1,"div",10)(2,"ul"),b(3,Ve,5,6,"li",11),r()(),_()),s&2){let e=v();a(3),c("ngForOf",e.items)}}function De(s,i){if(s&1&&(l(0,"div",14)(1,"h2",15),u(2),r()()),s&2){let e=v(2);a(2),x(" ",e.getMessage()," ")}}function Re(s,i){if(s&1&&b(0,De,3,1,"div",13),s&2){let e=v();c("ngIf",!e.loadingTelevendas&&e.searchValue&&e.searchValue.length>2&&e.items&&e.items.length<=0)}}function Ne(s,i){if(s&1){let e=y();g(0),l(1,"div",16)(2,"vip-button",17),h("click",function(){p(e);let n=v();return m(n.abrirModalValidaCEP())}),u(3," Cadastrar Cliente "),r()(),_()}}var H=(()=>{class s{constructor(e){this.cd=e,this.items=[],this.selectedItem=null,this.isDeskTopResponsive=!1,this.loadingTelevendas=!1,this.searchValue="",this.itemSelected=new d,this.openModalCep=new d,this.resetForm=new d,this.fetchItems=new d,this.viewButtonRegister=!1}ngOnChanges(e){e.searchValue&&this.searchValue?.length<3&&(this.items=[],this.viewButtonRegister=!0),e.items&&this.items.length<=0&&(this.viewButtonRegister=!0)}selectItem(e){this.selectedItem=e,this.itemSelected.emit(e),this.clearFilter()}clearFilter(){this.items=[],this.selectedItem=null,this.resetForm.emit(),this.viewButtonRegister=!0}abrirModalValidaCEP(){this.openModalCep.emit()}isOnlyNumbers(e){if(e==null||e.includes("@"))return!1;let t=e.replace(/\D/g,"");return/^\d+$/.test(t)}getMessage(){let e=this.searchValue||"";return e.includes("@")?V.EMAIL:this.isCellPhoneNumber(e)?V.CELULAR:this.isOnlyNumbers(e)?V.CPF:V.NOME}isCellPhoneNumber(e){return/\(\d{2}\)/.test(e)}static{this.\u0275fac=function(t){return new(t||s)(E(I))}}static{this.\u0275cmp=T({type:s,selectors:[["vip-list-select"]],inputs:{items:"items",selectedItem:"selectedItem",isDeskTopResponsive:"isDeskTopResponsive",loadingTelevendas:"loadingTelevendas",searchValue:"searchValue"},outputs:{itemSelected:"itemSelected",openModalCep:"openModalCep",resetForm:"resetForm",fetchItems:"fetchItems"},standalone:!1,features:[R],decls:7,vars:4,consts:[["notFoundItems",""],[1,"list-select"],[1,"list-none","p-0"],[4,"ngIf"],[4,"ngIf","ngIfElse"],[1,"flex","justify-between","items-center","header-result"],[1,"font-medium","vip-color-first-default","text-base"],["type","normal","size","small",3,"click"],[1,"vip-color-error-main","font-roboto","text-xs","font-medium","tracking-custom"],[1,"icon-delete_forever","text-xs","vip-color-error-main"],[1,"max-h-48","overflow-scroll"],["class","cursor-pointer p-2 transition duration-200 flex justify-between items-center hover:font-bold hover:text-red-500 hover:bg-blue-100",3,"ngClass","click",4,"ngFor","ngForOf"],[1,"cursor-pointer","p-2","transition","duration-200","flex","justify-between","items-center","hover:font-bold","hover:text-red-500","hover:bg-blue-100",3,"click","ngClass"],["class","mt-8 mb-8",4,"ngIf"],[1,"mt-8","mb-8"],[1,"text-xs","sm:text-xs","md:text-sm","text-center"],[1,"mt-2"],["data-cy","button-aplicar-filtro","type","raised",1,"mt-auto",3,"click"]],template:function(t,n){if(t&1&&(l(0,"div",1)(1,"ul",2),b(2,xe,9,0,"ng-container",3)(3,Fe,4,1,"ng-container",4)(4,Re,1,1,"ng-template",null,0,oe)(6,Ne,4,0,"ng-container",3),r()()),t&2){let o=ne(5);a(2),c("ngIf",n.items&&n.items.length>0&&n.searchValue.length>2),a(),c("ngIf",n.items&&n.items.length>0)("ngIfElse",o),a(3),c("ngIf",n.items&&n.items.length===0&&n.viewButtonRegister)}},dependencies:[P,ae,L,Ce],encapsulation:2,changeDetection:0})}}return s})();var Le=()=>[];function Oe(s,i){s&1&&(g(0),l(1,"div",9)(2,"small"),u(3,"M\xEDnimo de 3 caracteres para a busca"),r()(),_())}var ke=class K{set filiaisTelevendas(i){this._filiaisTelevenda=i??null,this.cd.detectChanges()}get filiaisTelevendas(){return this._filiaisTelevenda}set clientesTelevenda(i){this._clientesTelevenda=i??[]}get clientesTelevenda(){return this._clientesTelevenda}constructor(i,e){this.cd=i,this.NgxMaskPipe=e,this.openModalCepEmitter=new d,this.isDesktopResponsive=!1,this.loadingTelevendas=!1,this.isTelevendas=!1,this.openDesktopCepModal=new d,this.searchClickTelevendas=new d,this.itemSelected=new d,this.selectedFilial=new d,this.isDesktopResponsiveRef=!1,this.filiais=[],this.searchValue="",this.destroy$=new B,this._clientesTelevenda=[],this._filiaisTelevenda=null,this.masks={cpf:O.CPF,cnpj:O.CNPJ,celular:O.CELULAR,email:""},this.currentInputType="email",this.mask="",this.previousSearchValue="",this.searchTerms=new B,this.formGroup=new de({filial:new q(null,[$.required]),cliente:new q("",[$.required])})}ngOnInit(){this.isDesktopResponsiveRef=this.isDesktopResponsive,this.isDesktopResponsiveRef||(Array.isArray(this._filiaisTelevenda?.filiais)?this.filiais=this._filiaisTelevenda?.filiais.map(i=>({value:{vipcommerce_filial_id:i?.vipcommerce_filial_id.toString(),filial_id:i?.id},text:i.nome??""}))??[]:this.filiais=[]),this.searchTerms.pipe(Z(300),Y(),pe(this)).subscribe(i=>{this.searchClickTelevendas.emit(new F("keyup",i,new Event("debounced")))})}ngOnChanges(){this.searchInput&&this.formGroup.get("cliente")?.setValue(this.searchInput.input?.nativeElement.value),Array.isArray(this._filiaisTelevenda?.filiais)?this.filiais=this._filiaisTelevenda?.filiais.map(i=>({value:{vipcommerce_filial_id:i?.vipcommerce_filial_id?.toString(),filial_id:i?.id},text:i?.nome??""}))??[]:this.filiais=[],this.formGroup.get("cliente")?.valueChanges.pipe(W(this.destroy$)).subscribe(i=>{i.length<3?this.formGroup.get("cliente")?.setErrors({minlength:!0}):this.formGroup.get("cliente")?.setErrors(null)})}ngOnDestroy(){this.destroy$.next(),this.destroy$.complete()}openModalCep(){this.isDesktopResponsive?this.openDesktopCepModal.emit():this.openModalCepEmitter.emit()}handleSearchEvent(i){if(i.stopPropagation(),this.searchValue=i.value,this.searchInput){let e=this.searchInput.input?.nativeElement;if(e){let t=e.value||"",n=e.selectionStart;if(e.value=t,e.setSelectionRange(n,n),/^\d/.test(t)){let o=t.replace(/[-./]/g,"");(this.currentInputType==="cpf"||this.currentInputType==="cnpj")&&(o=o.substring(0,14));let f=this.NgxMaskPipe.transform(o,this.mask),w=o.substring(0,14);w.length>=3&&this.searchClickTelevendas.emit(new F("keyup",w,i))}else t.length>=3&&this.searchClickTelevendas.emit(new F("keyup",t,i))}}}handleSearchClick(i){i.stopPropagation();let e=this.formGroup.get("cliente")?.value;if(e&&e.length>=3){let t=new F("click",e,i);this.searchClickTelevendas.emit(t)}}selectedItem(i){i&&(this.itemSelected.emit(i),this.resetFormCliente())}selectedFilialItem(i){this.selectedFilial.emit(i),i.text==="(Selecione)"&&this.resetFormCliente()}resetFormCliente(){this.searchInput&&this.searchInput.clear(),this._clientesTelevenda=null}handleUserKeyUp(i){if(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"].includes(i.key)||!this.searchInput?.input?.nativeElement)return;let t=this.searchInput.input.nativeElement,n=t.value||"";if(!n.trim())return;let o=t.selectionStart??0;if((t.selectionEnd??0)-o>0)return;if(/^[a-zA-Z]/.test(n))this.currentInputType="email",this.mask="",t.value=n;else{let G=n.replace(/\D+/g,""),U=G.length,M;U<=11?U>=10&&G.charAt(2)==="9"?(this.currentInputType="celular",M=11):(this.currentInputType="cpf",M=11):U<=14?(this.currentInputType="cnpj",M=14):(this.currentInputType="celular",M=11),this.mask=this.masks[this.currentInputType];let Q=G.slice(0,M);t.value=this.mask?this.NgxMaskPipe.transform(Q,this.mask):Q}let w=t.value.length;t.setSelectionRange(w,w);let Me=this.currentInputType==="email"?t.value:t.value.replace(/\D+/g,"");this.searchTerms.next(Me)}isValidCPF(i){if(i=i.replace(/[^\d]+/g,""),i.length!==11||/^(\d)\1+$/.test(i))return!1;let e=0,t;for(let n=1;n<=9;n++)e+=parseInt(i.substring(n-1,n))*(11-n);if(t=e*10%11,(t===10||t===11)&&(t=0),t!==parseInt(i.substring(9,10)))return!1;e=0;for(let n=1;n<=10;n++)e+=parseInt(i.substring(n-1,n))*(12-n);return t=e*10%11,(t===10||t===11)&&(t=0),t===parseInt(i.substring(10,11))}static{this.\u0275fac=function(e){return new(e||K)(E(I),E(j))}}static{this.\u0275cmp=T({type:K,selectors:[["vip-selecionar-cliente-televendas"]],viewQuery:function(e,t){if(e&1&&ee(A,5),e&2){let n;te(n=ie())&&(t.searchInput=n.first)}},inputs:{isDesktopResponsive:"isDesktopResponsive",filiaisTelevendas:"filiaisTelevendas",clientesTelevenda:"clientesTelevenda",loadingTelevendas:"loadingTelevendas",isTelevendas:"isTelevendas"},outputs:{openDesktopCepModal:"openDesktopCepModal",searchClickTelevendas:"searchClickTelevendas",itemSelected:"itemSelected",selectedFilial:"selectedFilial"},standalone:!1,features:[R],decls:12,vars:11,consts:[["vipSearch",""],[1,"font-medium","mb-3","vip-color-first-default","text-base"],[3,"formGroup"],[1,"mt-4"],["data-cy","select-cliente","id","clientSelect","label","Filial","formControlName","filial",1,"text-left",3,"itemSelected","options","isDesktop"],["data-cy","vip_search","placeholder","Pesquise por Nome/CPF/CNPJ/Celular/E-mail","typeInput","retangle","name","cliente",1,"w-full","mt-2",3,"search","keyup","focusOnInit","disabled","isTelevendas"],[4,"ngIf"],[1,"mb-3"],[3,"itemSelected","openModalCep","isDeskTopResponsive","resetForm","items","searchValue","loadingTelevendas"],[1,"mt-1","mb-1"]],template:function(e,t){if(e&1){let n=y();l(0,"div")(1,"h3",1),u(2," Selecionar cliente para compra "),r(),g(3),l(4,"form",2)(5,"div",3)(6,"vip-select",4),h("itemSelected",function(f){return p(n),m(t.selectedFilialItem(f))}),r(),l(7,"vip-search",5,0),h("search",function(f){return p(n),m(t.handleSearchEvent(f))})("keyup",function(f){return p(n),m(t.handleUserKeyUp(f))}),r(),b(9,Oe,4,0,"ng-container",6),r()(),N(10,"hr",7),l(11,"vip-list-select",8),h("itemSelected",function(f){return p(n),m(t.selectedItem(f))})("openModalCep",function(){return p(n),m(t.openModalCep())})("isDeskTopResponsive",function(){return p(n),m(t.isDesktopResponsiveRef)})("resetForm",function(){return p(n),m(t.resetFormCliente())}),r(),_(),r()}if(e&2){let n;a(4),c("formGroup",t.formGroup),a(2),c("options",t.filiais)("isDesktop",!0),a(),c("focusOnInit",!1)("disabled",!((n=t.formGroup.get("filial"))!=null&&n.value))("isTelevendas",t.isTelevendas),a(2),c("ngIf",(t.searchInput==null||t.searchInput.input==null||t.searchInput.input.nativeElement.value==null?null:t.searchInput.input.nativeElement.value.length)<3&&(t.searchInput==null||t.searchInput.input==null||t.searchInput.input.nativeElement.value==null?null:t.searchInput.input.nativeElement.value.length)>0),a(2),c("items",t._clientesTelevenda||re(10,Le))("searchValue",t.searchInput==null||t.searchInput.input==null?null:t.searchInput.input.nativeElement.value)("loadingTelevendas",t.loadingTelevendas)}},dependencies:[L,be,H,A,fe,me,ue,he,ve],encapsulation:2,changeDetection:0})}};ke=z([ce(),J("design:paramtypes",[I,j])],ke);var we=(()=>{class s{static{this.\u0275fac=function(t){return new(t||s)}}static{this.\u0275mod=S({type:s})}static{this.\u0275inj=C({imports:[k,Te]})}}return s})();var wt=(()=>{class s{static{this.\u0275fac=function(t){return new(t||s)}}static{this.\u0275mod=S({type:s})}static{this.\u0275inj=C({imports:[k,ye,we,Se,ge,_e]})}}return s})();var Ft=(()=>{class s{constructor(){this.number="00",this.isHeader=!1,this.position="center"}get classes(){return[`vip-badge vip-badge-top vip-badge-${this.position}`]}get formattedNumber(){let e=this.number?this.number:"00";return e=e.length<2?`0${e}`:e,e||"00"}static{this.\u0275fac=function(t){return new(t||s)}}static{this.\u0275cmp=T({type:s,selectors:[["vip-badge"]],inputs:{number:"number",isHeader:"isHeader",position:"position"},standalone:!1,decls:2,vars:4,consts:[[1,"items-center","text-tiny","font-bold",3,"ngClass"]],template:function(t,n){t&1&&(l(0,"span",0),u(1),r()),t&2&&(X("is-header",n.isHeader),c("ngClass",n.classes),a(),x(" ",n.formattedNumber,""))},dependencies:[P],styles:[`.vip-badge[_ngcontent-%COMP%]{position:absolute;display:inline-block;padding:.125rem .25rem;border-radius:3px;line-height:.5625rem}.vip-badge[_ngcontent-%COMP%]{color:var(--vip-component-badge-color-contrast);background-color:var(--vip-component-badge-color-background)}.is-header[_ngcontent-%COMP%]{color:var(--vip-component-header-desktop-color-badge_text, var(--vip-component-badge-color-contrast));background-color:var(--vip-component-header-desktop-color-badge_background, var(--vip-component-badge-color-background))}.vip-badge-top[_ngcontent-%COMP%]{top:-.3125rem}.vip-badge-end[_ngcontent-%COMP%]{right:-.625rem}.vip-badge-before[_ngcontent-%COMP%]{left:-.625rem}.vip-badge-center[_ngcontent-%COMP%]{left:50%;transform:translate(-50%)} /*# sourceMappingURL=badge.component-2BM32YZ7.css.map */`]})}}return s})();var Lt=(()=>{class s{static{this.\u0275fac=function(t){return new(t||s)}}static{this.\u0275mod=S({type:s})}static{this.\u0275inj=C({imports:[k]})}}return s})();export{ke as a,wt as b,Ft as c,Lt as d}; //# sourceMappingURL=chunk-2GNYMNFM.js.map