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 modalId = `result_${result.uri}`; const hasReviews = typeof result.averageRating !== 'undefined' && typeof result.numberOfReviews !== 'undefined'; const buttonHTML = html``; const tabNames = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen', 'twenty']; const modalContent = html`

${__('search.covers')}

${typeof result.covers === 'undefined' ? html`` : html`
${result.covers.map((cover, index) => { return [ html``, // html``, ]; })}
${result.covers.map((cover, index, allCovers) => { return html`
${cover.uri.replace(':', ' ').toUpperCase()}, Published: ${cover.publishDate} ${typeof allCovers[index - 1] === 'undefined' ? null : html`` } ${typeof allCovers[index + 1] === 'undefined' ? null : html`` }
`; })}
` }
${!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')}

`; 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: () => { if (typeof result.covers === 'undefined') { searchController.getCovers(result.uri).then(() => emit('render')); } }, }); }