import {
  BandsintownItem,
  BaseItem,
  DataCaptureFormItem,
  EventItem,
  ExperienceItem,
  FanClubItem,
  GroupItem,
  LinkItem,
  MusicItem,
  OnDemandVideoItem,
  PodcastItem,
  ProductItem,
  ShopifyModuleItem,
  ShopifyProductItem,
  TalentModuleMixItem,
  TalentProfileModule,
  TalentProfileModuleGroup,
  YoutubeVideoItem,
} from "models/talent/talent-profile-module.model";

import { ModuleType } from "@komi-app/shared-types"

// TODO: No `ModuleType` enum value corresponds to `TalentModuleMixItem.DataCaptureFormItem`
// TODO: No `TalentModuleMixItem` enum value corresponds to `ModuleType.SHOP_MY_SHELF`
// TODO: No `TalentModuleMixItem` enum value corresponds to `ModuleType.SHOPIFY_COLLECTION`
// TODO: No `TalentModuleMixItem` enum value corresponds to `ModuleType.YOUTUBE`
// TODO: No `TalentModuleMixItem` enum value corresponds to `ModuleType.YOUTUBE_COLLECTION`

export const isModuleGroup = (
  module: GroupItem
): module is TalentProfileModuleGroup<TalentModuleMixItem> => {
  return module.type === ModuleType.GROUP;
};

export const isProductItem = (
  module: GroupItem
): module is TalentProfileModule<ProductItem> => {
  return module.type === ModuleType.PRODUCT;
};
export const isLinkItem = (
  module: GroupItem
): module is TalentProfileModule<LinkItem> => {
  return module.type === ModuleType.LINK;
};
export const isMusicItem = (
  module: GroupItem
): module is TalentProfileModule<MusicItem> => {
  return module.type === ModuleType.MUSIC;
};
export const isOnDemandVideoItem = (
  module: GroupItem
): module is TalentProfileModule<OnDemandVideoItem> => {
  return module.type === ModuleType.ON_DEMAND_VIDEO;
};
export const isYoutubeVideoItem = (
  module: GroupItem
): module is TalentProfileModule<YoutubeVideoItem> => {
  return module.type === ModuleType.YOUTUBE_VIDEO;
};
export const isExperienceItem = (
  module: GroupItem
): module is TalentProfileModule<ExperienceItem> => {
  return module.type === ModuleType.EXPERIENCE;
};
export const isPodcastItem = (
  module: GroupItem
): module is TalentProfileModule<PodcastItem> => {
  return module.type === ModuleType.PODCAST;
};
export const isFanClubItem = (
  module: GroupItem
): module is TalentProfileModule<FanClubItem> => {
  return module.type === ModuleType.FAN_CLUB;
};
export const isBandsintownItem = (
  module: GroupItem
): module is TalentProfileModule<BandsintownItem> => {
  return module.type === ModuleType.BANDSINTOWN;
};
export const isShopifyProductItem = (
  module: GroupItem
): module is TalentProfileModule<ShopifyProductItem> => {
  return module.type === ModuleType.SHOPIFY_PRODUCT;
};
export const isRyeShopifyProductItem = (
  module: GroupItem
): module is TalentProfileModule<ShopifyProductItem> => {
  return module.type === ModuleType.RYE_SHOPIFY_PRODUCT;
};
export const isShopifyModuleItem = (
  module: GroupItem
): module is TalentProfileModule<ShopifyModuleItem> => {
  return module.type === ModuleType.SHOPIFY;
};
export const isRyeShopifyModuleItem = (
  module: GroupItem
): module is TalentProfileModule<ShopifyModuleItem> => {
  return module.type === ModuleType.RYE_SHOPIFY;
};
export const isEventItem = (
  module: GroupItem
): module is TalentProfileModule<EventItem> => {
  return module.type === ModuleType.EVENTS;
};
export const isDataCaptureFormItem = (
  module: GroupItem
): module is TalentProfileModule<DataCaptureFormItem> => {
  return module.type === ModuleType.FORM_DATA;
};

export const flipVisibilityForItemAndCloneArray = (
  item: BaseItem,
  items: BaseItem[]
): any[] => {
  let index: number;
  if (item.order === undefined) index = items.findIndex((x) => x == item);
  else {
    index = item.order;
  }
  const updatedItem = Object.assign({}, items[index]);
  updatedItem.visible = !updatedItem.visible;
  updatedItem.isUpdate = true;
  const updatedItems = Array.from(items);
  updatedItems[index] = updatedItem;
  return updatedItems;
};

export const isEmptyModule = (module: TalentProfileModule<BaseItem>) => {
  return !module.items || !module.items.length;
};
