function [] = setPlotHandleVisibility(pHandles, pVisible)
%HIDEORSHOWHANDLES Summary of this function goes here
%   Detailed explanation goes here

%% Parameter check
if ~islogical(pVisible)
    warning('Parameter pVisible needs to be logical. Skipping...');
    return;
end

%% Check data structure
if iscell(pHandles)
    processCell(pHandles);
    return;
end

if isstruct(pHandles)
    processStruct(pHandles);
    return;
end

if all(ishandle(pHandles)) && length(pHandles) > 1
    processHandleArray(pHandles);
    return;
end

%% Check if handle is valid
if isempty(pHandles) || ~isvalid(pHandles)
    return;
end

%% Set visibility
if pVisible
    pHandles.Visible = 'on';
else
    pHandles.Visible = 'off';
end

    function processCell(pCell)
        for i = 1:length(pCell)
            artoa.controller.setPlotHandleVisibility(pCell{i}, pVisible);
        end
    end

    function processStruct(pHandles)
        fnames = fieldnames(pHandles);
        for oFnames = 1:length(fnames)
            artoa.controller.setPlotHandleVisibility(pHandles.(fnames{oFnames}), pVisible);
        end
    end

    function processHandleArray(pHandleArray)
        for i = 1:length(pHandleArray)
            artoa.controller.setPlotHandleVisibility(pHandleArray(i), pVisible);
        end
    end

end

