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