1import{A as e,E as t,I as n,O as r,T as i,j as a}from"./chunk-KS7C4IRE-DIkipulk.js";import{t as o}from"./jsx-runtime-CsaOnxTR.js";import{l as s}from"./components-JSzoenoU.js";import{$i as c,$r as l,A as u,Aa as d,Ai as f,Ei as p,Fi as m,Ia as h,Ii as g,J as _,Jr as v,La as y,Li as b,Ma as x,Mn as S,Ra as C,Ui as w,Wi as T,Xi as E,Zr as D,_t as ee,da as te,dr as O,ea as k,gt as A,ht as j,ja as ne,ki as M,kn as N,mt as P,nn as re,pt as F,qi as I,sa as L,ur as R,yt as ie}from"./Elements-C-xYWSPQ.js";import{n as z,t as B}from"./ssr-CJ2n4bG3.js";import{t as V}from"./PageLayout-CMR1o20j.js";import{n as H}from"./MetaTags-BxzFdyK8.js";import{i as U,t as W}from"./StatusHandler-Bh1ghBjk.js";import{r as G,t as K}from"./adsHelper-DZxrkyG4.js";var q=n(a(),1),J=o();function ae({data:e,title:t,refCode:n,refClassName:r,showExpand:i=!0,className:a,testId:o=`keyword-summary-test-id`}){let{answer:s,docs:l}=e,[u,d]=(0,q.useState)(!1);if(!L(l)&&!L(s))return null;let f=e=>{if(L(e))return e.map(e=>{let t=l.findIndex(t=>t._id===e);return t===-1?``:`[${t+1}]`})};return(0,J.jsxs)(`div`,{className:h(`keyword-summary py-16`,a),"data-testid":o,children:[t&&(0,J.jsx)(T,{type:I.CONTAINER,size:E.XXSCURATOR,weight:c.FIFTY,className:`mb-16 text-primary`,children:t}),(0,J.jsxs)(`div`,{className:h(`relative flex flex-col`,i&&`max-h-120 overflow-hidden`,!u&&i&&`after:content-[''] after:absolute after:bottom-00 after:left-00 after:w-full after:h-85 after:bg-gradient-to-t after:from-white/80 after:to-black/0 after:z-10`,u&&`max-h-full after:hidden`),children:[L(s)&&(0,J.jsx)(`div`,{children:s.map((e,t)=>(0,J.jsxs)(w,{className:`mb-16`,testId:`keyword-summary-answer-test-id`,children:[e.text,` `,f(e.references)]},`keyword-summary-${t}`))}),L(l)&&(0,J.jsx)(`ol`,{className:h(`font-body-baseline-regular link-default list-decimal ml-24 mb-16`,r),children:l.map((e,t)=>(0,J.jsx)(`li`,{children:(0,J.jsx)(k,{url:`${e.link}?ref=${n||``}`,title:e.title,testId:`keyword-summary-link-test-id`,className:`font-body-baseline-regular link-default`})},`summary-ref-${t}`))})]}),i&&!u&&(0,J.jsx)(D,{fill:m.OUTLINE,size:g.SMALL,text:`Read more`,handler:()=>{d(!0)},className:`w-full mt-16 my-24`,testId:`keyword-summary-expand-button-test-id`}),(0,J.jsx)(M,{})]})}var oe=`Search on The Straits Times`,Y=[{value:`relevancydate`,label:`Relevance`},{value:`date`,label:`Newest`}],se=new Date(`2018-01-01`),X={apiError:{pageTitle:`Something went wrong`,title:`Something went wrong`,lead:[`Please refresh the page or try again later.`,`For urgent assistance, please contact our customer service team at 6388 3838 or drop us an email.`],buttonText:`Return to homepage`,to:`/`},clientSideError:{pageTitle:`Unexpected Error`,title:`Oops, something went wrong.`,lead:[`Try refreshing this page, updating your browser or contact us if the problem persists.`]},noInternet:{pageTitle:`No Internet Connection`,title:`No Internet Connection`,lead:[`Please check your connection and try again.`],buttonText:`Refresh`,to:`refresh`},noData:{pageTitle:`No results found`,title:`No results found`,lead:[`Please try with another keyword or filter.`],buttonText:`Retry`,to:`refresh`}};_.LISTING;function ce({authors:e,initialAdvancedSearch:t,callback:n}){let r=(0,q.useRef)(null),[i,a]=(0,q.useState)(!1),[o,c]=(0,q.useState)(t?.author||``),[l,u]=(0,q.useState)(t?.dateRange||void 0),f=`advanced search`,p=(0,q.useMemo)(()=>({title:`Advanced search`,modalHeightClass:`overflow-y-auto`,successButton:`Confirm`,cancelButton:`Cancel`,showSuccessButton:!0,showCancelButton:!0,cancelFill:m.OUTLINE,onClose:()=>{c(t?.author||``),u(t?.dateRange||void 0),a(!1)},onSuccessClick:()=>{n({author:o,dateRange:l}),a(!1),d({eventCategory:f,eventAction:`click`,eventLabel:`confirm`})},onCancelClick:()=>{c(t?.author||``),u(t?.dateRange||void 0),a(!1)},className:`advanced-search-modal bg-white absolute w-full h-full max-w-full max-h-full p-24 bg-white rounded-none desktop:left-1/2 desktop:top-1/2 desktop:-translate-x-1/2 desktop:-translate-y-1/2 desktop:w-auto desktop:h-auto desktop:max-w-570 desktop:max-h-auto desktop:rounded-xl z-1200`,testId:`advanced-search-modal-test-id`}),[n,o,l,t]);return(0,q.useEffect)(()=>(s&&(document.body.classList.toggle(`no-scrollbar`,i),document.body.classList.toggle(`!overflow-hidden`,i),document.body.classList.toggle(`hide-a
1ds-wrapper`,i)),()=>{s&&(document.body.classList.remove(`no-scrollbar`),document.body.classList.remove(`!overflow-hidden`),document.body.classList.remove(`hide-ads-wrapper`))}),[i]),(0,J.jsxs)(`div`,{"data-testid":`advanced-search-test-id`,children:[(0,J.jsx)(D,{text:`Advanced`,type:b.ICON_LEFT,fill:m.OUTLINE,size:g.SMALL,icon:{iconName:y.ACTION_FILTER,iconWidth:C.SMALL},handler:()=>{a(!0),d({eventCategory:f,eventAction:`click`,eventLabel:`advanced`})},className:`transition-all`,testId:`advanced-search-button-test-id`}),i&&(0,J.jsxs)(`div`,{className:`fixed w-screen h-dvh desktop:h-screen top-00 left-00 z-1200`,children:[(0,J.jsx)(`div`,{className:`absolute overlay-default w-full h-full top-00 left-00 hidden desktop:block`}),(0,J.jsx)(D,{type:b.ICON_ONLY,fill:m.NONE,icon:{iconName:y.NAV_CHEVRON_LEFT},handler:()=>{a(!1)},className:`absolute p-00 top-24 left-24 transition-all desktop:hidden z-1300`,testId:`advanced-search-back-button-test-id`}),(0,J.jsx)(N,{...p,children:(0,J.jsxs)(`form`,{ref:r,className:`advanced-search-form`,"data-testid":`advanced-search-form`,onSubmit:e=>{e.preventDefault()},children:[(0,J.jsx)(v,{name:`search-by-date`,label:`Search by date`,minDate:se,maxDate:new Date,className:`mb-24`,init:t?.dateRange||l,callback:u}),(0,J.jsx)(F,{name:`search-by-author`,placeholder:`Select author`,labelText:`Search by author`,options:e,disabled:!L(e),init:t?.author||o,callback:e=>{c(e||``)}})]})})]})]})}function le({initialSortBy:e,callback:t}){let n=(0,q.useRef)(Y.find(t=>t.value===e)||Y[0]),r=(0,q.useRef)(null),[i,a]=(0,q.useState)(!1),o={title:`Sort by`,modalHeightClass:`overflow-y-auto`,onClose:()=>{if(r.current){let e=new FormData(r.current).get(`search-sort-by`);if(e&&e!==n.current.value){let r=Y.find(t=>t.value===e);r&&(n.current=r,t?.(r.value))}}a(!1)},className:`absolute bg-white w-9/10 left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 z-30 tablet:max-w-548 desktop:max-w-570`,testId:`search-sort-by-modal-test-id`};return(0,J.jsxs)(`div`,{"data-testid":`search-sort-by-test-id`,children:[(0,J.jsx)(D,{text:n.current.label,type:b.ICON_LEFT,fill:m.OUTLINE,size:g.SMALL,icon:{iconName:y.ACTION_SORT,iconWidth:C.SMALL},handler:()=>{a(!0)},className:`transition-all`}),i&&(0,J.jsxs)(`div`,{className:`fixed w-full h-full top-00 left-00 z-1200`,children:[(0,J.jsx)(`div`,{className:`absolute overlay-default w-full h-full top-00 left-00`}),(0,J.jsx)(N,{...o,children:(0,J.jsx)(`form`,{ref:r,className:`search-sort-by-form`,"data-testid":`search-sort-by-form`,children:(0,J.jsx)(R,{id:`search-sort-by`,name:`search-sort-by`,orientation:`vertical`,init:n.current.value,items:Y,size:O.SMALL,handler:()=>{o.onClose()}})})})]})]})}function ue({authors:e,searchParams:t,setSetting:n}){let r=j(t?.daterange??``);return(0,J.jsxs)(`div`,{className:`flex flex-row gap-24 my-16 desktop:px-32`,"data-testid":`search-config-test-id`,children:[(0,J.jsx)(le,{initialSortBy:t?.sort,callback:e=>{if(!e)return;let i=r.startDate&&r.endDate?r:void 0;n?.({sortBy:e,dateRange:i,author:t?.facetedvalue})}}),(0,J.jsx)(ce,{initialAdvancedSearch:{dateRange:r.startDate&&r.endDate?{startDate:new Date(r.startDate),endDate:new Date(r.endDate)}:void 0,author:t?.facetedvalue},authors:e,callback:e=>{let{dateRange:t,author:r}=e,i=t?.startDate,a=t?.endDate,o=i instanceof Date?i.toString():typeof i==`string`?i:``,s=a instanceof Date?a.toString():typeof a==`string`?a:``;n?.({dateRange:o&&s?j(`${o},${s}`):void 0,author:r})}})]})}function de({handler:e,searchValue:t,className:n,testId:i=`search-input-test-id`}){let[a,o]=(0,q.useState)(``),c=r();(0,q.useEffect)(()=>{t&&o(t)},[t]);let l=t=>{t.key===`Enter`&&e(a)},u=e=>{o(e.target.value)},d=()=>{o(``),e(``)};return(0,J.jsxs)(`div`,{"data-testid":i,className:h(`search-input`,n),children:[(0,J.jsx)(D,{type:b.ICON_ONLY,size:g.DEFAULT,fill:m.NONE,testId:`search-submit-button-test-id`,icon:{iconName:y.NAV_CROSS,iconWidth:C.REGULAR,className:`icon-tertiary`},className:`p-00 desktop:hidden`,handler:()=>{a||t?d():s&&window.history.length>1?c(-1):c(`/`,{replace:!0})}}),(0,J.jsxs)(`div`,{className:`search-input-container`,children:[(0,J.jsx)(D,{type:b.ICON_ONLY,size:g.DEFAULT,fill:m.NONE,testId:`search-submit-button-test-id`,icon:{iconName:y.NAV_SEARCH,iconWidth:C.REGULAR,className:`icon-tertiary`},className:`p-00`,handler:()=>{e(a)}}),(0,J.jsx)(`input`,{"data-testid":`search-input-field-test-id`,placeholder:oe,value:a,onChange:u,onKeyDown:l,className:`font-secondary-label-lg-regular w-full focus:outline-0`}),a&&(0,J.jsx)(D,{type:b.ICON_ONLY,size:g.DEFAULT,fill:m.NONE,testId:`search-input-clear-button-test-id`,icon:{iconName:y.STATUS_ERROR_OUTLINED,iconWidth:C.SMALL,className:`icon-tertiary`},className:`p-00`,handler:d})]})]})}function Z({title:e=`Trending searches`,keywords:t,dividerClassName:n,setTrendingSearchKeyword:r,className:i,testId:a=`trending-keyword-test-id`}){return L(t)?(0,J.jsxs)(`div`,{className:h(`search-keyword`,i),"data-testid":a,children:[(0,J.jsx)(S,{title:e,className:`w-full px-00`,testId:`trending-keyword-header`,titleClassName:`text-primary pt-0 desktop:h-auto`,dividerClassName:h(`!border-neutral-50`,n)}),(0,J.jsx)(`div`,{className:`inline-flex flex-wrap gap-x-08 gap-y-16 my-08`,children:t.map((e,t)=>(0,J.jsx)(D,{type:b.TEXT_ONLY,fill:m.OUTLINE,size:g.SMALL,text:e,handler:()=>{let t=e.toLocaleLowerCase();t&&r?.(t)},textClassName:`whitespace-nowrap`,testId:`search-keyword-button-test-id`},t))})]}):null}function Q({total:e=0,endIndex:t=10,trendingKeyword:n=[],errorMessage:r,isLoading:i=!1,setSearchKeyword:a,loadM
1ore:o,dataset:s}){return L(s)&&(e===0&&(e=s.length),t<s.length&&(s=s.slice(0,t))),(0,J.jsxs)(`div`,{className:h(`flex flex-col pb-16`,!r||L(n)?`desktop:flex-row desktop:inline-grid desktop:grid-flow-row-dense desktop:gap-32 desktop:px-32`:`desktop:px-32`),children:[(0,J.jsx)(Z,{keywords:n,setTrendingSearchKeyword:a,dividerClassName:`desktop:hidden`,className:`w-full desktop:col-start-18 desktop:col-end-24`}),(0,J.jsx)($,{className:`w-full desktop:col-start-1 desktop:col-end-18`,title:`Latest Headlines`,refCode:`search-latest-headlines`,dataset:s,errorMessage:r,dividerClassName:`desktop:hidden`,testId:`search-latest-headlines-test-id`,children:t<e&&(0,J.jsx)(`div`,{className:`w-full text-center py-32 desktop:col-start-1 desktop:col-end-20`,children:(0,J.jsx)(D,{type:b.TEXT_ONLY,fill:m.OUTLINE,size:g.SMALL,text:`Load more`,handler:()=>o,testId:`load-more-test-id`,disabled:i})})})]})}function $({errorMessage:e,title:t,dividerClassName:n,dataset:r,refCode:i,children:a,className:o,testId:s=`search-list-layout-test-id`}){return(0,J.jsxs)(`div`,{className:h(`search-result-list`,o),"data-testid":s,children:[(0,J.jsx)(S,{title:t,type:f.STRONG,testId:`search-result-header`,className:`w-full px-00`,titleClassName:`text-primary pt-0 desktop:h-auto`,dividerClassName:h(`!border-neutral-50`,n)}),L(r)?(0,J.jsxs)(J.Fragment,{children:[r.map((e,t)=>(0,J.jsx)(J.Fragment,{children:(0,J.jsx)(u,{...e,refCode:i,className:`py-24 border-t border-default`})},`search-article-${t}`)),a]}):e&&(0,J.jsx)(U,{...e,title:e.title||X.noData?.title||`No results found`,lead:e.lead||X.noData?.lead})]})}function fe({errorMessage:e,searchParams:t,isLoading:n=!1,setSearchKeyword:r,loadMore:i,callback:a,dataset:o}){let{total:s,endindex:c}=o?.metadata||{total:0,endindex:0};return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(ue,{authors:o?.faceted?.creator||[],searchParams:t,setSetting:e=>{a?.(e)}}),o?.gpts?.[0]&&(0,J.jsx)(ae,{className:`desktop:px-32`,title:`Keyword summary`,data:o.gpts[0],refCode:`search-keyword-summary`}),L(o?.related)&&(0,J.jsx)(Z,{title:`Related searches`,keywords:o.related,setTrendingSearchKeyword:e=>r?.(e),className:`w-full desktop:px-32`,testId:`related-searches-test-id`}),(0,J.jsx)($,{className:`w-full desktop:px-32`,title:`Search results`,refCode:`search-results`,dataset:o?.items||[],errorMessage:e,testId:`search-results-test-id`,children:s!==10&&c<s&&(0,J.jsx)(`div`,{className:`w-full text-center py-32`,children:(0,J.jsx)(D,{type:b.TEXT_ONLY,fill:m.OUTLINE,size:g.SMALL,text:`Load more`,handler:()=>i?.(),testId:`load-more-test-id`,disabled:n})})})]})}var pe=!1,me=e(function(){let{pathname:e}=t(),n=G(re.DEFAULT,te(e)),r=L(n)?n[0]:void 0;pe||=(K(n),!0);let{searchkey:a,sort:o,author:c,daterange:u}=s&&window.location.search&&A(window.location.search)||{},[d,f]=(0,q.useState)(a||``),[m,h]=(0,q.useState)({query:a||``,endindex:0,sort:o||Y[0].value,facetedkey:c?`creator`:``,facetedvalue:c||``,daterange:u||``,timezoneoffset:ie().toString()}),[g,v]=(0,q.useState)(!1),[b,S]=(0,q.useState)(!1),[w,E]=(0,q.useState)(!0),[D,O]=(0,q.useState)(),[k,j]=(0,q.useState)(),[M,N]=(0,q.useState)(``);(0,q.useEffect)(()=>{if(!w&&m.endindex===0){let e=m.query&&d?ee({searchkey:m.query,sort:m.sort,author:m.facetedvalue,daterange:m.daterange,ref:M}):void 0;s&&e?window.location.replace(`${window.location.pathname}?${e}`):s&&window.location.replace(window.location.pathname)}},[m]),(0,q.useEffect)(()=>{v(!0),w&&P(m).then(e=>(v(!1),O(e),E(!1),L(e.items)||j(X.noData),e)).catch(e=>{console.error(`Error fetching search data:`,e),j(X.apiError),v(!1)})},[]);let F=()=>{D?.metadata.endindex&&(h(e=>({...e,endindex:(e.endindex??0)+10})),S(!0),P({...m,endindex:D.metadata.endindex}).then(e=>{S(!1),O(t=>t?{...t,items:[...t.items,...e.items],metadata:e.metadata,related:e.related,faceted:e.faceted,trending:e.trending}:e);let t=Math.floor((m.endindex??0)/10);ne(x.VIRTUAL_PV,{contenttype:_.LISTING,pagination:(t+1).toString()})}).catch(e=>{console.error(`Error fetching more search data:`,e),j(X.apiError),S(!1)}))},R=(e=``)=>{h(t=>({...t,query:e.toLocaleLowerCase(),endindex:0,sort:Y[0].value,facetedvalue:``,daterange:``}))},z=i();return z.type===B.CLIENT_ERROR||z.type===B.SERVER_ERROR?(0,J.jsx)(W,{response:z}):(0,J.jsx)(V,{lb1Ad:r,children:(0,J.jsxs)(`div`,{className:`search-page container`,children:[(0,J.jsx)(T,{type:I.DISPLAY_SEO,className:`absolute -left-[9999px]`,children:p.title}),(0,J.jsx)(`div`,{className:`flex desktop:grid`,children:(0,J.jsxs)(`div`,{className:`w-full col-span-full desktop:col-start-4 desktop:col-end-21 tablet:min-h-320`,children:[(0,J.jsx)(de,{searchValue:d,handler:e=>{f(String(e)),R(e)}}),!g&&(0,J.jsx)(J.Fragment,{children:d?(0,J.jsx)(fe,{errorMessage:k,searchParams:m,loadMore:F,isLoading:b||g,callback:e=>{h(t=>({...t,endindex:0,sort:e.sortBy||t.sort,facetedvalue:e.author?e.author:``,daterange:e.dateRange?[e.dateRange.startDate,e.dateRange.endDate].join(`,`):``}))},setSearchKeyword:e=>{f(e),R(e),N(`related-searches`)},dataset:D}):(0,J.jsx)(Q,{errorMessage:k,trendingKeyword:D?.trending,isLoading:b||g,setSearchKeyword:e=>{f(e),R(e),N(`trending-searches`)},dataset:D?.items})}),(g||b)&&(0,J.jsx)(`div`,{className:`flex justify-center items-center p-16`,children:(0,J.jsx)(l,{iconName:y.LOADER,className:`!icon-placeholder`,iconWidth:C.REGULAR})})]})})]})})}),he=e=>{let t=e.loaderData;if(t.type===B.SUCCESS){let e=t.payload.metaData;return H(e)}};async function ge(e){let t=await z(e);if(!t.context)return console.error(`Error occured during client-side routing for home, returning server Loader Data`),await e.serverLoader();let n=t.context;return(!n||typeof n!=`object`||!(`payload`in n)||typeof n.payload!=`object`)&&console.error(`Client Loader: fetchContext() returned an invali
1d payload for home`),n}export{ge as clientLoader,me as default,he as meta};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.