package templates import ( "fmt" "veola/internal/models" ) type ItemFormData struct { Page IsEdit bool Item models.Item Categories []string Errors []string } func itemSelected(have, want string) bool { return have == want } type selectOpt struct { Value string Label string } // conditionOptions are the eBay-only item-condition filters. Values match the // vocabulary mapped to Browse API condition IDs in internal/ebay. func conditionOptions() []selectOpt { return []selectOpt{ {"", "— any —"}, {"new", "New"}, {"used", "Used"}, {"refurbished", "Refurbished"}, {"parts", "For parts / not working"}, } } // regionOptions are the eBay-only item-location filters, keyed by ISO 3166-1 // alpha-2 country code (the value the Browse API itemLocationCountry filter // expects). func regionOptions() []selectOpt { return []selectOpt{ {"", "— any —"}, {"US", "United States"}, {"GB", "United Kingdom"}, {"DE", "Germany"}, {"FR", "France"}, {"IT", "Italy"}, {"ES", "Spain"}, {"CA", "Canada"}, {"AU", "Australia"}, {"JP", "Japan"}, {"CN", "China"}, {"HK", "Hong Kong"}, } } type marketplaceOpt struct { Value string Label string } func marketplaceOptions() []marketplaceOpt { return []marketplaceOpt{ {"ebay.com", "eBay (US)"}, {"ebay.co.uk", "eBay (UK)"}, {"ebay.de", "eBay (DE)"}, {"ebay.fr", "eBay (FR)"}, {"ebay.com.au", "eBay (AU)"}, {"ebay.ca", "eBay (CA)"}, {"yahoo.co.jp", "Yahoo Auctions JP"}, {"mercari.jp", "Mercari JP"}, } } func isKnownMarketplace(v string) bool { for _, o := range marketplaceOptions() { if o.Value == v { return true } } return false } func itemHasMarketplace(it models.Item, v string) bool { for _, m := range it.Marketplaces { if m == v { return true } } return false } // customMarketplacesCSV returns the comma-separated list of marketplaces on // the item that are NOT in the curated list, so the user can keep editing // unusual values without losing them. func customMarketplacesCSV(it models.Item) string { var custom []string for _, m := range it.Marketplaces { if !isKnownMarketplace(m) { custom = append(custom, m) } } return joinCSV(custom) } func joinCSV(vs []string) string { out := "" for i, v := range vs { if i > 0 { out += ", " } out += v } return out } func itemHasJapanMarketplace(it models.Item) bool { for _, m := range it.Marketplaces { if m == "yahoo.co.jp" || m == "mercari.jp" { return true } } return false } func newCategory(v string, known []string) string { if v == "" { return "" } for _, c := range known { if c == v { return "" } } return v } templ itemFormBody(d ItemFormData) {