import{o as e}from"./chunk-mlkTr37E.js";import{t}from"./_plugin-vue2_normalizer-BHc2Ljhs.js";import{n}from"./api-DzB1tprs.js";import{i as r}from"./utils-BlhIOnbm.js";import{n as i}from"./category-CtKDHzno.js";import{t as a}from"./slugify-CO19mam7.js";var o=e(a()),s=t({name:`ShopeeCategoryTree`,data(){return{fullTreeData:[],displayedTreeData:[],searchText:``,checkedKeys:[],matchedKeys:[]}},methods:{buildTree(e,t){return e.map(e=>({title:e.display_name,slug:(0,o.default)(e.display_name,{lower:!0,trim:!0,locale:`vi`}),category_id:e.catid,key:e.catid,image:r(e.image),is_root:t,children:e.children?this.buildTree(e.children,!1):[]}))},searchTreeForHighlight(e,t,n=[]){return e.forEach(e=>{e.title.toLowerCase().includes(t.toLowerCase())&&n.push(e.category_id),e.children&&e.children.length&&this.searchTreeForHighlight(e.children,t,n)}),n},filterTree(e,t){let n=[];return e.forEach(e=>{let r=e.title.toLowerCase().includes(t.toLowerCase()),i=[];e.children&&e.children.length&&(i=this.filterTree(e.children,t)),r?n.push({...e,children:e.children}):i.length&&n.push({...e,children:i})}),n},onSearch(){let e=this.searchText.trim();e?(this.matchedKeys=this.searchTreeForHighlight(this.fullTreeData,e,[]),this.displayedTreeData=this.filterTree(this.fullTreeData,e)):(this.matchedKeys=[],this.displayedTreeData=this.fullTreeData)},renderContent(e,{data:t}){let{category_id:n,slug:r}=t,i=this.matchedKeys.includes(n),a=t.image,o=this.getRouterUrl(`/shopee/spy/category/${n}`),s=`https://shopee.vn/${r}-cat.${n}`,c=i?{color:`#f90`,fontWeight:`bold`}:{};return e(`div`,{style:{display:`flex`,alignItems:`center`}},[a&&e(`img`,{attrs:{src:a},style:{width:`24px`,height:`24px`,marginRight:`8px`,borderRadius:`4px`,objectFit:`cover`}}),e(`a`,{attrs:{href:s,target:`_blank`},style:{textDecoration:`none`,color:`#515a6e`,...c}},t.title),e(`a`,{attrs:{href:o,target:`_blank`},style:{marginLeft:`5px`}},this.$t(`SPY_BTN`))])}},created(){let e=i();this.fullTreeData=this.buildTree(e,!0),this.displayedTreeData=this.fullTreeData}},function(){var e=this,t=e._self._c;return t(`div`,[t(`Input`,{staticStyle:{"margin-bottom":`16px`},attrs:{placeholder:e.$t(`SEARCH_CATEOGRY_NAME`),clearable:``},on:{"on-change":e.onSearch},model:{value:e.searchText,callback:function(t){e.searchText=t},expression:`searchText`}}),t(`Tree`,{attrs:{data:e.displayedTreeData,"show-checkbox":!1,"highlight-current":!1,render:e.renderContent,"default-expand-all":!0,"checked-keys":e.checkedKeys},on:{"update:checkedKeys":function(t){e.checkedKeys=t},"update:checked-keys":function(t){e.checkedKeys=t}}})],1)},[],!1,null,`16311783`,null,null).exports,c=t({name:`ShopeeSpyMarket`,components:{"category-tree":s},created(){n()}},function(){var e=this._self._c;return e(`div`,[e(`Row`,[e(`Col`,{attrs:{span:12,offset:6}},[e(`category-tree`)],1)],1)],1)},[],!1,null,null,null,null).exports;export{c as default};