"use strict";var e=require("@babel/runtime/helpers/toConsumableArray"),t=require("@babel/runtime/helpers/defineProperty"),r=require("@babel/runtime/helpers/slicedToArray"),n=require("react"),i=require("prop-types"),a=require("uuid/v1"),s=require("@material-ui/core"),u=require("./components/TrackSettings.js"),c=require("./components/SingleChannelTrackSettings.js"),o=require("./constants.js"),l=require("../Modal/Modal.js");require("./AddEditTrack.css.js");var d=require("react/jsx-runtime");function f(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var p=f(e),g=f(t),m=f(r),b=f(i),j=f(a);function T(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function y(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?T(Object(r),!0).forEach((function(t){g.default(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):T(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}var h=function(e){var t=e.children,r=e.classes,i=e.id,a=e.settings,f=e.onSettingsChange,b=e.settingsKey,T=e.mapping,h=e.multipleAssets,S=n.useState(!1),v=m.default(S,2),q=v[0],O=v[1],k=n.useState(o.DEFAULT_TRACK_SETTINGS),C=m.default(k,2),A=C[0],E=C[1],_=function(e,t){E(y(y({},A),{},g.default({},e,t)))};n.useEffect((function(){var e=i?a[b].find((function(e){return e.id===i})):o.DEFAULT_TRACK_SETTINGS;E(e)}),[a,b,i]);return d.jsxs(d.Fragment,{children:[d.jsx("div",{className:r.link,onClick:i?function(){return O(!0)}:function(){f(y(y({},a),{},g.default({},b,[].concat(p.default(a&&a[b]||[]),[y(y({},A),{},{id:j.default()})])))),E(o.DEFAULT_TRACK_SETTINGS)},children:t}),d.jsx(l,{open:q,title:"Track Settings",actions:d.jsxs("div",{className:"c-pc-track-setting-actions",children:[i&&d.jsx(s.Button,{className:r.button,color:"primary",onClick:function(){var e=a[b].filter((function(e){return e.id!==i}));f(y(y({},a),{},g.default({},b,e))),O(!1)},children:"Delete Track"}),d.jsx(s.Button,{"data-testid":"".concat("DC_AddEditTrack","_cancel"),className:r.button,color:"primary",onClick:function(){var e=i?a[b].find((function(e){return e.id===i})):o.DEFAULT_TRACK_SETTINGS;E(e),O(!1)},children:"Cancel"}),d.jsx(s.Button,{"data-testid":"".concat("DC_AddEditTrack","_save"),className:r.button,variant:"contained",color:"primary",onClick:function(){var e=a[b].map((function(e){return e.id===i?A:e}));f(y(y({},a),{},g.default({},b,e))),O(!1)},children:"Save"})]}),children:h?d.jsx(c,{trackSettings:A,onChange:_,mapping:T}):d.jsx(u,{settings:A,onChange:_,mapping:T})})]})};h.propTypes={settingsKey:b.default.string,multipleAssets:b.default.bool,settings:b.default.shape({}),onSettingsChange:b.default.func.isRequired,children:b.default.element.isRequired,id:b.default.string,mapping:b.default.arrayOf(b.default.shape({name:b.default.string.isRequired,key:b.default.string.isRequired}).isRequired).isRequired},h.defaultProps={id:"",settingsKey:o.SETTINGS_KEY,settings:{},multipleAssets:!1};var S=s.withStyles({link:{cursor:"pointer"},button:{fontSize:14,marginLeft:20}})(h);module.exports=S;
//# sourceMappingURL=AddEditTrack.js.map
