import { FC, useMemo } from 'react';

import { GenericPostMenu } from 'src/pages/dashboard/feed/components/GenericPostMenu';
import MarketplacePostDelete from 'src/pages/dashboard/marketplace/components/MarketplacePostDelete';
import MarketplacePostEdit from 'src/pages/dashboard/marketplace/components/MarketplacePostEdit';

export type MarketplacePostMenuProps = {
  id: number;
  isDetail?: boolean;
  showEdit: boolean;
  showDelete: boolean;
};

export const MarketplacePostMenu: FC<MarketplacePostMenuProps> = props => {
  const { id, isDetail = false, showEdit, showDelete } = props;

  const menuOptions = useMemo(
    () => [
      {
        id: 'edit-post',
        enabled: showEdit,
        option: <MarketplacePostEdit id={id} />,
        closeOnSelect: true,
      },
      {
        id: 'delete-post',
        enabled: showDelete,
        option: (
          <MarketplacePostDelete
            id={id}
            isDetail={isDetail}
          />
        ),
      },
    ],
    [id, isDetail, showEdit, showDelete],
  );

  return (
    <GenericPostMenu
      id={id}
      menuOptions={menuOptions}
    />
  );
};

export default MarketplacePostMenu;
