import { type ListMeta } from '@/interfaces/common';
import React from 'react';

export interface IBookingImage {
    key: string
    url: string
    original_name: string
    uploaded_by?: number | null
    uploaded_at?: string
}

export interface IBookingApplicant {
    id: number
    lead_id: number
    lead_booking_id: number
    client_name: string
    client_mobile: string
    client_email: string
    is_optional: number | boolean
}

export interface IBookingApplicants {
    applicant1: IBookingApplicant | null
    applicant2: IBookingApplicant | null
}

export interface IBooking {
    id: number
    lead_id: number
    project_id?: number | null
    project_name?: string | null
    applicants?: IBookingApplicants
    booked_at: string | null
    booking_amount: number | string | null
    brokerage: number | string | null
    passback_amount: number | string | null
    agreement_value: number | string | null
    carpet_area: number | string | null
    unit: string | null
    remark: string | null
    booking_images: IBookingImage[] | null
    sourcing: string | null
    closing: string | number | null
    closing_user?: string | null
    closing_user_role?: string | null
    which_configuration_you_are_looking_for_?: string | null
    is_cancelled: boolean
    cancelled_at: string | null
    cancel_remark: string | null
    created_at: string
}

export interface AllLeadsData {
    followUp: string
    customerName: string
    project: string
    config: string
    budget: number
    status: string
}
export interface LeadsPayload {
    pageSize?: number
    current?: number
    current_page: number
    per_page: number
    sort: any
    filters?: LeadsFilter
}
export interface AllLeadsState {
    dropdownList: any
    fieldSalesList: any
    preSalesList: any
    teamLeadList: any
    clusterManList: any
    leadCalendar: any
    leadRemarks?: any
    budgetList?: any
    leadStatus?: any
    launchedProjects: any
    filterProjectLList?: any
    projectListHasMore?: boolean
    filterLocalityLList?: any
    localityListHasMore?: boolean
    filterLaunchLList?: any
    launchTeamMates?: any
    configurationList?: any
    allLeads: any
    selectedEmployee: any
    SelectedLaunches: any
    leadDetailById: any
    projects: string[]
    loading: boolean
    listLoading: boolean
    status: 'loading' | 'succeeded' | 'failed'
    error: string | null
    leadsMeta: ListMeta
    activeLeads: ActiveLead[]
    overdueLeads: OverdueLead[]
    scheduled: ScheduledLead[]
    visited: VisitedLead[]
    token: string | null
    booked: BookedLead[]
    deadLead: DeadLead[]
}

export interface ActiveLead {
    followUp: string
    customerName: string
    project: string
    config: string
    budget: number
    status: string
}

export interface OverdueLead {
    followUp: string
    customerName: string
    project: string
    config: string
    budget: number
    status: string
}

export interface ScheduledLead {
    [x: string]: string | number | Date /* | Dayjs  */ | null | undefined
    followUp: string
    customerName: string
    project: string
    config: string
    budget: number
    status: string
}

export interface VisitedLead {
    followUp: string
    customerName: string
    project: string
    config: string
    budget: number
    status: string
}

export interface BookedLead {
    followUp: string
    customerName: string
    project: string
    config: string
    budget: number
    status: string
}

export interface DeadLead {
    followUp: string
    customerName: string
    project: string
    config: string
    budget: number
    status: string
}

interface LeadsFilter {
    project?: string
    launch?: string // You can change the type to Date if needed
    config?: string
    status?: string
    budget?: number
}
export interface VisibleColumns {
    followUpDateTime: boolean
    customerName: boolean
    project: boolean
    config: boolean
    budget: boolean
    remark: boolean
    // Add more columns with their types here
}
export interface projectListI {
    id: number
    value: number
    label: string
    name: string
}

export interface configList {
    configuration_id: number
    value: string
    label: string
    configuration_name: string
}

export interface budgetListI {
    value: string
    label: string
    meta_value: string
}
export interface remarkItem {
    id: number
    lead_id: number
    user_id: number
    remark: string
    status: null
    created_at: string
    user_name: string
    status_name: null
    title?: string
}

