"use strict";var e=require("@babel/runtime/helpers/toConsumableArray"),r=require("@babel/runtime/helpers/defineProperty"),t=require("@babel/runtime/helpers/slicedToArray"),n=require("react"),a=require("prop-types"),i=require("uuid"),s=require("@material-ui/core"),c=require("@material-ui/icons/NavigateNext"),u=require("@material-ui/icons/Add"),o=require("../constants.js"),l=require("./TraceSettings.js"),d=require("./TraceSelect.js"),f=require("./TrackSettings.css.js"),p=require("../../ColorPicker/ColorPicker.js"),m=require("../../Modal/Modal.js"),h=require("react/jsx-runtime");function j(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var g=j(e),v=j(r),b=j(t),y=j(a),x=j(i),T=j(c),q=j(u);function C(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 N(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?C(Object(t),!0).forEach((function(r){v.default(e,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):C(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}))}return e}var O=function(e){var r=e.settings,t=r.name,a=r.traces,i=e.onChange,c=e.classes,u=e.mapping,j=n.useState(!1),y=b.default(j,2),C=y[0],O=y[1],k=n.useState(),S=b.default(k,2),P=S[0],R=S[1],A=a&&a.length>o.MAX_TRACE_COUNT,B=function(){var e=a.map((function(e){return e.id===P.id?P:e}));i("traces",e),O(!1)};return h.jsxs(s.Grid,{className:c.container,children:[h.jsx(s.FormControl,{className:c.input,children:h.jsx(s.TextField,{label:"Track Name",value:t,className:c.input,onChange:function(e){var r=e.target.value;return i("name",r)}})}),h.jsx("div",{className:f.title,children:"Traces: "}),a&&!!a.length&&h.jsx("div",{className:f.tracesContainer,children:a.map((function(e,r){var t=e.id,n=e.key,o=e.color;return h.jsxs("div",{className:f.tracesItem,children:[h.jsx(d,{value:n,onChange:function(e){return function(e,r){var t=a.map((function(t){var n=u.find((function(e){var t=e.key;return r===t}));return t.id===e?N(N({},t),n):t}));i("traces",t)}(t,e)},mapping:u}),h.jsx("div",{className:f.colorPicker,children:h.jsx(p,{value:o,onChange:function(e){return function(e,r,t){var n=a.map((function(n){return n.id===e?N(N({},n),{},v.default({},r,t)):n}));i("traces",n)}(t,"color",e)},hideLabel:!0,buttonClassName:c.picker})}),h.jsx(s.IconButton,{onClick:function(){return function(e){R(a[e]),O(!0)}(r)},className:c.navBtn,children:h.jsx(T.default,{fontSize:"small",className:c.navIcon})})]},t)}))}),!A&&h.jsxs(s.Button,{color:"primary",onClick:function(){a&&a.length?i("traces",[].concat(g.default(a),[N({id:x.default()},o.DEFAULT_TRACE_SETTINGS)])):i("traces",[N({id:x.default()},o.DEFAULT_TRACE_SETTINGS)])},children:[h.jsx(q.default,{}),h.jsx("span",{children:"Add Trace"})]}),h.jsx(m,{open:C,title:h.jsxs("div",{className:f.modalTitle,children:[h.jsxs("span",{className:f.trackTitle,onClick:B,children:["Track Settings /"," "]}),P&&P.name||"Empty Trace"]}),actions:h.jsxs("div",{className:f.actions,children:[h.jsx(s.Button,{className:c.button,color:"primary",onClick:function(){var e=a.filter((function(e){return e.id!==P.id}));i("traces",e),O(!1)},children:"Delete Trace"}),h.jsx(s.Button,{className:c.button,color:"primary",onClick:function(){return O(!1)},children:"Cancel"}),h.jsx(s.Button,{className:c.button,variant:"contained",color:"primary",onClick:B,children:"Save"})]}),children:h.jsx(l,{traceSettings:P,onChange:function(e,r){R(N(N({},P),{},v.default({},e,r)))},mapping:u})})]})};O.propTypes={settings:y.default.shape({name:y.default.string.isRequired,traces:y.default.arrayOf(y.default.shape({}))}).isRequired,onChange:y.default.func.isRequired,classes:y.default.shape({}).isRequired,mapping:y.default.arrayOf(y.default.shape({name:y.default.string.isRequired,key:y.default.string.isRequired}).isRequired).isRequired};var k=s.withStyles((function(e){return{container:{paddingTop:20,minWidth:300},input:{width:200},picker:{width:36,minWidth:36,height:24},navBtn:{position:"absolute",right:-10,top:"50%",transform:"translate(0, -50%)"},navIcon:{color:"#BDBDBD"},button:{fontSize:14,marginLeft:20}}}))(O);module.exports=k;
