{
    Author: Hert van Zwietering
    Initial Date: 5 may 2020

    Version history:
        1.0
            5 may 2020;
            initial version
}

  function HandleImageItem(AImageItem: TImageItem): Boolean;
  begin
    result := PublicCatalog.ImageHasRecipe(AImageItem);

    if result then
    begin
      PublicCatalog.RemoveRecipeForImage(AImageItem);
      PublicBroadcastObjectText(nil, 'BuildThumbnailFor', AImageItem, nil, nil, '');
    end;
  end;

var
  AHit, i: Integer;
  AProgress: TxomProgress;
begin
  if Selected.Count = 0 then
  begin
    Say ('No images selected');
    exit;
  end;

  if not Ask ('This script will clean up all recipes for the ' + IntToStr(Selected.Count) + ' selected thumbnails.' + CrLf2 + 'Are you sure you want to continue?') then
    exit;

  AProgress := TxomProgress.Create(nil);
  try
    AProgress.Caption := 'Recipe Cleansing';
    AProgress.Cancel := False;
    AProgress.ProgressBar := True;
    AProgress.Max := Selected.Count;
    AProgress.Show;

    AHit := 0;
    for i := 0 to Selected.Count - 1 do
    begin
      AProgress.ProgressText := Selected.Items[i].FileName;
      AProgress.Pos := i + 1;
      if AProgress.Cancel then
        break;

      if HandleImageItem(Selected.Items[i]) then
        AHit := AHit + 1;
    end;

    AProgress.Hide;
    if AProgress.Cancel then
      Say('Cancelled')
    else
      Say('Done');
  finally
    AProgress.Free;
  end;
end;

