import '../../setup-fixture';

import { type BlockRendererOptions } from '../../BlockRenderer/BlockRendererOptions';
import { PopupManager } from '../../ui-kit/PopupManager/PopupManager';
import { Blocks } from '../Blocks';
import { TARIFFS_CARD } from '../CarouselTariffsCard/CarouselTariffsCard.fixture';
import { BankAccountFiltration } from './BankAccountFiltration';
import { type BankAccountFiltrationContent } from './BankAccountFiltrationContent';

const options = { blocksRegistry: Blocks } as BlockRendererOptions;

const filtrationSchema: BankAccountFiltrationContent['filtrationSchema'] = {
  extraOptions: {
    title: 'Дополнительные опции',
    type: 'array',
    items: {
      type: 'string',
      enum: ['rko', 'acquiring', 'ved'],
      enumNames: ['РКО', 'Эквайринг', 'ВЭД'],
    },
  },
  externalTransfers: {
    title: 'Внешние переводы на счета ЮЛ и ИП в месяц',
    type: 'array',
    single: true,
    items: {
      type: 'string',
      enum: ['often', 'rarely'],
      enumNames: ['Часто', 'Редко'],
    },
  },
  depositingCash: {
    title: 'Внесение наличных в месяц',
    type: 'array',
    single: true,
    items: {
      type: 'string',
      enum: ['often', 'rarely'],
      enumNames: ['Часто', 'Редко'],
    },
  },
  withdrawalCash: {
    title: 'Снятие наличных в месяц',
    type: 'array',
    single: true,
    items: {
      type: 'string',
      enum: ['often', 'rarely'],
      enumNames: ['Часто', 'Редко'],
    },
  },
};

const TARRIFF_FARMERS_RKO_EXTERNAL_OF = {
  type: 'CarouselTariffsCard',
  content: {
    ...TARIFFS_CARD,
    consumer: ['farmers'],
    extraOptions: ['rko'],
    externalTransfers: ['often'],
    className: ['col-span-6'],
  },
};

const TARRIFF_FARMERS_RKO_EXTERNAL_RAR = {
  type: 'CarouselTariffsCard',
  content: {
    ...TARIFFS_CARD,
    consumer: ['farmers'],
    extraOptions: ['rko'],
    externalTransfers: ['rarely'],
    className: ['col-span-6'],
  },
};

const TARRIFF_FARMERS_VED_EXTERNAL_RAR = {
  type: 'CarouselTariffsCard',
  content: {
    ...TARIFFS_CARD,
    consumer: ['farmers'],
    extraOptions: ['ved'],
    externalTransfers: ['rarely'],
    className: ['col-span-6'],
  },
};

const TARRIFF_NEW_BUSINESS_VED_EXTERNAL_RAR = {
  type: 'CarouselTariffsCard',
  content: {
    ...TARIFFS_CARD,
    consumer: ['newBusiness'],
    extraOptions: ['ved'],
    externalTransfers: ['rarely'],
    className: ['col-span-6'],
  },
};

const TARRIFF_ACTIVE_BUSINESS_RKO_EXTERNAL_OF = {
  type: 'CarouselTariffsCard',
  content: {
    ...TARIFFS_CARD,
    consumer: ['farmers'],
    extraOptions: ['rko'],
    externalTransfers: ['often'],
    className: ['col-span-6'],
  },
};

const BLOCK_CONTENT: BankAccountFiltrationContent = {
  resetButton: { text: 'Очистить фильтры', version: 'primary' },
  filtrationSchema,
  consumerField: {
    title: 'Для кого',
    type: 'array',
    single: true,
    ui: 'dropdown',
    items: {
      type: 'string',
      enum: ['farmers', 'newBusiness', 'activeBusiness'],
      enumNames: ['Для фермеров', 'Для начинающего бизнеса', 'Для активного бизнеса'],
    },
  },
  notFound: {
    title: 'Нет подходящего тарифа',
    description: 'Попробуйте очистить фильтры',
  },
};

const BLOCK_PROPS = {
  className: 'col-span-12',
  options,
  block: {
    type: 'BankAccountFiltration',
    blocks: [
      TARRIFF_FARMERS_RKO_EXTERNAL_OF,
      TARRIFF_FARMERS_RKO_EXTERNAL_RAR,
      TARRIFF_FARMERS_VED_EXTERNAL_RAR,
      TARRIFF_NEW_BUSINESS_VED_EXTERNAL_RAR,
      TARRIFF_ACTIVE_BUSINESS_RKO_EXTERNAL_OF,
    ],
  },
};

export default {
  default: (
    <div className="container grid grid-cols-12">
      <BankAccountFiltration
        {...BLOCK_CONTENT}
        {...BLOCK_PROPS}
        blocksSection={{ view: 'carousel' }}
      />
      <PopupManager />
    </div>
  ),
  grid: (
    <div className="container grid grid-cols-12">
      <BankAccountFiltration
        {...BLOCK_CONTENT}
        {...BLOCK_PROPS}
        blocksSection={{ view: 'grid', topItemsCount: 2, label: 'Показать ещё' }}
      />
      <PopupManager />
    </div>
  ),
};
