function hh = zlabel(varargin)
%ZLABEL Z-axis label.
%   ZLABEL('text') adds text beside the Z-axis on the current axes.
%
%   ZLABEL('text','Property1',PropertyValue1,'Property2',PropertyValue2,...)
%   sets the values of the specified properties of the zlabel.
%
%   ZLABEL(AX,...) adds the zlabel to the specified axes.
%
%   H = ZLABEL(...) returns the handle to the text object used as the label.
%
%   See also XLABEL, YLABEL, TITLE, TEXT.

%   Copyright 1984-2019 The MathWorks, Inc.

if nargout>0
    [isaxarr,hh]=matlab.graphics.chart.internal.objArrayDispatch(@zlabel,varargin{:});
else
    isaxarr=matlab.graphics.chart.internal.objArrayDispatch(@zlabel,varargin{:});
end
if isaxarr
    return
end

% if the input has a zlabel property which is a text object, use it to set
% the zlabel on.
try
[ax,args,nargs] = plotedit({'labelcheck','ZLabel',varargin});
catch ME
    throw(ME);
end

if nargs == 0 || (nargs > 1 && (rem(nargs-1,2) ~= 0))
  error(message('MATLAB:zlabel:InvalidNumberOfInputs'))
end

if isempty(ax)
    ax = gca;
    
    % Chart subclass support
    % Invoke zlabel method with same number of outputs to defer output arg
    % error handling to the method.
    if isa(ax,'matlab.graphics.chart.Chart')
        if(nargout == 1)
            hh = zlabel(ax,args{:});
        else
            zlabel(ax,args{:});
        end
        return
    end
end

if isa(ax,'matlab.graphics.axis.GeographicAxes')
   error(message('MATLAB:Chart:UnsupportedConvenienceFunction', 'zlabel', ax.Type)); 
end

string = args{1};
if isempty(string), string=''; end
pvpairs = args(2:end);

% get-set does not support strings as of now
pvpairs = matlab.graphics.internal.convertStringToCharArgs(pvpairs);

if isappdata(ax,'MWBYPASS_zlabel')
    fcn = getappdata(ax,'MWBYPASS_zlabel');
    h = feval(fcn{:},string,pvpairs{:});

  %---Standard behavior
else
    h = get(ax,'ZLabel');
    if ~isa(ax,'matlab.graphics.layout.Layout')
        set(h,'FontSizeMode','auto',...
            'FontUnitsMode','auto',...
            'FontWeight',get(ax,'FontWeight'),...
            'FontAngle',get(ax,'FontAngle'),...
            'FontName',get(ax,'FontName'));
    end
    set(h, 'String', string, pvpairs{:});
   
end

if nargout > 0
  hh = h;
end
