'use strict';

var UserReports = require('../types/UserReports.js');
var localsHelper = require('./localsHelper.js');
var urlHelper = require('./urlHelper.js');

const itemActionsHtml = (retryHref, executionId, type, status) => {
    const text = status === UserReports.RequestStatus.EXPIRED ? 'Refresh' : 'Retry';
    return `<div class="dpr-icon-wrapper__item-actions">
      <a class='govuk-link dpr-user-list-action govuk-link--no-visited-state govuk-!-margin-bottom-1' href="${retryHref}">${text}</a>
      <a class="govuk-link dpr-user-list-action govuk-link--no-visited-state dpr-remove-${type}-report-button"" href="#" data-execution-id='${executionId}'>Remove</a>
    </div>`;
};
const getTypeTagColor = (type) => {
    let tagColourClass = '';
    switch (type) {
        case UserReports.ReportType.DASHBOARD:
            tagColourClass = 'govuk-tag--purple';
            break;
        case UserReports.ReportType.UNAVAILABLE:
            tagColourClass = 'govuk-tag--grey';
            break;
        default:
            tagColourClass = '';
            break;
    }
    return tagColourClass;
};
const createListItemProduct = (productName, reportName, type, ts) => {
    const tsClass = !ts ? 'dpr-display-none' : '';
    const tagColor = getTypeTagColor(type);
    const reportType = toSentenceCase(type);
    return `<div>
  <p class="govuk-body govuk-!-margin-bottom-1" aria-label="Report name ${reportName}"><strong>${reportName}</strong></p>
  <p class="govuk-body-s govuk-!-margin-bottom-3" aria-label="Product name ${productName}">${productName}</p>
  <strong class="govuk-tag ${tagColor} dpr-request-status-tag--small govuk-!-margin-bottom-4" aria-label="Report type ${reportType}">${reportType}</strong>
  <p class="govuk-body-xs govuk-!-margin-bottom-0 govuk-!-margin-top-3 ${tsClass}" aria-label="Timestamp">${ts}</p>
</div>`;
};
const createListItemProductMin = (reportName, type) => {
    const tagColor = getTypeTagColor(type);
    const reportType = toSentenceCase(type);
    return `<div>
  <p class="govuk-body-s govuk-!-margin-bottom-2"><strong>${reportName}</strong></p>
  <strong class="govuk-tag ${tagColor} dpr-request-status-tag--small">${reportType}</strong>
</div>`;
};
const createListActions = (href, type, loadType, bookmarkHtml, authorised = true, missing = false) => {
    if (!authorised) {
        return `<strong class="govuk-tag govuk-tag--red dpr-request-status-tag dpr-request-status-tag--small dpr-unauthorised-report" aria-label="You are unauthorised to view this report">Unauthorised</strong>`;
    }
    let requestAction;
    let actionText;
    if (missing) {
        actionText = `Request report`;
        requestAction = `<a class='govuk-link dpr-user-list-action govuk-link--no-visited-state govuk-!-margin-bottom-1' href="${href}">${actionText}</a>`;
    }
    else {
        actionText = `Request ${type}`;
        if (loadType && loadType === UserReports.LoadType.SYNC) {
            actionText = `Load ${type}`;
        }
        requestAction = `<a class='govuk-link dpr-user-list-action govuk-link--no-visited-state govuk-!-margin-bottom-1 dpr-live-report dpr-type__${type}' href="${href}">${actionText}</a>`;
    }
    if (bookmarkHtml) {
        requestAction = `${requestAction}${bookmarkHtml}`;
    }
    return requestAction;
};
const toSentenceCase = (text) => {
    return text.charAt(0).toUpperCase() + text.substring(1).toLowerCase();
};
const setInitialHref = (loadType, type, reportId, id, res, isMissing = false) => {
    const { pathSuffix, dpdPathFromQuery } = localsHelper.default.getValues(res);
    const { nestedBaseUrl } = localsHelper.getRouteLocals(res);
    const rootPath = urlHelper.setNestedPath(`/dpr`, nestedBaseUrl);
    let href = '';
    if (isMissing) {
        href = `${rootPath}/request-missing-report/${reportId}/${id}/form`;
    }
    else {
        const dpdPathQueryParam = dpdPathFromQuery ? pathSuffix : '';
        href = `${rootPath}/request-report/${type}/${reportId}/${id}/filters${dpdPathQueryParam}`;
        if (loadType && loadType === UserReports.LoadType.SYNC) {
            href = `${rootPath}/view-report/sync/${type}/${reportId}/${id}/load-report${dpdPathQueryParam}`;
        }
    }
    return href;
};

exports.createListActions = createListActions;
exports.createListItemProduct = createListItemProduct;
exports.createListItemProductMin = createListItemProductMin;
exports.itemActionsHtml = itemActionsHtml;
exports.setInitialHref = setInitialHref;
exports.toSentenceCase = toSentenceCase;
//# sourceMappingURL=reportListsHelper.js.map
