1import{j as e,u as ee}from"./index-D2hihgzr.js";import{u as te,r as i,L as E}from"./react-vendor-CkReSM2q.js";import{s as se,g as ae,h as ne,j as re,N as ie,r as B,k as le,l as oe,m as ce,b as C,c as de,n as ue}from"./slug-BTAcLlnm.js";import{g as F,a as me}from"./myRoutes-pryEk3Sw.js";import{u as he}from"./useDocumentMeta-DupQMyuJ.js";function fe({href:l,variant:s="orange",ariaLabel:o="Connect with Strava"}){return e.jsxs("a",{href:l,className:`strava-connect strava-connect--${s}`,"aria-label":o,children:[e.jsx("span",{className:"strava-connect-mark","aria-hidden":"true",children:e.jsx("svg",{width:"22",height:"22",viewBox:"0 0 24 24",children:e.jsx("path",{fill:"currentColor",d:"M15.387 17.944l-2.089-4.116h-3.065L15.387 24l5.15-10.172h-3.066m-7.008-5.599l2.836 5.598h4.172L10.463 0l-7 13.828h4.169"})})}),e.jsx("span",{className:"strava-connect-text",children:"Connect with Strava"})]})}function Ne(){var L,$;const l=te(),{t:s}=ee(),[o,p]=i.useState([]),[r,y]=i.useState({connected:!1}),[G,J]=i.useState(!1),[c,I]=i.useState(null),[h,O]=i.useState(null),[b,x]=i.useState(null),[m,S]=i.useState(null),[N,T]=i.useState("routes"),[g,_]=i.useState(()=>ve()),[R,z]=i.useState(null),[w,M]=i.useState(!1),[k,D]=i.useState(null),[f,j]=i.useState({enabled:!1,busy:!1}),[d,A]=i.useState({busy:!1,results:null,error:null});i.useEffect(()=>{p(F())},[]),i.useEffect(()=>{let t=!0;return se().then(a=>{t&&(y(a),J(!0),a.connected&&(ae().then(n=>{t&&I(n)}).catch(n=>{t&&x(n.message)}),ne().then(n=>{if(!t)return;const u=n.filter(v=>/Ride/i.test(v.sport_type||v.type));O(u)}).catch(n=>{t&&x(n.message)}),re().then(n=>{t&&j({enabled:n.enabled,busy:!1})}).catch(()=>{})))}),()=>{t=!1}},[]);const H=t=>{me(t),p(F())},K=async()=>{if(!d.busy){A({busy:!0,results:null,error:null});try{const t=await le(3);A({busy:!1,results:t,error:null})}catch(t){A({busy:!1,results:null,error:(t==null?void 0:t.message)||"Backfill failed"})}}},Y=async()=>{if(!f.busy){j(t=>({...t,busy:!0}));try{f.enabled?(await oe(),j({enabled:!1,busy:!1})):(await ce(),j({enabled:!0,busy:!1}))}catch(t){x((t==null?void 0:t.message)||"Toggle failed"),j(a=>({...a,busy:!1}))}}},q=async t=>{if(!m){S(t.id);try{const{id:a}=await C(t.id_str||t.id);l(B(t.name,a))}catch(a){x((a==null?void 0:a.message)||s("routes.errorImport")),S(null)}}},Q=async t=>{if(!m){S(t.id);try{const{id:a}=await de(t.id);l(B(t.name,a))}catch(a){x((a==null?void 0:a.message)||s("routes.errorImportAct")),S(null)}}},U=async()=>{await ue(),y({connected:!1}),I(null)},V=async t=>{const a=String(t.id_str||t.id);if(!(R||g.has(a))){z(t.id);try{await C(a,{community:!0});const n=new Set(g);n.add(a),_(n),P(n)}catch(n){x((n==null?void 0:n.message)||"Error al compartir")}finally{z(null)}}},X=async()=>{if(!c||c.length===0||w)return;const t=c.filter(u=>!g.has(String(u.id_str||u.id)));if(t.length===0||!window.confirm(s("routes.shareBulkConfirm",{n:t.length})))return;M(!0),D({done:0,total:t.length});const a=new Set(g);let n=0;for(const u of t){const v=String(u.id_str||u.id);try{await C(v,{community:!0}),a.add(v),_(new Set(a)),P(a)}catch(Z){console.warn("bulk share failed for",v,Z)}n++,D({done:n,total:t.length})}M(!1),D(null)};return he({title:s("meta.routes.title"),description:s("meta.routes.desc")}),e.jsxs(e.Fragment,{children:[e.jsx(ie,{}),e.jsx("section",{className:"section",style:{paddingTop:56},children:e.jsxs("div",{className:"container",style:{maxWidth:920},children:[G?r.connected?e.jsxs("div",{className:"card panel",style:{marginBottom:28,borderColor:"#fed7aa",background:"linear-gradient(135deg, #fff7ed, #ffedd5)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,flexWrap:"wrap"},children:[((L=r.athlete)==null?void 0:L.profile)&&e.jsx("img",{src:r.athlete.profile,alt:"",style:{width:40,height:40,borderRadius:999,border:"2px solid #fc4c02"}}),e.jsxs("div",{style:{flex:1},children:[e.jsx("div",{style:{fontWeight:800,color:"var(--ink)"},children:s("routes.connectedTitle",{name:($=r.athlete)!=null&&$.firstname?` · ${r.athlete.firstname}`:""})}),e.jsx("div",{className:"muted",style:{fontSize:"0.85rem"},children:s("routes.connectedSub")}),e.jsxs("div",{className:"strava-attrib",style:{marginTop:6},children:[e.jsx("span",{className:"strava-attrib-mark",children:e.jsx("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"
1currentColor","aria-hidden":"true",children:e.jsx("path",{d:"M15.387 17.944l-2.089-4.116h-3.065L15.387 24l5.15-10.172h-3.066m-7.008-5.599l2.836 5.598h4.172L10.463 0l-7 13.828h4.169"})})}),"Powered by Strava"]})]}),e.jsx("button",{onClick:U,className:"btn btn-ghost",style:{fontSize:"0.85rem",padding:"8px 12px"},children:s("routes.disconnect")})]}),e.jsxs("div",{className:"autodesc-row",children:[e.jsxs("div",{className:"autodesc-text",children:[e.jsx("div",{className:"autodesc-title",children:s("routes.autoDesc.title")}),e.jsx("div",{className:"autodesc-sub",children:s("routes.autoDesc.sub")})]}),e.jsx("button",{type:"button",role:"switch","aria-checked":f.enabled,disabled:f.busy,onClick:Y,className:`switch${f.enabled?" on":""}${f.busy?" busy":""}`,"aria-label":s(f.enabled?"routes.autoDesc.disable":"routes.autoDesc.enable"),children:e.jsx("span",{className:"switch-thumb"})})]}),f.enabled&&e.jsxs("div",{className:"autodesc-backfill",children:[e.jsx("button",{type:"button",onClick:K,disabled:d.busy,className:"btn btn-ghost",style:{fontSize:"0.85rem"},children:d.busy?s("routes.autoDesc.backfilling"):s("routes.autoDesc.backfill")}),d.error&&e.jsx("div",{className:"autodesc-error",children:d.error}),d.results&&d.results.length===0&&e.jsx("div",{className:"autodesc-empty",children:s("routes.autoDesc.backfillEmpty")}),d.results&&d.results.length>0&&e.jsx("ul",{className:"autodesc-results",children:d.results.map(t=>e.jsxs("li",{className:t.ok?"ok":"skip",children:[e.jsx("span",{className:"autodesc-results-name",children:t.name}),t.ok&&t.link?e.jsx("a",{href:t.link,target:"_blank",rel:"noopener noreferrer",className:"autodesc-results-link",children:s("routes.autoDesc.viewAnalysis")}):e.jsx("span",{className:"autodesc-results-reason",children:t.reason||"â"})]},t.activityId))})]})]}):e.jsxs("div",{className:"card panel",style:{marginBottom:28,textAlign:"center",padding:32,background:"#fff"},children:[e.jsx("h3",{style:{fontSize:"1.1rem",marginBottom:8},children:s("routes.connectTitle")}),e.jsx("p",{className:"muted",style:{marginBottom:16,fontSize:"0.9rem"},children:s("routes.connectLead")}),e.jsx("div",{style:{display:"flex",justifyContent:"center"},children:e.jsx(fe,{href:"/api/strava/connect"})})]}):e.jsx("div",{className:"card panel",style:{marginBottom:28,padding:32,textAlign:"center",background:"#fff"},children:e.jsx("div",{className:"muted",style:{fontSize:"0.9rem"},children:s("routes.loadingStrava")})}),r.connected&&e.jsxs("div",{style:{marginBottom:36},children:[e.jsxs("div",{className:"tabs",style:{marginBottom:14},children:[e.jsxs("button",{onClick:()=>T("routes"),className:`tab${N==="routes"?" active":""}`,children:[s("routes.tabRoutes"),c&&e.jsx("span",{className:"tab-count",children:c.length})]}),e.jsxs("button",{onClick:()=>T("activities"),className:`tab${N==="activities"?" active":""}`,children:[s("routes.tabActivities"),h&&e.jsx("span",{className:"tab-count",children:h.length})]})]}),b&&e.jsx("div",{style:{padding:12,background:"#fef2f2",color:"#991b1b",borderRadius:8,fontSize:"0.88rem",marginBottom:12},children:b}),N==="routes"&&e.jsxs(e.Fragment,{children:[!c&&!b&&e.jsx("div",{className:"muted",style:{fontSize:"0.9rem"},children:s("routes.loadingRoutes")}),c&&c.length===0&&e.jsx("div",{className:"muted",style:{fontSize:"0.9rem"},children:s("routes.noRoutes")}),c&&c.length>0&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"share-bulk",children:[e.jsxs("div",{className:"share-bulk-text",children:[e.jsxs("strong",{children:["ð ",s("routes.shareBulkTitle")]}),e.jsx("span",{className:"muted",children:s("routes.shareBulkLead")})]}),e.jsx("button",{className:"btn btn-primary",style:{padding:"8px 14px",fontSize:"0.85rem",whiteSpace:"nowrap"},onClick:X,disabled:w||c.every(t=>g.has(String(t.id_str||t.id))),children:w&&k?s("routes.shareBulkProgress",{done:k.done,total:k.total}):c.every(t=>g.has(String(t.id_str||t.id)))?s("routes.shareBulkAllDone"):s("routes.shareBulkBtn")})]}),e.jsx("div",{className:"grid-routes",children:c.map(t=>{const a=String(t.id_str||t.id),n=g.has(a),u=R===t.id;return e.jsxs("div",{className:"card route-tile",style:{position:"relative",padding:0},children:[e.jsxs("button",{onClick:()=>q(t),disabled:m===t.id,style:{width:"100%",padding:"14px 16px 12px",textAlign:"left",cursor:m===t.id?"wait":"pointer",opacity:m===t.id?.6:1,background:"transparent",border:"none",font:"inherit"},children:[e.jsx("div",{className:"route-tile-name",children:t.name}),e.jsxs("div",{className:"route-tile-meta",children:[e.jsxs("span",{children:[e.jsx("strong",{children:(t.distance/1e3).toFixed(0)})," km"]}),t.elevation_gain>50&&e.jsxs("span",{children:["â ",e.jsx("strong",{children:Math.round(t.elevation_gain)})," m"]}),e.jsxs("span",{className:"muted",children:["· ",m===t.id?s("routes.importing"):s("routes.analyze")]})]})]}),e.jsx("button",{onClick:()=>V(t),disabled:n||u||w,className:`share-pill${n?" shared":""}`,title:s(n?"routes.shareDoneTitle":"routes.shareTitle"),children:u?"â¦":n?`â ${s("routes.shareDone")}`:`ð ${s("routes.shareBtn")}`})]},t.id)})})]})]}),N==="activities"&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"muted",style:{fontSize:"0.85rem",marginBottom:10},children:s("routes.activitiesLead")}),!h&&!b&&e.jsx("div",{className:"muted",style:{fontSize:"0.9rem"},children:s("routes.loadingActivities")}),h&&h.length===0&&e.jsx("div",{className:"muted",style:{fontSize:"0.9rem"},children:s("routes.noActivities")}),h&&h.length>0&&e.jsx("div",{className:"grid-routes",children:h.map(t=>e.jsxs("button",{onClick:()=>Q(t),disabled:m===t.id,className:"card route-tile",style:{textAlign:"left",cursor:m===t.id?"wait":"pointer",opacity:m===t.id?.6:1},children:[e.jsx("div",{className:"route-tile-name",children:t.name}),e.jsxs("div",{className:"route-tile-meta",children:[e.jsxs("span",{children:[e.jsx("strong",{children:(t.distance/1e3).toFixed(0)})," km"]}),t.total_elevation_gain>50&&e.jsxs("span",{children:["â ",e.jsx("strong",{children:Math.round(t.total_elevation_gain)})," m"]}),e.jsxs("span",{className:"muted",children:["· ",ge(t.start_date_local,s)]})]})]},t.id))})]})]}),e.jsx("h2",{style:{fontSize:"1.2rem",fontWeight:800,marginBottom:4},children:s("routes.localTitle")}),e.jsx("p",{className:"muted",style:{marginBottom:18,fontSize:"0.88rem"},children:s("routes.localLead")}),o.length===0?e.jsxs("div",{className:"card",style:{textAlign:"center",padding:36},children:[e.jsx("p",{style:{marginBottom:12},children:s("routes.empty")}),e.jsx(E,{to:"/",className:"btn btn-primary",style:{marginTop:4},children:s("routes.uploadGpx")})]}):e.jsx("div",{className:"grid-routes",children:o.map(t=>e.jsxs(E,{to:B(t.name,t.id),className:"card route-tile",children:[e.jsx("div",{className:"route-tile-name",children:t.name}),e.jsxs("div",{className:"route-tile-meta",children:[e.jsxs("span",{children:[e.jsx("strong",{children:t.km.toFixed(0)})," km"]}),t.elevGain>50&&e.jsxs("span",{children:["â ",e.jsx("strong",{children:Math.round(t.elevGain)})," m"]}),e.jsxs("span",{className:"muted",children:["· ",xe(t.visitedAt,s)]})]}),e.jsx("button",{className:"route-tile-remove",onClick:a=>{a.preventDefault(),a.stopPropagation(),H(t.id)},title:s("routes.removeTitle"),children:"Ã"})]},t.id))})]})})]})}function ge(l,s){if(!l)return"";const o=new Date(l);if(isNaN(o.getTime()))return"";const r=Math.floor((new Date().getTime()-o.getTime())/864e5);return r===0?s("time.today"):r===1?s("time.yesterday"):r<7?s("time.daysAgo",{n:r}):`${String(o.getDate()).padStart(2,"0")}/${String(o.getMonth()+1).padStart(2,"0")}`}function xe(l,s){const o=new Date(l).getTime(),p=Date.now(),r=Math.max(0,Math.round((p-o)/1e3));if(r<60)return s("time.justNow");if(r<3600)return s("time.minAgo",{n:Math.round(r/60)});if(r<86400)return s("time.hAgo",{n:Math.round(r/3600)});if(r<86400*7)return s("time.dAgo",{n:Math.round(r/86400)});const y=new Date(l);return`${String(y.getDate()).padStart(2,"0")}/${String(y.getMonth()+1).padStart(2,"0")}`}const W="mw.shared-strava-routes";function ve(){if(typeof window>"u")return new Set;try{const l=window.localStorage.getItem(W);if(!l)return new Set;const s=JSON.parse(l);return Array.isArray(s)?new Set(s.filter(o=>
1typeof o=="string")):new Set}catch{return new Set}}function P(l){if(!(typeof window>"u"))try{window.localStorage.setItem(W,JSON.stringify([...l]))}catch{}}export{Ne as default};
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.