import{m as O,u as S,a as D,E as T,G as J}from"#entry";import{c as V}from"./index-BLWf41J8.mjs";import{u as I}from"./useStringUtils-B4L5WUsu.mjs";function H(){function f(l){return l==="results"?{labels:"label",type:"contentType",authors:"author",websiteSchedules:"websiteSchedule"}:{label:"labels",contentType:"type",author:"authors",websiteSchedule:"websiteSchedules"}}function z(){let l={};return S()?.query?.filters&&(l=JSON.parse(S().query.filters)),l}function x(l,e,h,o){const{$cmsUser:n}=D(),t={};e?.text&&(t.searchPhrase=e.text,t.textSearchFields=h),e?.statusText?.length&&(t.statusText={values:e?.statusText,operator:"or"}),e?.status?.length&&(t.status={values:e?.status,operator:"or"}),e?.tenant?.length&&(t.tenant={values:e?.tenant,operator:"or"}),e?.contentIds?.length&&(t.contentIds=e.contentIds);const d=f("search");if(["blueConicClient","bodyBlockTypes","company","contentFlags","contentGating","labels"].forEach(s=>{e?.[s]&&(t[s]={values:[e[s]],operator:"and"})}),["authors","primarySection","taxonomy","type"].forEach(s=>{const c=d?.[s]?d[s]:s;e?.[s]?.value?.length&&(t[c]={values:e[s].value,operator:e[s].andOr})}),!e?.type?.value?.length&&o?.length){const s=J.filter(c=>!o.includes(c.value)).map(c=>c.value);t.type={values:s,operator:"or"}}if(e?.websiteSchedule?.value?.length){const s=e.impliedSchedules?"websiteSchedulesImplied":"websiteSchedules";t[s]={values:e.websiteSchedule.value,operator:e.websiteSchedule.andOr}}if(e.dateSearch&&(e.dateSearch.startDate||e.dateSearch.endDate)&&(t[e.dateSearch.field]={},e.dateSearch.startDate&&(t[e.dateSearch.field].from=e.dateSearch.startDate),e.dateSearch.endDate&&(t[e.dateSearch.field].to=e.dateSearch.endDate)),l&&(t.published={to:l}),e?.myContent){const s=n.getUserInfo();t.userContent=s.username}return e?.magazineSchedule&&(t.magazineSchedules={},e?.magazineSchedule?.publication&&(t.magazineSchedules.publication=e?.magazineSchedule.publication.toString()),e?.magazineSchedule?.issue&&(t.magazineSchedules.issue=e?.magazineSchedule.issue.toString()),e?.magazineSchedule?.section&&(t.magazineSchedules.section=e?.magazineSchedule.section.toString()),e?.magazineSchedule?.mailDate&&(t.magazineSchedules.mailDate=e?.magazineSchedule.mailDate)),e?.newsletterSchedule&&(t.newsletterSchedules={},e?.newsletterSchedule?.template&&(t.newsletterSchedules.template=e?.newsletterSchedule.template.toString()),(e?.newsletterSchedule?.startDate||e?.newsletterSchedule?.endDate)&&(t.newsletterSchedules.deploymentDate={},e?.newsletterSchedule?.startDate&&(t.newsletterSchedules.deploymentDate.from=e.newsletterSchedule.startDate),e?.newsletterSchedule?.endDate&&(t.newsletterSchedules.deploymentDate.to=e.newsletterSchedule.endDate)),e?.newsletterSchedule?.unscheduled===!0&&(t.hasNewsletterSchedules="false")),t}function g(l){const e={};return Object.keys(l).forEach(o=>{const n=l[o];if(o==="statusText"||o==="tenant")e[o]=n;else if(typeof n=="object"&&"value"in n&&"andOr"in n)(n.value.length>0||Object.keys(n.value).length>0)&&(e[o]=n);else if(typeof n=="object"&&"value"in n&&l[o].value.length>0)e[o]=n;else if(typeof n=="object"){const t=g(n);Object.keys(t).length>0&&(e[o]=t)}else(n.length>0||n>0||n===!0)&&(e[o]=n)}),e}async function j(l,e,h,o,n,t,d,w){const{$gql:C}=D(),s=x(e,{...h},n==="public-search"?["name","teaser","body","author","companyName"]:["name","teaser","body","companyName"],w),c={sortField:t.split("_")[0],sortDirection:t.split("_")?.[1]??"desc",limit:parseInt(d),skip:parseInt((parseInt(o)-1)*parseInt(d)),...s},u=await C.query(n==="public-search"?"searchContent/searchContentPublic":n==="ids-only"?"searchContent/searchContentAdminIdsOnly":n==="admin-content-select"?"searchContent/searchContentAdminContentSelect":n==="admin-research"?"searchContent/searchContentAdminResearch":"searchContent/searchContentAdmin",c);u.error&&T.error(u.message);let m={facetOptions:{},results:{items:[],totalCount:[0]}};if(u.error)return T.error(u.message),m;{const N=f("results"),r={};u.data.meta?.facet&&Object.keys(u.data.meta?.facet).map(a=>{const q=u.data.meta.facet[a];r[N[a]??a]=q.buckets.map(i=>({value:i._id,label:i._id.split("|_|").slice(-1).pop(),count:h[a]?.andOr==="or"?null:i.count})).sort((i,G)=>i.label({...a,primarySection:a?.primarySection?{name:a.primarySection}:null,primaryImage:a?.primaryImage?{src:a.primaryImage}:""})),_=(r?.contentFlags??[]).map(a=>({...a,label:I.convertCamelCase(a.label)})),A=(r?.blueConicClient??[]).map(a=>({...a,label:I.convertCamelCase(a.label)})),E=(r?.bodyBlockTypes??[]).filter(a=>a.value!=="raw_html").map(a=>({...a,label:V[a.value].label}));m={facetOptions:{author:r?.author??[],bodyBlockTypes:E,company:r?.company??[],contentFlags:_,blueConicClient:A,contentGating:r?.contentGating??[],statusText:r?.statusText??[],contentType:r?.contentType??[],label:r?.label??[],primarySection:r?.primarySection??[],tenant:r?.tenant??[],websiteSchedule:r?.websiteSchedule??[]},results:{items:k,totalCount:u.data?.meta?.count?.lowerBound??0}}}return JSON.parse(JSON.stringify(m))}function b(){return O("contentSearchFilters",()=>({}))}function y(){return O("contentOptionsFilters",()=>({}))}return{search:j,getFiltersFromUrl:z,clearEmptyFilters:g,getContentSearchFilters:b,getContentOptionsFilters:y}}export{H as u};

AltStyle によって変換されたページ (->オリジナル) /