import html from 'choo/html'; import { reviewCard } from '../partials/reviewCard'; import { starRating } from '../partials/starRating'; import { modal } from '../partials/modal'; export const resultDetails = (searchController, result, emit = () => {}) => { const { __ } = searchController.i18n; const source = result.sources[0]; const modalId = `result_${source.uri}`; const hasReviews = typeof result.averageRating !== 'undefined' && typeof result.numberOfReviews !== 'undefined'; const buttonHTML = html``; const coversHTMLArray = result.covers.map((cover, index, allCovers) => { return html`
${cover.sourceId.replace(':', ' ').toUpperCase()}, Published: ${cover.publishDate} ${typeof allCovers[index - 1] === 'undefined' ? null : html`` } ${typeof allCovers[index + 1] === 'undefined' ? null : html`` }
`; }); const modalContent = html`

${__('search.covers')}

${typeof result.covers === 'undefined' ? html`` : html`
${result.covers.map((cover, index) => { return [ html``, // html``, ]; })}
${ searchController.openModal === modalId ? coversHTMLArray : '' /* Leave the covers column empty until opened to prevent loading too many images */ }
` }
${!hasReviews ? html`

${__('search.no_reviews')}

` : html`

${__('interaction.average_rating')}

${starRating(result.averageRating)} ${(typeof result.reviews !== 'undefined' && Array.isArray(result.reviews) ? result.reviews : []).map(review => { return reviewCard(searchController, review); })}` }

${!searchController.showShelves ? null : html``}

${__('search.see_book_details')}

`; const onShow = () => { const coversColumn = document.getElementById(`covers_${modalId}`); coversColumn.innerHTML = ''; coversHTMLArray.forEach(element => coversColumn.appendChild(element)); }; return modal(modalId, searchController, modalContent, { styles: "width:90%;", buttonHTML, // This should be replaced with buttonHTML containing the ratings and number of reviews etc. headerText: result.name, onShow, }); }