import { createSelector } from 'reselect';

/**
 * Direct selector to the create state domain
 */
const selectLineDomain = () => (state) => state.get('templates');
const selectLineMessageEditDomain = () => (state) => state.get('lineCreate');

const makeSelectLine = () => createSelector(
  selectLineDomain(),
  (substate) => substate && substate.toJS()
);

const makeSelectCreateLine = () => createSelector(
  selectLineMessageEditDomain(),
  (substate) => substate && substate.toJS()
);

const editLineContentSelector = () => createSelector(
  selectLineMessageEditDomain(),
  substate => [{
    messageContent: substate.getIn(['templateDetails', 'versions', 'base', 'content', 'messages']),
    messageTitle: substate.getIn(['templateDetails', 'name']),
    type: substate.getIn(['templateDetails', 'mode']),
  }]
);

export {
  makeSelectLine, makeSelectCreateLine, editLineContentSelector,
};
