import * as watchesSelectors from '../redux/selectors';

export const getChannelFromStore = (state) => {
  const watchId = watchesSelectors.watchIdSelector(state);
  const channelId = watchesSelectors.channelIdSelector(state);
  const watches = watchesSelectors.watchesSelector(state);

  if (channelId && watchId) {
    const watch = watches.find((item) => item.id === watchId);
    const channel = watch?.watchChannels?.find((item) => item?.id === channelId) ?? null;

    if (channel) {
      return {
        watchTitle: watch.title,
        watchId,
        ...channel,
      };
    }

    return null;
  }

  return null;
};

export default {};
