import Elementary import Persistence /// The seller's answer to an open offer: accept or decline, each a form. struct AnswerOffer: HTML { // MARK: Properties /// The offer answered. let offer: Offer /// The path to return to afterwards; accepting leads to the sale record instead. let returnPath: String // MARK: Computed var body: some HTML { form( .class("answer"), .action(.Route.answer(offer: offer.id)), .method(.post) ) { input( .type(.hidden), .name("return"), .value(returnPath) ) button( .class("button button--primary button--sm"), .type(.submit), .name("answer"), .custom(name: "value", value: "accept") ) { "Accept" } button( .class("button button--sm"), .type(.submit), .name("answer"), .custom(name: "value", value: "decline") ) { "Decline" } } } } // MARK: - Extensions extension Offer.Status { // MARK: Computed /// The status in a word. var label: String { switch self { case .open: "Open" case .accepted: "Accepted" case .declined: "Declined" case .expired: "Expired" } } /// The chip colouring for the status. var tone: Chip.Tone { switch self { case .open: .warn case .accepted: .good case .declined: .bad case .expired: .neutral } } }