import{M as k,u as L,Q as v,d as g,a as S,j as e,G as m,N as I,l as j,L as b,O as T,T as N,U as P,V as D,n as M,w as F,W as w,X as A,Y as $,Z as E,_ as O,b as C,$ as R,a0 as W}from"../index.Crez7j-Y.bundle.js";import{E as _}from"./EmptyContent.BRQ9JwMr.bundle.js";import{B as U}from"./Breadcrumbs.DEki5OLn.bundle.js";const B=(u,r)=>{const{getCategorySummaryAPI:h}=k();return L({queryKey:v.categorySummary(u),queryFn:()=>h(u),enabled:u!==0&&!isNaN(u),...r})},G=()=>{const u=g.useCallback((o,d)=>{let l=null,a=null;function s(t,i){for(const c of t){if(c.categoryNo===d){l=c,a=i;return}if(c.children&&c.children.length>0&&s(c.children,c),l)return}}return s(o,null),l?a===null?o.filter(t=>t.categoryNo!==d).map(t=>({categoryNo:t.categoryNo,depth:t.depth,label:t.label})):a.children.filter(t=>t.categoryNo!==d):[]},[]),r=g.useCallback((o,d)=>{const l=[],a=(s,t)=>{if(t.push({depth:s.depth,label:s.label,categoryNo:s.categoryNo}),s.categoryNo===d)return l.push(...t),!0;for(const i of s.children)if(a(i,t))return!0;return t.pop(),!1};for(const s of o.multiLevelCategories)if(a(s,[]))break;return l},[]),h=g.useCallback((o,d)=>{let l=null,a=[];const s=t=>{for(const i of t){if(i.categoryNo===d)return l=i,a=i.childCategories,!0;if(s(i.childCategories))return!0}return!1};return s(o),{currentCategory:l,childrenCategoryList:a}},[]);return{getSiblingCategory:u,findCategoryPath:r,findCurrentAndSubCategoryList:h}};function Q(u){const{allCategoryListData:r,categorySummaryData:h,categoryNos:o}=u,{findCategoryPath:d,findCurrentAndSubCategoryList:l,getSiblingCategory:a}=G(),s=g.useMemo(()=>!r||o===null?[]:d(r,Number(o)),[r,o]),{currentCategory:t,childrenCategoryList:i}=g.useMemo(()=>!h||o===null?{currentCategory:null,childrenCategoryList:[]}:l(h.multiLevelCategories,Number(o)),[h,o]),{isDesktop:c,isMobile:x}=S();return e.jsxs(e.Fragment,{children:[c&&e.jsxs(e.Fragment,{children:[e.jsx(m,{desktop:12,children:e.jsx(I,{spacing:2,children:e.jsxs(U,{separator:e.jsx(j,{fontSize:"small"}),children:[e.jsx(b,{underline:"hover",color:"black",href:"/",variant:"body",display:"block",children:"HOME"}),r&&s.map(n=>e.jsx(T,{category:n,groupedCategory:a(r.multiLevelCategories,n.categoryNo)},n.categoryNo))]})})}),e.jsx(m,{desktop:12,my:3,children:e.jsx(N,{component:"em",variant:"titleLarge",children:t==null?void 0:t.label})})]}),x&&e.jsx(m,{mobile:12,mx:2,py:1,children:s.map((n,p,f)=>e.jsxs(b,{href:"".concat(P.PRODUCT_LIST,"?categoryNos=").concat(n.categoryNo),variant:"subtitle1",underline:"none",sx:{display:"inline-flex",alignItems:"center",fontWeight:400},children:[n.label,p!==f.length-1&&e.jsx(j,{fontSize:"small"})]},n.categoryNo))}),i&&i.length>0&&e.jsx(m,{desktop:12,mobile:12,component:"nav",children:e.jsx(D,{sx:{display:"flex",flexWrap:"wrap",alignItems:"center",justifyTracks:"start",bgcolor:M,px:3,py:2},children:i.map(n=>e.jsx(F,{sx:{width:"auto",mr:2},disablePadding:!0,children:e.jsxs(b,{variant:c?"subtitle1":"body",underline:"none",fontWeight:400,href:"".concat(P.PRODUCT_LIST,"?categoryNos=").concat(n.categoryNo),children:["".concat(n.label,"("),e.jsx(N,{variant:c?"subtitle2":"subtitle1",px:1,component:"span",children:n.count}),")"]})},n.categoryNo))})})]})}function K(){const[u]=w(),{data:r,isPending:h}=A(u),[o,d]=g.useState(!1),l=g.useCallback((n,p)=>{const f=n.productManagementCd.trim(),y=p.productManagementCd.trim();return f===""&&y===""?0:f===""?1:y===""?-1:f.localeCompare(y)},[]),a=g.useMemo(()=>r?o?[...r.items].sort(l):r.items:[],[r,o]),s=u.get("categoryNos"),t=s?Number(s):null,{data:i}=$(),{data:c}=B(Number(t)),{isDesktop:x}=S();return e.jsxs(E,{children:[e.jsx(m,{item:!0,desktop:12,mobile:12,component:"section",children:e.jsx(Q,{allCategoryListData:i,categorySummaryData:c,categoryNos:t})}),e.jsx(m,{item:!0,desktop:12,mobile:12,component:"section",children:e.jsx(O,{itemTotalCount:(r==null?void 0:r.totalCount)||0,setShouldOrderSpec:d})}),e.jsxs(m,{item:!0,desktop:12,mobile:12,component:"section",container:!0,sx:{px:2},children:[r&&r.totalCount==0&&e.jsx(_,{text:"판매중인 제품이 없습니다."}),e.jsxs(m,{container:!0,spacing:3,children:[h&&Array.from({length:10}).map((n,p)=>e.jsxs(m,{item:!0,desktop:2.4,mobile:6,children:[e.jsx(C,{variant:"rectangular",width:"100%",height:x?"300px":"150px"}),e.jsx(C,{variant:"text",width:"100%",height:"30px"}),e.jsx(C,{variant:"text",width:"100%",height:"30px"})]},p)),a&&a.map(n=>e.jsx(m,{item:!0,desktop:2.4,mobile:6,children:e.jsx(R,{product:n})},n.productNo))]}),e.jsx(W,{itemTotalCount:r==null?void 0:r.totalCount})]})]})}export{K as default};