var t,e,i,s,a=Object.defineProperty,r=(t,e,i)=>(((t,e,i)=>{e in t?a(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i})(t,"symbol"!=typeof e?e+"":e,i),i),n=(t,e,i)=>{if(!e.has(t))throw TypeError("Cannot "+i)},o=(t,e,i)=>(n(t,e,"read from private field"),i?i.call(t):e.get(t)),l=(t,e,i)=>{if(e.has(t))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(t):e.set(t,i)},h=(t,e,i,s)=>(n(t,e,"write to private field"),s?s.call(t,i):e.set(t,i),i);import{r as c,j as d}from"./react-B_SyE9nW.js";import{bs as p,bq as m,p as g,q as u,r as T,O as I,aX as L,bf as f,P as E,aZ as y,w as S,bt as v,aJ as b,bu as C,F as R,m as _,au as w,aQ as N,s as O,N as k,o as x,G as P,n as A,B as M,j}from"./index-Flm6m8Wj.js";import{R as B}from"./RatingReview-B-1D8CT5.js";import{S as V}from"./SubTitle-CrjAIwYk.js";import{T as Y}from"./index-C6Ujt1Uk.js";import{B as D}from"./BusinessIco-CeGzN8J_.js";import{G as F}from"./Grid-DM22V-x0.js";const U={NONE:"NONE",RANKING:"RANKING",ROUTE:"ROUTE",FAVORITES:"FAVORITES"},z="SELECT",G="ADD_LIST",$={END:"END",START:"START",POSITION:"POSITION"},W={TYPE_PRODUCT:"TYPE_PRODUCT",TYPE_BUSINESS:"TYPE_BUSINESS",TYPE_LIST:"TYPE_LIST"};function J(){return{name:"",description:"",type:W.TYPE_PRODUCT,visibility:!1,front_picture:"",note:"",order:0,position:$.POSITION}}const H={VISIBILITY_PUBLIC:"VISIBILITY_PUBLIC",VISIBILITY_PRIVATE:"VISIBILITY_PRIVATE",VISIBILITY_SHARED:"VISIBILITY_SHARED"};t=new WeakMap,e=new WeakMap,i=new WeakMap,s=new WeakMap;const K=c.createContext(new class extends p{constructor(){super(J),r(this,"element",{}),r(this,"listMap",new Map),r(this,"tabNav",z),r(this,"addListType",U.NONE),r(this,"cb"),r(this,"refresh",!1),r(this,"cropperStore",new m(1)),l(this,t,new Set),l(this,e,0),l(this,i,0),l(this,s,!0),r(this,"isLoading",!1),r(this,"setIsLoading",((t=!1)=>{this.isLoading=t})),r(this,"setCb",((t=void 0)=>{this.cb=t})),r(this,"setListMap",((t=new Map)=>{this.listMap=t})),r(this,"isSelected",(t=>{var e;return!!(null==(e=this.listMap.get(t))?void 0:e.selected)})),r(this,"setTabNav",((t=z)=>{this.tabNav=t})),r(this,"setAddListType",((t=U.NONE)=>{this.addListType=t})),r(this,"setElement",(t=>{this.element=t})),r(this,"ensureValidators",(()=>{const{name:t}=this.form;null==t||t.validators(f)})),r(this,"clearAddList",(()=>{this.setTabNav(),this.setAddListType()})),r(this,"resetPagination",(()=>{h(this,e,0),h(this,i,0),h(this,s,!0),h(this,t,new Set),this.setListMap()})),r(this,"loadList",(async()=>{E(!0),this.resetPagination();try{const{listType:e,item_identifier:i}=this.element,{success:s,data:a}=await y.getBookmarkListForItem(i,e);s&&(a.lists.forEach((({uuid:e})=>o(this,t).add(e))),await this.loadData(),S("MANAGE_LIST"))}catch(e){console.log("ERROR-loadBookmarkList: ",e)}finally{E()}})),r(this,"loadData",(async()=>{if(o(this,s)&&!this.isLoading){this.setIsLoading(!0);try{const{success:c,data:d,errors:p}=await y.getBookmarkLists(this.element.listType,{page:++(a=this,r=i,{set _(t){h(a,r,t,n)},get _(){return o(a,r,l)}})._,page_size:v});if(c){const i=new Map,{results:a,count:r}=d;a.forEach((({uuid:e,type:s,name:a,visibility:r,is_default_front_picture:n,front_picture:l,created_at:h,updated_at:c})=>{const d=o(this,t).has(e);i.set(e,{uuid:e,type:s,name:a,visibility:r===H.VISIBILITY_PUBLIC,is_default_front_picture:n,front_picture:l,selected:d,value:d,created_at:h,updated_at:c})}));const n=new Map([...this.listMap,...i]);h(this,e,r||n.size),h(this,s,n.size<o(this,e)),this.setListMap(n)}else console.log(`Errors: ${JSON.stringify(p,null,2)}`)}catch(c){console.log("ERROR: ",c)}finally{this.setIsLoading()}var a,r,n,l}})),r(this,"saveUpdateList",(async(t=!1)=>{E(!0),this.ensureValidators();const{hasError:e}=await this.form.validate;e?E():(await this[t?"updateList":"saveList"](),this.getCropperStore.setImgsToCrop([]))})),r(this,"saveList",(async()=>{try{const{item_identifier:t,listType:e,src:i}=this.element;this.form.type.onChange(e);const{note:s,visibility:a,...r}=this.form.values,n=await this.imageAsFile(i),{success:o,data:l,errors:h}=await y.addLists({...r,show_map:!this.isFavorites,show_rank:!this.isFavorites,visibility:a?H.VISIBILITY_PRIVATE:H.VISIBILITY_PUBLIC,front_picture:n});o?(await y.addListsElement(l.uuid,{note:s,type:e,item_identifier:t}),this.onCloseListForm(),await this.loadList(),this.refresh=!0):console.log(`ERROR: ${JSON.stringify(h,null,2)}`)}catch(t){console.log("ERROR: ",t)}finally{E()}})),r(this,"updateList",(async()=>{try{const{item_identifier:t,src:e}=this.element,{description:i,visibility:s,name:a}=this.form.values,r=await this.imageAsFile(e),{success:n,errors:o}=await y.updateList(t,{visibility:s?H.VISIBILITY_PRIVATE:H.VISIBILITY_PUBLIC,front_picture:r,description:i,name:a});n?(this.onCloseListForm(),this.refresh=!0,this.invokeCb(!0)):console.log(`ERROR: ${JSON.stringify(o,null,2)}`)}catch(t){console.log("ERROR: ",t)}finally{E()}})),r(this,"updateListElement",(async()=>{try{const{refUuid:t="",parentUuid:e="",count:i=1}=this.element,{note:s,order:a}=this.form.values;let r=a;switch(this.getPosition){case"START":r=1;break;case"END":r=i}const{success:n,errors:o}=await y.updateListElement(e,t,{note:s,order:r});n?(this.onCloseListForm(),this.refresh=!0,this.invokeCb(!0)):console.log(`ERROR: ${JSON.stringify(o,null,2)}`)}catch(t){console.log("ERROR: ",t)}finally{E()}})),r(this,"imageAsFile",(async t=>{const e=t.includes("data:image/jpeg;base64")?t:await b(t),i=await fetch(e),s=await i.blob(),a=`${C()}.jpeg`;return new File([s],a,{type:"image/jpeg"})})),r(this,"addElementToList",(async(t,e)=>{E(!0);try{const{item_identifier:i,listType:s}=this.element;await y.addElementToLists({add:t,remove:e,item_identifier:i,item_type:s}),await this.loadList(),this.refresh=!0,this.invokeCb()}catch(i){console.log("ERROR: ",i)}finally{E()}})),r(this,"invokeCb",((t=!1)=>{var e;null==(e=this.cb)||e.call(this,{is_bookmarked:Array.from(this.listMap.values()).some((({selected:t})=>t)),refresh:this.refresh,data:{...this.element,isEditing:t}}),S(),this.refresh=!1,this.setCb()})),r(this,"onEditList",(()=>{const{name:t,visibility:e,description:i}=this.element,{name:s,visibility:a,description:r}=this.form;s.onChange(t),a.onChange(e===H.VISIBILITY_PRIVATE),r.onChange(i||""),S("EDIT_LIST")})),r(this,"onEditListItem",(()=>{const{note:t,order:e=1}=this.element,{note:i,order:s}=this.form;i.onChange(t||""),s.onChange(e),S("EDIT_LIST_ELEMENT")})),r(this,"onClickBookmark",(async(t,e=!1,i=!1)=>{if(!e){let t;if(t=await R.isValidAction({modalOpen:"LOGIN_FORM"}),!t)return}t.main_picture=t.src,this.setElement(t),this.form.type.onChange(t.listType),e?i?this.onEditListItem():this.onEditList():await this.loadList()})),r(this,"onClickCreateList",(()=>{this.clearAddList(),_.setPrevious(_.current),S("CREATE_LIST")})),r(this,"onClickAddListOfType",((t=U.NONE)=>{this.setAddListType(t),this.setTabNav(G)})),r(this,"onClickAddList",(()=>this.saveUpdateList())),r(this,"onClickUpdateList",(()=>this.saveUpdateList(!0))),r(this,"onClickUpdateListElement",(()=>{E(!0),this.updateListElement()})),r(this,"onChangeListItemStatus",((t,e)=>{w((()=>{const i=this.listMap.get(t);i&&(i.selected=e)}))})),r(this,"onClickAddElementToLists",(()=>{const t=[],e=[];if(Array.from(this.getList).forEach((({uuid:i,value:s,selected:a})=>{s!==a&&(a?e.push(i):t.push(i))})),e.length||t.length)return this.addElementToList(e,t);this.invokeCb()})),r(this,"onCloseListForm",(()=>{S(),this.resetForm()})),r(this,"onCloseManageList",(async()=>{this.refresh&&await this.loadList(),this.invokeCb()})),r(this,"onHandleUploadClick",(t=>{N(t,this.cropperStore.addImgToCrop,void 0,1,this.cropperStore.clear)})),r(this,"onClickAcceptImage",(()=>{w((()=>{this.element.src=this.cropperStore.getImgsToCrop[0].croppedImage??this.cropperStore.getImgsToCrop[0].croppedImage}))})),r(this,"onPositionChange",((t,e)=>{this.form.position.onChange(e)})),g(this,{tabNav:u,addListType:u,element:u,listMap:u,isLoading:u,setTabNav:T,setAddListType:T,setElement:T,setListMap:T,setIsLoading:T,hasMore:I})}get getName(){return this.form.name}get getDescription(){return this.form.description}get getVisibility(){return this.form.visibility}get getNote(){return this.form.note}get getOrder(){return this.form.order}get getPosition(){return this.form.position.value}get isDisabledPosition(){return this.getPosition!==$.POSITION}get isListType(){return this.element.listType===W.TYPE_LIST}get getNotePlaceholder(){switch(this.element.listType){case"TYPE_PRODUCT":return"whatDoYouLikeProduct";case"TYPE_LIST":return"whatDoYouLikeList";case"TYPE_BUSINESS":return"whatDoYouLikeBusiness"}}get getSize(){return this.listMap.size}get hasMore(){return this.getSize<o(this,e)}get offset(){return this.getSize-L}get getCropperStore(){return this.cropperStore}get getList(){return Array.from(this.listMap.values())}get hasItems(){return!!this.getSize}get getTab(){return this.tabNav}get getAddListType(){return this.addListType}get isForm(){return this.addListType!==U.NONE}get getElement(){return this.element}get isFavorites(){return this.addListType===U.FAVORITES}}),q=O(k)`
  overflow-wrap: anywhere;
  white-space: pre-wrap;
`,Q={DESKTOP:338,TABLET:365,MOBILE:117};const X=x((function({size:t="micro",children:e,baseReadMore:i=Q,asTitle:s,...a}){const{needReadMore:r,base:n}=c.useMemo((()=>{const t=i[P.device];return{needReadMore:String(e).length>=t,base:t}}),[P.device,e]),[o,l]=c.useState(r);return c.useEffect((()=>{l(r)}),[r]),d.jsxs(q,{...a,size:t,color:s?"black":"gray50",weight:s?"bold":void 0,children:[o?`${String(e).substr(0,n)}...`:String(e),o?d.jsx(k,{color:"red",margin:"0 0 0 5px",size:"mini",style:{cursor:"pointer"},onClick:t=>{t.stopPropagation(),l(!1)},children:A("readMore")}):null]})}));const Z=x((function({title:t="",titleMargin:e="0 0 0 2px",subTitleMargin:i="5px 0 0 2px",titleSize:s="micro",subTitle:a="",titleStart:r,titleEnd:n,ratingCmp:o,ratingRightCmp:l,onClick:h,onClickSubTitle:c,onClickRating:p,sx:m,baseReadMore:g,titleVariant:u,subTitleVariant:T,mt:I,ml:L,mr:f,...E}){return d.jsxs(F,{container:!0,flexDirection:"column",margin:"0",width:"fit-content",flexWrap:"nowrap",display:"flex",height:"max-content",sx:m,children:[t?d.jsxs(M,{sx:{display:"flex","& p":{cursor:h?"pointer":void 0}},className:"enj-cnt-rating-review-title",children:[r,g?d.jsx(X,{margin:e,align:"start",asTitle:!0,size:s,baseReadMore:g,onClick:h,children:String(t)}):d.jsx(Y,{variant:u,text:String(t),margin:e,align:"start",size:s,onClick:h,dataTest:"enj-entity-name",sx:{userSelect:"text"}}),n]}):d.jsx(d.Fragment,{}),d.jsxs(M,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between"},className:"enj-rr-with-right",children:[o??d.jsx(B,{...E,onClick:p,mt:I,ml:L,mr:f}),l||d.jsx(d.Fragment,{})]}),a?d.jsxs(M,{display:"flex",alignItems:"center",margin:i,className:"enj-cnt-rating-sub-title",sx:{cursor:c?"pointer":void 0,"& .MuiSvgIcon-root":{mr:"5px",border:`1px solid ${j.grayMap}`,borderRadius:"50%",p:"3px",width:"20px",height:"20px"}},onClick:c,children:[d.jsx(D,{}),d.jsx(V,{variant:T,text:String(a),align:"start",margin:"0"})]}):d.jsx(d.Fragment,{})]})}));export{U as A,K as B,W as L,$ as P,Z as R,X as S,H as V};