text: import VoiceCampaignToken from '@apps/campaigns/admin/tokens/campaign/voice'
  import ProgramForm from '@apps/crm/admin/components/programform'
  import { Logo, Page } from '@admin'
  import React from 'react'
  import New from './new'
  
  const mapPropsToPage = (props, context, resources, page) => ({
    title: 'Voice Campaigns',
    rights: ['campaigns:manage_voice_campaigns'],
    collection: {
      endpoint: '/api/admin/campaigns/voice',
      table: [
        { label: 'ID', key: 'id', collapsing: true, visible: false },
        { label: 'Title', key: 'title', primary: true, format: (campaign) => (
          <VoiceCampaignToken campaign={ campaign } />
        )}
      ],
      criteria: {
        fields: [
          { label: 'Voice Campaign', fields: [
            { name: 'Program', key: 'program_id', type: 'select', endpoint: '/api/admin/crm/programs', text: 'title', value: 'id' }
          ] }
        ],
        system: resources.programs.map((program, index) => (
          { id: index, title: program.title, token: <Logo team={ program } width="24" />, config: {
            criteria: [
              { code: 'abc', data: null, field: null, operator: '$and', parent: null, value: null },
              { code: 'def', data: null, field: 'program_id', operator: '$eq', parent: 'abc', value: program.id }
            ]
          } }
        ))
      },
      export: [
        { label: 'ID', key: 'id' },
        { label: 'Title', key: 'title' },
        { label: 'Program', key: 'program.title' },
        { label: 'Calls', key: 'calls_count' },
        { label: 'Active', key: 'active_count' },
        { label: 'Lost', key: 'lost_count' },
        { label: 'Converted', key: 'converted_count' },
        { label: 'Completed', key: 'completed_count' },
        { label: 'Status', key: 'status' }
      ],
      defaultSort: { key: 'created_at', order: 'desc' },
      empty: {
        icon: 'phone',
        title: 'No Voice Campaigns',
        text: 'You have not yet created any voice campaigns',
        buttons: resources.programs.length > 0 ? [
          { label: 'Create Campaign', modal: <ProgramForm programs={ resources.programs } fields={ resources.fields } requires={['phone_number']} form={ New } /> }
        ] : null
      },
      entity: 'campaign',
      onClick: (record) => context.router.history.push(`/campaigns/voice/${record.id}`)
    },
    task: resources.programs.length > 0 ? {
      icon: 'plus',
      modal: <ProgramForm programs={ resources.programs } fields={ resources.fields } requires={['phone_number']}  form={ New } />
    } : null
  })
  
  const mapResourcesToPage = (props, context) => ({
    programs: {
      endpoint: '/api/admin/crm/programs',
      filter: {
        phone_number_id: {
          $nnl: true
        },
        access_type: {
          $in: ['manage','edit']
        }
      }
    }
  })
  
  export default Page(mapResourcesToPage, mapPropsToPage)
  