import { CampaignStatuses } from "@komi-app/components";
import { ContactType, MarketingPermission } from "@komi-app/fans-sdk";
import {
  campaignsUrl,
  audiencesUrl,
  segmentsUrl,
  templatesUrl,
} from "constants/dca";
import { CursorPaginatedItem } from "hooks/usePagination";
import { embedUrl } from "constants/dca/embed";

export interface AudienceAndCampaignsPage {
  component: JSX.Element;
  tab: AudienceAndCampaignsTabs;
}
export enum AudienceAndCampaignsPages {
  Contacts = "contacts",
  Segments = "segments",
  Segment = "segment",
  Templates = "templates",
  TemplatesCreate = "templates-create",
  TemplatesEdit = "templates-edit",
  Campaigns = "campaigns",
  CampaignCreate = "campaign-create",
  CampaignEdit = "campaign-edit",
  CampaignReport = "campaign-report",
  Embed = "embed",
}

export interface ExistingCampaignRouteState {
  campaignId?: string;
}

export enum AudienceAndCampaignsTabs {
  Contacts = "contacts",
  Segments = "segments",
  Campaigns = "campaigns",
  SMSCampaigns = "sms-campaigns",
  Templates = "templates",
  Embed = "embed",
}

export const tabs = [
  {
    name: "Contacts",
    key: AudienceAndCampaignsTabs.Contacts,
    uri: audiencesUrl,
  },
  {
    name: "Segments",
    key: AudienceAndCampaignsTabs.Segments,
    uri: segmentsUrl,
  },
  {
    name: "Campaigns",
    key: AudienceAndCampaignsTabs.Campaigns,
    uri: campaignsUrl,
  },
  {
    name: "Templates",
    key: AudienceAndCampaignsTabs.Templates,
    uri: templatesUrl,
  },
  {
    name: "Website Embed",
    key: AudienceAndCampaignsTabs.Embed,
    uri: embedUrl,
  },
];

export interface ContactsTableRow {
  name: string;
  email: string[];
  phone: string;
  firstSignedUp: string;
}
export interface CampaignsTableRow {
  campaignId: string;
  name: string;
  status: CampaignStatuses;
  segmentData: { segmentName: string }[];
  openRate: number | null;
  clickThroughRate: number | null;
  scheduledSendTimestamp: number | null;
}
export type CampaignsWithCursorTableRow =
  CursorPaginatedItem<CampaignsTableRow>;

// Move into test files when api integrated
export const getTestSegments = (rows: number) => {
  const segments = [];

  for (let i = 0; i < rows; i++) {
    segments.push({
      segmentId: `${i}`,
      name: `Segment ${i}`,
      contactType: ContactType.Any,
      marketingPermission: MarketingPermission.Any,
      expressions: [],
    });
  }
  return segments;
};

export type ReviewSuccessfulState = { wasReviewSuccessful: boolean };
