getPicrtureItem(picture)).join('');
-
const typeItemsTemplate = ROUTE_TYPE.map((typeItem) => getEventTypeItem(typeItem, state.type, isDisabled)).join('');
const cityItemsTemplate = pointDestinations.get()
.map((point) => point.name)
diff --git a/src/view/filter-view.js b/src/view/filter-view.js
index c71737d..ebf0d18 100644
--- a/src/view/filter-view.js
+++ b/src/view/filter-view.js
@@ -1,23 +1,15 @@
import AbstractView from '../framework/view/abstract-view.js';
-const createFilterItemTemplate = (filter, isChecked) => {
- const {type} = filter;
-
- return (`
-
-
+const createFilterItems = (filter, flag) => (`
+
+
`);
-};
-
-const createFilterTemplate = (filterItems) => {
- const filterItemsTemplate = filterItems.map((filter, index) => createFilterItemTemplate(filter, index === 0)).join('');
- return (`
`);
-};
+const createFilterTemplate = (filters) => (`
`);
export default class FilterView extends AbstractView{
#filters = null;
@@ -25,7 +17,7 @@ export default class FilterView extends AbstractView{
constructor({filters, onFilterTypeChange}) {
super();
- this.#filters = filters;
+ this.#filters = Object.values(filters);
this.#handleFilterTypeChange = onFilterTypeChange;
this.element.querySelectorAll('.trip-filters__filter')
@@ -37,7 +29,7 @@ export default class FilterView extends AbstractView{
}
#filterClickHandler = (evt) => {
- evt.preventDefault();
- this.#handleFilterTypeChange (evt.target.innerHTML);
+ // evt.preventDefault();
+ this.#handleFilterTypeChange(evt.target.innerHTML);
};
}
diff --git a/src/view/trip-info-view.js b/src/view/trip-info-view.js
index e3b00f5..9974235 100644
--- a/src/view/trip-info-view.js
+++ b/src/view/trip-info-view.js
@@ -1,48 +1,66 @@
-import {POINT_EMPTY} from '../mock/const.js';
+import {POINT_EMPTY} from '../const.js';
import {formatToShortDate, formatToDay} from '../utils.js';
import AbstractView from '../framework/view/abstract-view.js';
import dayjs from 'dayjs';
+const getOffersCoast = (offersIds = [], offers = []) => offersIds.reduce(
+ (result, id) => result + (offers.find((offer) => offer.id === id)?.price ?? 0),
+ 0
+);
+
+const getTripCost = (points = [], offers = []) => points.reduce(
+ (result, point) => result + point.basePrice + getOffersCoast(point.offers, offers.find((offer) => point.type === offer.type)?.offers),
+ 0
+);
+
const findDestinationForPoint = (point, pointDestination) =>
pointDestination.find((destination) => destination.id === point.destination);
-const createDestinationElement = (pointDestination) =>
- pointDestination.length <= 3
- ? pointDestination.map((destination) => (`${destination} - `)).join('').slice(0, -2)
- : `${pointDestination[0]} - ... - ${pointDestination[pointDestination.length - 1]}`;
+const createDestinationElement = (destinations) =>
+ destinations.length <= 3
+ ? destinations.map((destination) => (`${destination} - `)).join('').slice(0, -2)
+ : `${destinations[0]} - ... - ${destinations[destinations.length - 1]}`;
-const createTripInfoTemplate = ({points, pointDestination}) => (`
+const createTripInfoTemplate = ({points, destination, isEmpty, cost}) =>
+ (`${!isEmpty
+ ? `
-
${createDestinationElement(pointDestination)}
+
${createDestinationElement(destination)}
${formatToShortDate(points[0].dateFrom)} —
${dayjs(points[points.length - 1].dateTo).month() === dayjs(points[0].dateFrom).month()
- ? formatToDay(points[points.length - 1].dateTo)
- : formatToShortDate(points[points.length - 1].dateTo)}
+ ? formatToDay(points[points.length - 1].dateTo)
+ : formatToShortDate(points[points.length - 1].dateTo)}
Total: €
- ${points.reduce((x, point) => (x + point.basePrice), 0)}
+ ${cost}
- `);
+ `
+ : ''
+ }`);
export default class TripInfoView extends AbstractView {
- #points = null;
- #pointDestination = [];
+ #points = 0;
+ #destination = [];
+ #offers = [];
- constructor({points = POINT_EMPTY, pointDestination}) {
+ constructor({points = POINT_EMPTY, destinations, offers}) {
super();
this.#points = points;
- this.#pointDestination = points
- .map((point) => findDestinationForPoint(point, pointDestination))
+ this.#offers = offers;
+ this.#destination = points
+ .map((point) => findDestinationForPoint(point, destinations))
.map((destination) => destination.name);
}
get template() {
return createTripInfoTemplate({
points: this.#points,
- pointDestination: this.#pointDestination,
+ destination: this.#destination,
+ isEmpty: this.#points.length === 0,
+ cost: getTripCost(this.#points, this.#offers)
});
}
}