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