export interface TabFilterI {
    page: number | any
    pageSize: number | any
    sortColumn: string
    sortOrder: string
}

export interface filterI {
    search: string
    which_configuration_you_are_looking_for_: string | null
    whats_your_tentative_budget_: string | null
    status_id: number[] | null | string
    field?: string
    order?: string
    project_id: string | number | number[]
    locality_id?: string | number | number[]
    launch_id: string
    created_by: string | number | any
    range_date: string
    start_date: string
    end_date: string
    city_head_id?: any
    cluster_manager_id?: string | number | any,
    lead_user_city_id?: number | null,
    lead_user_role_name?: string,
    lead_user_id?:number | null
    veiw_data?:string | number,
    isNRI?: string,
    source?: string,
    tag?: string,
    is_transferred?: string,
    status_history?: number[] | null,
    filterTabs: {
        all_leads:TabFilterI
        today_follow_up: TabFilterI
        fresh_lead: TabFilterI
        active: TabFilterI
        overdue: TabFilterI
        scheduled: TabFilterI
        visited: TabFilterI
        token_done: TabFilterI
        booked: TabFilterI
        dead: TabFilterI
    }
}

export interface Column {
    render?: (text: any, record: any) => string | React.ReactNode | React.JSX.Element
    title: string
    key: string
    dataIndex?: string
    width: number
    sorter?: boolean
    isVisible: boolean
    isDate?: boolean
    isDateTime?: boolean
}

// Updated the interface for the entire VISIBLE_COLUMNS structure
export interface VisibleColumnsI {
    [key: string]: Column[] | any // Index signature added
    all_leads: Column[]
    today_follow_up: Column[]
    fresh_lead: Column[]
    active: Column[]
    overdue: Column[]
    scheduled: Column[]
    visited: Column[]
    token_done: Column[]
    booked: Column[]
    dead: Column[]
    Record?: Record<string, Column[]> // Optional property using Record type
}

export interface ClearRadiosMethods {
    clearRadio: (value: number) => void
}

export interface ClearAllFiltersMethods {
    clearFilter: (filters: { config: null; budget: null; status_id: null }) => void
}

export interface LeadsRecordI {
    id: number
    status_id: null
    project_id: number
    launch_id: number
    source: string
    created_at: string
    inquiry_date: null
    customer_name: string
    project_name: null
    launch_name: string
    field_sales: string
    configuration: string
    budget: string
    remark: string | any
    lead_status_name: null
    created_by_name: null
    lead_id: number
    city_id: number
    team_head_id: number
    cluster_manager_id: number
    created_by: null
    field_sales_id: number
    pre_sales_id: number
    follow_up_date: string
    stage: string
    status_slug: string
    site_visited_date: string
    is_transferred?: number
    transferred_from_launch_id?: number
    transferred_from_launch_name?: string
    transferred_at?: string
    transfer_type?: string
    transfer_remark?: string
    transferred_from_employee_name?: string
    transferred_to_employee_name?: string
}

export interface ModalBoxProps {
    isModalOpen?: boolean
    handleClose: () => void
    data?: any | null
    handleOk: () => void
}

export interface DuplicateLead {
  lead_id: number;
  lead_name: string;
  mobile_number: string;
  stage: string;
  status: string;
  last_remark?: string;
  project?: string;
  launch?: string;
}

export interface DuplicateCheckResponse {
  success: boolean;
  isDuplicate: boolean;
  duplicateType: 'self' | 'team' | 'self_different_launch';
  canRevive: boolean;
  message: string;
  duplicateLead: DuplicateLead;
}

export const tabLabelMap: Record<string, string> = {
  all_leads: 'All Leads',
  today_follow_up: `Today's Follow Up`,
  fresh_lead: 'Fresh Leads',
  active: 'Active Leads',
  overdue: 'Overdue Leads',
  scheduled: 'Scheduled Leads',
  visited: 'Visited Leads',
  token_done: 'Token Done Leads',
  booked: 'Booked Leads',
  dead: 'Dead Leads',
};