import { useObjectLabel } from '@/object-metadata/hooks/useObjectLabel';
import { RecordIndexAddRecordInGroupDropdown } from '@/object-record/record-index/components/RecordIndexAddRecordInGroupDropdown';
import { recordIndexRecordGroupHideComponentFamilyState } from '@/object-record/record-index/states/recordIndexRecordGroupHideComponentFamilyState';
import { useRecordTableContextOrThrow } from '@/object-record/record-table/contexts/RecordTableContext';
import { RecordTableEmptyStateDisplay } from '@/object-record/record-table/empty-state/components/RecordTableEmptyStateDisplay';
import { getEmptyStateSubTitle } from '@/object-record/record-table/empty-state/utils/getEmptyStateSubTitle';
import { getEmptyStateTitle } from '@/object-record/record-table/empty-state/utils/getEmptyStateTitle';
import { useSetRecoilComponentFamilyStateV2 } from '@/ui/utilities/state/component-state/hooks/useSetRecoilComponentFamilyStateV2';
import { ViewType } from '@/views/types/ViewType';
import { Button } from 'twenty-ui/input';
import { IconPlus } from 'twenty-ui/display';

export const RecordTableEmptyStateByGroupNoRecordAtAll = () => {
  const { objectMetadataItem } = useRecordTableContextOrThrow();

  const setHideEmptyRecordGroup = useSetRecoilComponentFamilyStateV2(
    recordIndexRecordGroupHideComponentFamilyState,
    ViewType.Table,
  );

  const objectLabel = useObjectLabel(objectMetadataItem);

  const buttonTitle = `Add a ${objectLabel}`;

  const title = getEmptyStateTitle(
    objectMetadataItem.nameSingular,
    objectLabel,
  );

  const subTitle = getEmptyStateSubTitle(
    objectMetadataItem.nameSingular,
    objectLabel,
  );

  const handleButtonClick = () => {
    // When we have no records in the group, we want to show the empty state
    setHideEmptyRecordGroup(false);
  };

  return (
    <RecordTableEmptyStateDisplay
      title={title}
      subTitle={subTitle}
      animatedPlaceholderType="noRecord"
      buttonComponent={
        <RecordIndexAddRecordInGroupDropdown
          dropdownId="record-table-empty-state-add-button-dropdown"
          clickableComponent={
            <Button
              Icon={IconPlus}
              title={buttonTitle}
              variant={'secondary'}
              onClick={handleButtonClick}
            />
          }
        />
      }
    />
  );
};
