import React from 'react';
import { FormikProps } from 'formik';
import { Props as ButtonProps } from '../components/Button';
import { Field } from '../components/ListTable';

export interface Action extends ButtonProps {
  name: string;
}

export interface PanelProps<T> {
  item: T;
  mutate: (item: T) => void;
}

export interface ServiceParams<T = any> {
  route: string;
  name: string;
  tableFields: Field[];
  nameSingular?: string;
  default?: Partial<T>;
  routes?: Record<string, React.FC>;
  actions?: Action[];
  rowLink?: (item: T) => string;
  Form?: React.FC<FormikProps<T>>;
  Panel?: React.FC<PanelProps<T>>;
}

const ServiceContext = React.createContext<ServiceParams>({
  route: '',
  name: '',
  nameSingular: '',
  tableFields: [],
  default: {},
});

export const ServiceProvider = ServiceContext.Provider;
export default ServiceContext;
