import r from"@babel/runtime/helpers/toConsumableArray";import t from"@babel/runtime/helpers/defineProperty";import{useContext as e,useRef as n,useMemo as i}from"react";import o from"uuid";import a from"classnames";import c from"prop-types";import{range as s}from"lodash";import{DEFAULT_TRACK_SETTINGS as m}from"../constants.js";import p from"../AddEditTrack.js";import u from"../SettingsContext.js";import f from"../DataContext.js";import d from"./TraceHeader.js";import l from"./ChartContainer.js";import g from"./Track.css.js";import{jsx as b,Fragment as h,jsxs as j}from"react/jsx-runtime";function y(r,t){var e=Object.keys(r);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(r);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(r,t).enumerable}))),e.push.apply(e,n)}return e}function v(r){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?y(Object(n),!0).forEach((function(e){t(r,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(n)):y(Object(n)).forEach((function(t){Object.defineProperty(r,t,Object.getOwnPropertyDescriptor(n,t))}))}return r}var O=function(c){var y,O=c.id,P=c.index,x=e(u),C=x.horizontal,k=x.settingsKey,S=x.settings,w=x.onSettingsChange,D=x.maxTracesCount,T=x.multipleAssets,A=e(f).mapping,E=n(),N=i((function(){return O?S[k].find((function(r){return r.id===O})):m}),[O,S,k]),z=function(r){var e=S[k].map((function(t){return O===t.id?v(v({},t),{},{traces:t.traces&&t.traces.filter((function(t){return t.id!==r}))}):t}));w(v(v({},S),{},t({},k,e)))},K=function(e){var n=[];n=e.id?N.traces.map((function(r){return r.id===e.id?e:r})):[].concat(r(N.traces),[v(v({},e),{},{id:o()})]);var i=S[k].map((function(r){return O===r.id?v(v({},r),{},{traces:n}):r}));w(v(v({},S),{},t({},k,i)))},q=function(){E.current.click()},H=i((function(){if(!T)return N.name;var r=A.find((function(r){var t,e;return r.key===(null===(t=N.traces)||void 0===t||null===(e=t[0])||void 0===e?void 0:e.key)}));return r?r.name:N.name}),[N.traces,N.name,T]);return b(h,{children:j("div",{className:a(g.container,(y={},t(y,g.horizontal,C),t(y,g.vertical,!C),y)),children:[b(p,{mapping:A,settings:S,onSettingsChange:w,settingsKey:k,id:O,multipleAssets:T,children:b("div",{className:g.header,ref:E,children:b("div",{className:g.title,children:H})})}),!T&&s(D).map((function(r){return b(d,{index:r,traceSettings:N.traces[r],onDelete:z,mapping:A,onChange:K,openTrackSettings:q},N.traces[r]?N.traces[r].id:r)})),b(l,{traces:N.traces,trackIndex:P})]})})};O.propTypes={id:c.string,index:c.number.isRequired},O.defaultProps={id:""};export{O as default};
