import { h } from 'preact';
import { ExternalLink, Check } from 'react-feather';
import { useState } from 'preact/hooks';
import _ from 'lodash'
import { useSelector, useDispatch } from 'react-redux'
import { State } from './../store';
import http from '../http';
function OfferLine(offer) {
const ws = useSelector((state: State) => state.ws);
function setStatus(status) {
ws.sendOfferStatusSet(offer.id, status);
}
const accepted = offer.status === 'Accepted';
const classes = `${accepted ? 'accepted' : ''}`;
const btnText = accepted
? offer.status
: 'Accept';
const negBtn = accepted
?
: ;
return (
${offer.total}
{offer.condition}
{negBtn}
)
}
function OfferPriceBtn(offer) {
const ws = useSelector((state: State) => state.ws);
const accepted = offer.status === 'Accepted';
const confirmed = offer.status === 'Confirmed';
function setStatus() {
if (accepted) return ws.sendOfferStatusSet(offer.id, 'Pending')
ws.sendOfferStatusSet(offer.id, 'Accepted');
}
const classes = `${accepted ? 'accepted' : ''} ${confirmed ? 'confirmed' : ''}`;
const btnText = accepted
? offer.status
: 'Accept';
const title = accepted
? 'Click to cancel'
: 'Click to accept this offer';
return (
)
}
function OfferConditionSlider([condition, offers], i, groupId, rangeMin, rangeMax) {
// const ws = useSelector((state: State) => state.ws);
// const accepted = offer.status === 'Accepted';
// const confirmed = offer.status === 'Confirmed';
// function setStatus() {
// if (accepted) return ws.sendOfferStatusSet(offer.id, 'Pending')
// ws.sendOfferStatusSet(offer.id, 'Accepted');
// }
// const classes = `${accepted ? 'accepted' : ''} ${confirmed ? 'confirmed' : ''}`;
// const btnText = accepted
// ? offer.status
// : 'Accept';
// const title = accepted
// ? 'Click to cancel'
// : 'Click to accept this offer';
// return (
//
// )
const min = _.first(offers).total
const max = _.last(offers).total
// const step = min === max ? max : "any"
const step = 'any'
const id = `${groupId}-${i}`
const markersId = `${id}-markers`
const steps = offers.map(o => o.total)
const [acceptedPrice, setAcceptedPrice] = useState(0)
function onChange(target) {
const highest = () => {
return _.findLast(steps, s => target.value >= Number(s)) || 0
}
const v = highest()
setAcceptedPrice(v)
target.value = v
}
const acceptedPriceLabel = acceptedPrice ? `$${acceptedPrice}` : '-'
return (
onChange((e.target as HTMLInputElement)) } />
)
}
export default function OfferGroup(group, i) {
const ws = useSelector((state: State) => state.ws);
const format = group.details.formats[0].text ? `${group.details.formats[0].text} - ` : '';
const descriptions = group.details.formats.map(f => f.descriptions.join(' ')).join(' ')
const detailText = `${format} ${descriptions}`;
const conditions = Object.entries(_.groupBy(group.offers, 'condition'))
const rangeMin = 0
const rangeMax = _.maxBy(group.offers, 'total').total
return (
{group.details.artists_sort} - {group.details.title}
{group.details.year} - {detailText}
Status: {group.status}
{conditions.map((c, i) => OfferConditionSlider(c, i, group.details.id, rangeMin, rangeMax))}
)
}