'use client';
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("@gem-sdk/core"),l=require("../../grid/components/ChildrenDroppable.js"),i=require("../../common/components/Loading.js"),a=require("react"),r=require("./ArticleNotFound.js");exports.default=s=>{let o=t.useEditorMode(),{styles:n,setting:d,className:c,children:g,builderProps:u,advanced:m,builderAttrs:p,style:h}=s??{},{articleSetting:y,numberOfArticle:b}=d??{},{articleIds:v,articlePickType:f}=y??{},{border:S,rounded:w,hasBoxShadow:A,boxShadow:D}=m??{},[T]=t.splitStyle(["pos","top","left","bottom","right","z","d"],h),x=t.composeAdvanceStyle({border:S,rounded:w,hasBoxShadow:A,boxShadow:D,"spacing-setting":m?.["spacing-setting"]}),j={first:v?.length||50,where:{baseIDIn:[...y?.articleIds??[]]},orderBy:{direction:"DESC",field:"PLATFORM_UPDATED_AT"}},k={first:1,where:{baseID:y?.blogId},orderBy:{direction:"DESC",field:"PLATFORM_UPDATED_AT"},articlesOrderBy:{direction:"DESC",field:"PLATFORM_UPDATED_AT"}},[B,P]=a.useState(!0),O=t.useBlogsQuery("latest"===f?k:null,{revalidateOnMount:!0}),E=t.useArticlesQuery("manually"===f?j:null,{revalidateOnMount:!0}),R=O.data?.blogs?.edges?.[0]?.node,C="manually"===f?E.isLoading:O.isLoading,I="manually"===f?E.isValidating:O.isValidating,_="manually"===f?E.error:O.error,G=O?.data?.blogs?.edges?.[0]?.node,L="latest"===f?t.flattenConnection(G?.articles):t.flattenConnection(E?.data?.articles),M=(e,t)=>({...e??{},blog:{title:t?.title??"",handle:t?.handle??""}}),q="latest"===f?L?.filter((e,t)=>t<+(b||4)).map(e=>M(e,G)):"manually"===f&&y?.articleIds?.length?v?.map(e=>{let t=L?.find(t=>t?.baseID===e);return M(t,t?.blogs?.edges?.[0]?.node)}).filter(Boolean):L.filter((e,t)=>t<(y?.numOfSelectedArticles||4)).map(e=>M(e,e?.blogs?.edges?.[0]?.node));return q?.length||C||"edit"!=o?e.jsxs("div",{...p,className:u?.builderData?.uid,style:T,children:[I||C?e.jsx(i.default,{}):_?e.jsxs("div",{children:["Error: ",_?.message]}):q?.length?e.jsx(t.ArticleListProvider,{styles:{horizontalGutter:n?.horizontalGutter,verticalGutter:n?.verticalGutter,spacing:n?.spacing,width:n?.width,height:n?.height},settings:{slidesToShow:d?.slideToShow??{desktop:4,tablet:3,mobile:1}},articles:q,children:e.jsx("div",{"data-id":u?.uid,className:"gp-relative",children:e.jsx("div",{style:{...x,...t.makeStyleWithDefault("w",t.makeWidth(n?.width),{desktop:"--g-ct-w",tablet:"--g-ct-w",mobile:"--g-ct-w"}),...t.makeStyleResponsive("rg",n?.horizontalGutter),...t.makeStyleResponsive("cg",n?.verticalGutter),...t.getStyleBackgroundByDevice(d?.background),...t.getGradientBgrStyleByDevice(d?.background),...t.makeStyleResponsive("gtc",{desktop:`repeat(${t.getResponsiveValueByScreen(d?.slideToShow,"desktop")}, minmax(0, 1fr))`,tablet:d?.slideToShow?.tablet&&`repeat(${t.getResponsiveValueByScreen(d?.slideToShow,"tablet")}, minmax(0, 1fr))`,mobile:d?.slideToShow?.mobile&&`repeat(${t.getResponsiveValueByScreen(d?.slideToShow,"mobile")}, minmax(0, 1fr))`})},className:t.cls(c,"gp-m-auto gp-grid gp-w-full"),children:q.map(i=>e.jsx(t.ArticleProvider,{article:i,readOnly:!0,children:e.jsx("div",{"data-component-type":"component","data-component-tag":"Article","data-component-label":"Article","data-component-no-setting":!0,"data-article-id":i?.baseID?.replace("gid://shopify/OnlineStoreArticle/",""),children:t.isEmptyChildren(g)?e.jsx(l.default,{}):g})},i?.id))})})}):e.jsx("div",{children:"Articles not found"}),t.filterToolbarPreview(g,!0)]}):B?e.jsxs("div",{...p,className:u?.builderData?.uid,children:[e.jsx(r.default,{blogHandle:R?.handle,onClose:()=>P(!1),articlePickType:f??"manually",children:g}),t.filterToolbarPreview(g,!0)]}):null};
