import { LoadType, ReportType } from '../types/UserReports.js';
import localsHelper, { getRouteLocals } from './localsHelper.js';
import { setNestedPath } from './urlHelper.js';

const getTypeTagColor = (type) => {
    let tagColourClass = '';
    switch (type) {
        case ReportType.DASHBOARD:
            tagColourClass = 'govuk-tag--purple';
            break;
        case ReportType.UNAVAILABLE:
            tagColourClass = 'govuk-tag--grey';
            break;
        default:
            tagColourClass = '';
            break;
    }
    return tagColourClass;
};
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 === 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}</br>${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.getValues(res);
    const { nestedBaseUrl } = getRouteLocals(res);
    const rootPath = 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 === LoadType.SYNC) {
            href = `${rootPath}/view-report/sync/${type}/${reportId}/${id}/load-report${dpdPathQueryParam}`;
        }
    }
    return href;
};

export { createListActions, createListItemProductMin, setInitialHref, toSentenceCase };
//# sourceMappingURL=reportListsHelper.js.map
