1import{a as G}from"./chunk-7E6LAB4A.js";import{a as L,b as U}from"./chunk-EBENRLIP.js";import{a as h,b}from"./chunk-JT3FPE5R.js";import{b as P}from"./chunk-BKU42KDU.js";import{b as _}from"./chunk-JZ6FKLPZ.js";import{h as I}from"./chunk-426NRUZS.js";import{Dg as O,Kg as i}from"./chunk-DHTXLVSB.js";import{f as R,k as S}from"./chunk-2S7KTGXH.js";import{l as v}from"./chunk-45YFRGQL.js";import{a as N,i as f}from"./chunk-JILVGSAM.js";var y={ManualUpload:"manual_upload",ServiceSync:"service_sync"};function p(e){return typeof e=="string"&&e.trim().length>0?e.trim():null}function F(e){if(!e?.sourceSummary||typeof e.sourceSummary!="object"||Array.isArray(e.sourceSummary))return null;let n=e.sourceSummary;return p(n.sourceType)?n:null}function H(e){return Array.isArray(e?.deliverySummaries)?e.deliverySummaries.filter(n=>!!n&&typeof n=="object"&&!Array.isArray(n)).filter(n=>p(n.serviceName)!==null):[]}function w(e){return Array.isArray(e?.syncedDestinationServiceNames)?e.syncedDestinationServiceNames.map(n=>p(n)).filter(n=>n!==null):[]}function M(e){switch(e){case i.SuuntoApp:case i.GarminAPI:case i.COROSAPI:case i.WahooAPI:return e;default:return null}}function Y(e){return _(e,"source")}function Se(e){return X(e).label}function X(e){let n=F(e);if(!n)return{label:"Saved route",serviceName:null,presentation:null};if(n.sourceType===y.ServiceSync&&n.sourceServiceName){let r=M(n.sourceServiceName),t=L(r);return{label:`Synced from ${t?.displayLabel||Y(n.sourceServiceName)}`,serviceName:r,presentation:t}}return n.sourceType===y.ManualUpload?{label:"Manual upload",serviceName:null,presentation:null}:{label:"Saved route",serviceName:null,presentation:null}}function me(e){return q(e).map(n=>n.label)}function q(e){return Array.from(new Set(w(e))).map(n=>{let r=M(n),t=U(r);return{label:`Sent to ${t?.displayLabel||_(n,"destination")}`,serviceName:r,presentation:t}})}function x(e,n){return H(e).find(r=>p(r.serviceName)===n)||null}function K(e,n){let r=x(e,n),t=p(r?.latestProviderUserId);return t||(Array.isArray(r?.providerUserIds)?r.providerUserIds.map(s=>p(s)).filter(s=>s!==null):[])[0]||null}function J(e,n){let r=p(n);return r?x(e,r)!==null||w(e).includes(r):!1}function ge(e){return J(e,i.SuuntoApp)?"Send updated copy to Suunto":"Suunto"}function Z(e,n){return e.providerStates.find(r=>r.providerUserId===n)||null}function ee(e,n){let r=K(e,i.GarminAPI);if(!r)return null;let t=Z(n,r);return t?t.permissionsLoaded?t.missingPermissions.includes("COURSE_IMPORT")?"Grant Garmin Course Import permission for the Garmin account previously used for this route, then reconnect before sending routes.":null:"Checking Garmin permissions for the Garmin account previously used for this route.":"Reconnect the Garmin account previously used for this route before sending it again."}function Re(e){return e?/course import/i.test(e)?"Garmin (Course Import required)":/checking garmin permissions/i.test(e)?"Garmin (checking permissions)":/previously used for this route/i.test(e)?"Garmin (reconnect original account)":"Garmin":"Garmin"}function Ee(e,n){return!n.connected||n.reconnectRequired||ee(e,n)?!1:n.missingPermissions.length===0}function Ae(e,n){let r=F(e);if(r?.sourceServiceName!==i.SuuntoApp)return!0;let t=p(r.providerUserId);return t?n.map(o=>p(o)).some(o=>o!==null&&o!==t):!1}var De=(()=>{class e{routeHydrationService=S(h);getRouteFileAsGPXBlob(r){return f(this,null,function*(){let t=new O,o=yield t.getAsString(r);return new Blob([o],{type:t.fileType})})}getRouteDocumentAsGPXBlob(o){return f(this,arguments,function*(r,t={}){let s=yield this.routeHydrationService.hydrateRouteFile(r,t);return{blob:yield this.getRouteFileAsGPXBlob(s.routeFile),hydratedRoute:s}})}static \u0275fac=function(t){return new(t||e)};static \u0275prov=R({token:e,factory:e.\u0275fac,providedIn:"root"})}return e})();var c=class extends Error{code;cause;constructor(n,r,t){super(r),this.code=n,this.cause=t,this.name="RouteReprocessError"}};function Fe(e){switch(e){case"validating":return"Validating route source...";case"downloading":return"Downloading route source...";case"parsing":return"Parsing route...";case"regenerating_stats":return"Generating route statistics...";case"persisting":return"Saving route...";case"done":return"Done";default:return"Processing route..."}}function we(e){if(e instanceof c){if(e.code==="NO_ORIGINAL_FILES")return"No original route file found.";if(e.code==="PERSIST_FAILED")return"Could not load the updated route after reprocessing.";if(e.code==="PARSE_FAILED")return"Could not parse the original route source file.";
1if(e.code==="ACCOUNT_DELETING")return"Account deletion is in progress. Route reprocess is unavailable.";if(e.code==="SERVICE_UNAVAILABLE")return"Route reprocess service is temporarily unavailable. Please try again shortly."}return"Could not reprocess route from source file."}var Me=(()=>{class e{routeService=S(P);routeHydrationService=S(h);functionsService=S(I);reprocessRouteDocumentFromOriginalFile(r,t,o){return f(this,null,function*(){let s=yield this.reprocessRouteFunctionAndRefreshDocument(r,t,o);return this.notifyProgress(o,{phase:"done",progress:100,details:"Done"}),s})}reprocessRouteFromOriginalFile(r,t,o){return f(this,null,function*(){let s=yield this.reprocessRouteFunctionAndRefreshDocument(r,t,o),u=yield this.routeHydrationService.hydrateRouteFile(s.routeDocument,{streamTypes:[...b]});return this.notifyProgress(o,{phase:"done",progress:100,details:"Done"}),{routeDocument:u.routeDocument,routeFile:u.routeFile,sourceFile:u.sourceFile,user:r,sourceFilesCount:s.sourceFilesCount,routeCount:s.routeCount,waypointCount:s.waypointCount,pointCount:s.pointCount}})}reprocessRouteFunctionAndRefreshDocument(r,t,o){return f(this,null,function*(){let s=t.id;if(!s)throw new c("PARSE_FAILED","Route ID is missing and cannot be reprocessed.");if(this.routeService.getOriginalRouteFiles(t).length===0)throw new c("NO_ORIGINAL_FILES","No original source file metadata found for this route.");this.getProgressPlan().forEach(l=>this.notifyProgress(o,l));let u;try{u=(yield this.functionsService.call("reprocessRoute",{routeId:s})).data}catch(l){throw this.mapFunctionError(l)}if(u.status==="skipped"&&u.reason==="NO_ORIGINAL_FILES")throw new c("NO_ORIGINAL_FILES","No original source file metadata found for this route.");let a=yield v(this.routeService.getRoute(r,s));if(!a)throw new c("PERSIST_FAILED","Could not load updated route after reprocessing.");return{routeDocument:a,sourceFilesCount:u.sourceFilesCount,routeCount:u.routeCount,waypointCount:u.waypointCount,pointCount:u.pointCount}})}mapFunctionError(r){let t=`${r?.code||""}`,o=`${r?.message||(r instanceof Error?r.message:r)||""}`.trim();return o.includes("NO_ORIGINAL_FILES")?new c("NO_ORIGINAL_FILES","No original source file metadata found for this route.",r):t.includes("failed-precondition")&&/account is being deleted|account deletion|no longer exists/i.test(o)?new c("ACCOUNT_DELETING",o||"Account deletion is in progress.",r):t.includes("unavailable")||o.includes("Could not verify account state")?new c("SERVICE_UNAVAILABLE",o||"Route reprocess service is temporarily unavailable.",r):new c("PARSE_FAILED","Could not parse the original route source file.",r)}notifyProgress(r,t){r?.onProgress?.(t)}getProgressPlan(){return[{phase:"validating",progress:5,details:"Validating source file"},{phase:"downloading",progress:20,details:"Downloading source file"},{phase:"parsing",progress:45,details:"Parsing route"},{phase:"regenerating_stats",progress:70,details:"Generating route statistics"},{phase:"persisting",progress:90,details:"Saving updated route"}]}static \u0275fac=function(t){return new(t||e)};static \u0275prov=R({token:e,factory:e.\u0275fac,providedIn:"root"})}return e})();var C=25;var te="Sending stopped before this route because Quantified Self could not save the Garmin resend state for an earlier route. Retry the remaining routes.";function re(e){switch(e){case i.GarminAPI:return"Garmin Connect";case i.SuuntoApp:return"Suunto";case i.WahooAPI:return"Wahoo";case i.COROSAPI:return"COROS";default:return`${e}`}}function V(e){return e===i.GarminAPI?te:`Sending stopped before this route because Quantified Self could not save the ${re(e)} delivery state for an earlier route. Retry the remaining routes.`}var ne=["DESTINATION_AUTH_REQUIRED","DESTINATION_PERMISSION_REQUIRED","DELIVERY_METADATA_PERSIST_FAILED","ACCOUNT_DELETION_IN_PROGRESS","ACCOUNT_STATE_UNAVAILABLE","SEND_REQUEST_FAILED","SOURCE_SERVICE_BLOCKED","SOURCE_FILE_UNAVAILABLE","PARSE_FAILED","NOT_FOUND","NO_ORIGINAL_FILES","PROVIDER_ERROR","UNSUPPORTED_DESTINATION"],oe=["ACCOUNT_DELETION_IN_PROGRESS","ACCOUNT_STATE_UNAVAILABLE","DESTINATION_AUTH_REQUIRED","DESTINATION_PERMISSION_REQUIRED","DELIVERY_METADATA_PERSIST_FAILED"],se=new Set(["Could not send route.","Could not send routes to Suunto.","Could not send routes to Garmin.","Could not send routes to Wahoo.","Could not send routes to COROS.","Could not send routes to the selected service."]);function ie(e,n){let r=e?.message,t=e?.code,o=typeof r=="string"?r:"",s=typeof t=="string"?t:"";return W(o)?o:s.includes("permission-denied")?"Sending routes to services is a Pro feature.":s.includes("unauthenticated")?ae(o,n)?$(n||Q(o)):"Sending routes is not authorized. Please sign in again.":/not supported yet/i.test(o)?o:/grant .*permission/i.test(o)||/course import/i.test(o)?z(n||Q(o)):/account is being deleted/i.test(o)?"Account is being deleted or no longer exists.":/could not verify account state/i.test(o)?"Could not verify account state. Please retry.":o||j(n)}function ue(e){let n=e.results.filter(t=>t.status!=="success");switch(ne.find(t=>n.some(o=>o.reason===t))){case"DESTINATION_AUTH_REQUIRED":return B(n,"DESTINATION_AUTH_REQUIRED")||$(e.destinationServiceName);case"DESTINATION_PERMISSION_REQUIRED":return B(n,"DESTINATION_PERMISSION_REQUIRED")||z(e.destinationServiceName);case"ACCOUNT_DELETION_IN_PROGRESS":return"Account is being deleted or no longer exists.";case"ACCOUNT_STATE_UNAVAILABLE":return"Could not verify account state. Please retry.";case"SOURCE_SERVICE_BLOCKED":return n.find(t=>t.reason==="SOURCE_SERVICE_BLOCKED"&&typeof t.message=="string"&&t.message.trim().length>0)?.message?.trim()||"Routes imported from Suunto are already there and cannot be sent back to Suunto.";default:return n.find(t=>typeof t.message=="string"&&t.message.trim())?.message?.trim()||j(e.destinationServiceName)}}function Ye(e){if(!e.results.some(t=>t.status!=="success"))return null;let r=ue(e);return se.has(r)?null:r}var Xe=(()=>{class e{functionsService=S(I);sendRoutesToService(s,u){return f(this,arguments,function*(r,t,o={}){let a=Array.from(new Set(r.map(g=>`${g||""}
1`.trim()).filter(Boolean)));if(a.length===0)throw new Error("Select at least one route to send.");let l=this.chunkRouteIds(a),m=[],d=0;for(let g=0;g<l.length;g++){let D=l[g];try{let E=yield this.functionsService.call("sendRoutesToService",N({routeIds:D,destinationServiceName:t},o.forceCopy===!0?{forceCopy:!0}:{}));m.push(E.data),d+=D.length,o.onProgress?.({chunkIndex:g,chunkCount:l.length,processedRouteCount:d,routeCount:a.length});let A=this.getTerminalInBandChunkResult(E.data);if(A){let T=a.slice(d);T.length>0&&m.push(this.buildTerminalInBandResponse(t,T,A));break}}catch(E){if(m.length===0)throw E;let A=a.slice(d);m.push(this.buildFailedChunkResponse(t,A,E));break}}return this.mergeResponses(t,a.length,m)})}chunkRouteIds(r){let t=[];for(let o=0;o<r.length;o+=C)t.push(r.slice(o,o+C));return t}buildFailedChunkResponse(r,t,o){let s=ie(o,r);return{destinationServiceName:r,status:"failure",routeCount:t.length,successCount:0,failureCount:t.length,skippedCount:0,results:t.map(u=>({routeId:u,destinationServiceName:r,status:"failure",reason:"SEND_REQUEST_FAILED",message:s}))}}getTerminalInBandChunkResult(r){for(let t of oe){let o=r.results.find(s=>s.reason===t);if(o)return o}return null}buildTerminalInBandResponse(r,t,o){return o.reason==="DELIVERY_METADATA_PERSIST_FAILED"?{destinationServiceName:r,status:"failure",routeCount:t.length,successCount:0,failureCount:t.length,skippedCount:0,results:t.map(s=>({routeId:s,destinationServiceName:r,status:"failure",reason:"SEND_REQUEST_FAILED",message:V(r)}))}:{destinationServiceName:r,status:o.status==="success"?"success":"failure",routeCount:t.length,successCount:o.status==="success"?t.length:0,failureCount:o.status==="failure"?t.length:0,skippedCount:o.status==="skipped"?t.length:0,results:t.map(s=>({routeId:s,destinationServiceName:r,status:o.status,reason:o.reason,message:o.message}))}}mergeResponses(r,t,o){let s=o.flatMap(d=>d.results),u=s.filter(d=>d.status==="success").length,a=s.filter(d=>d.status==="skipped").length,l=s.length-u-a,m=u===t?"success":u>0?"partial_success":"failure";return{destinationServiceName:r,status:m,routeCount:t,successCount:u,failureCount:l,skippedCount:a,results:s}}static \u0275fac=function(t){return new(t||e)};static \u0275prov=R({token:e,factory:e.\u0275fac,providedIn:"root"})}return e})();function $(e){switch(e){case i.SuuntoApp:return"Connect Suunto again before sending routes.";case i.GarminAPI:return"Connect Garmin again before sending routes.";case i.WahooAPI:return"Connect Wahoo again before sending routes.";default:return"Reconnect the selected service before sending routes."}}function z(e){switch(e){case i.GarminAPI:return"Grant Garmin Course Import permission and reconnect before sending routes.";case i.WahooAPI:return G;default:return"Grant the required destination permissions and reconnect before sending routes."}}function W(e){return/previously used for this route/i.test(e)}function B(e,n){return e.find(t=>t.reason===n&&typeof t.message=="string"&&t.message.trim().length>0&&W(t.message.trim()))?.message?.trim()||null}function j(e){switch(e){case i.SuuntoApp:return"Could not send routes to Suunto.";case i.GarminAPI:return"Could not send routes to Garmin.";case i.WahooAPI:return"Could not send routes to Wahoo.";default:return"Could not send routes to the selected service."}}function Q(e){return/suunto/i.test(e)?i.SuuntoApp:/garmin/i.test(e)?i.GarminAPI:/wahoo/i.test(e)?i.WahooAPI:null}function ae(e,n){return n===i.SuuntoApp?/suunto/i.test(e)||/no connected .*account/i.test(e)||/re-?connect/i.test(e):n===i.GarminAPI?/garmin/i.test(e)||/no connected .*account/i.test(e)||/re-?connect/i.test(e):n===i.WahooAPI?/wahoo/i.test(e)||/no connected .*account/i.test(e)||/re-?connect/i.test(e):/suunto/i.test(e)||/garmin/i.test(e)||/wahoo/i.test(e)||/no connected .*account/i.test(e)||/re-?connect/i.test(e)}export{Y as a,Se as b,X as c,me as d,q as e,J as f,ge as g,ee as h,Re as i,Ee as j,Ae as k,De as l,Fe as m,we as n,Me as o,ie as p,ue as q,Ye as r,Xe as s};
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.