<?php declare(strict_types = 0);
$widget = (new CWidget())
->setTitle(_('API tokens'))
->setTitleSubmenu(getUserSettingsSubmenu());
$token_form = (new CForm())
->setAttribute('aria-labelledby', ZBX_STYLE_PAGE_TITLE);
$token_from_list = (new CFormList())
->addRow(_('Name').':', $data['name'])
->addRow(_('Auth token').':', [
_("Make sure to copy the auth token as you won't be able to view it after the page is closed.")
(new CLinkAction(_('Copy to clipboard')))
->onClick('writeTextClipboard("'.$data['auth_token'].'")')
->setAttribute('autofocus', 'autofocus')
->addRow(_('Expires at').':', [
($data['expires_at'] == 0) ? '-' : date(DATE_TIME_FORMAT_SECONDS, (int) $data['expires_at']),
($data['expires_at'] != 0 && time() > $data['expires_at'])
? [NBSP(), makeErrorIcon(_('The token has expired. Please update the expiry date to use the token.'))]
->addRow(_('Description').':', (new CDiv($data['description']))->addClass(ZBX_STYLE_WORDBREAK))
->addRow(new CLabel(_('Enabled').':', 'enabled'),
(new CCheckBox('enabled'))
->setChecked($data['status'] == ZBX_AUTH_TOKEN_ENABLED)
$token_view = (new CTabView())->addTab('token', '', $token_from_list);
$token_view->setFooter(makeFormFooter((new CRedirectButton(_('Close'), (new CUrl('zabbix.php'))
->setArgument('action', 'user.token.list')
->setArgument('page', CPagerHelper::loadPage('user.token.list', null))
$token_form->addItem($token_view);