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