import{q as e,n as r}from"./vendor-react-DfNOgXDS.js";import{d as D}from"./vendor-dayjs-BrZ9gQN4.js";import{b$ as L,bb as F,P as O,bw as x,bE as A,Z as I,aj as h,q as _}from"./index-CRANE7wv.js";import{S as g}from"./skeleton-BLIekBlX.js";const Y="Shanghai",M="Москва",N="FILO20",y=6;function R(t){const a=t==null?void 0:t[0];return a!=null&&a.portFrom?a.portFrom.split(" ")[0]||a.portFrom:""}function U(t){var a;return t!=null&&t.length?((a=t[t.length-1])==null?void 0:a.portTo)??"":""}function k(t){return{id:t.id,routeLabel:R(t.segments),destination:U(t.segments),totalCost:t.totalCost??0}}function Z({cityFrom:t=Y,cityTo:a=M,size:l=N,onDetailsClick:j,onOrderClick:n,limit:i=y,title:m="Лучшие предложения по стоимости",className:b}){const[c,u]=e.useState([]),[f,d]=e.useState(!0),[C,p]=e.useState(!1);return e.useEffect(()=>{let s=!1;return d(!0),p(!1),L.calculateQuote({cityFrom:t,cityTo:a,time:D().format("DD.MM.YYYY"),size:l,pricingMode:"CONTAINER"}).then(o=>{if(s)return;const E=[...o].sort((S,T)=>(S.totalCost??0)-(T.totalCost??0));u(E.slice(0,i))}).catch(()=>{s||(u([]),p(!0))}).finally(()=>{s||d(!1)}),()=>{s=!0}},[t,a,l,i]),!f&&c.length===0?null:r.jsx(F,{py:"lg",bg:"surface",className:b,children:r.jsxs(O,{size:"base",children:[r.jsxs(x,{gap:6,children:[r.jsxs(x,{gap:2,className:"text-center max-w-2xl mx-auto",children:[r.jsx(A,{variant:"caption",children:"Популярный маршрут"}),r.jsx(I,{size:"sm",as:"h2",children:m})]}),f?r.jsx(h,{cols:3,gap:4,"aria-label":"Загрузка предложений",children:Array.from({length:3}).map((s,o)=>r.jsx(g,{className:"h-40 w-full"},o))}):r.jsx(h,{cols:3,gap:4,children:c.map(s=>r.jsx(_,{option:k(s),onDetailsClick:()=>j(s),onOrderClick:n?()=>n(s):void 0},s.id))})]}),C?r.jsx("span",{className:"sr-only",role:"status",children:"Не удалось загрузить предложения"}):null]})})}export{Z as B};