import React from 'react';
import { Space } from 'antd';
import { CreateButton, ExportButton, ImportButton } from '@refinedev/antd';
import { agentAttrs } from './agentPanel/agentAttributes';

export interface ListPageHeaderProps {
  /** Show import button */
  showImport?: boolean;
  /** Show export button */
  showExport?: boolean;
  /** Show create button */
  showCreate?: boolean;
  /** Import button props */
  importProps?: any;
  /** Export handler */
  onExport?: () => void;
  /** Export loading state */
  exportLoading?: boolean;
  /** Custom buttons to render before default buttons */
  extraButtons?: React.ReactNode;
  /** Custom buttons to render after default buttons */
  extraButtonsAfter?: React.ReactNode;
  /** Resource name for agent inspector */
  resourceName?: string;
}

/**
 * Default header buttons for list page
 */
export const ListPageHeader: React.FC<ListPageHeaderProps> = ({
  showImport = true,
  showExport = true,
  showCreate = true,
  importProps,
  onExport,
  exportLoading = false,
  extraButtons,
  extraButtonsAfter,
  resourceName = '',
}) => {
  return (
    <div {...agentAttrs({ type: 'list-header', resource: resourceName })}>
      <Space>
        {extraButtons}
        {showImport && importProps && <ImportButton {...importProps} />}
        {showExport && onExport && (
          <ExportButton onClick={onExport} loading={exportLoading} />
        )}
        {showCreate && <CreateButton type="primary" />}
        {extraButtonsAfter}
      </Space>
    </div>
  );
};

export default ListPageHeader;
