import {OOElement} from '../oo-element' import {html} from '../../lib/html' import badge from '../_atoms/oo-atoms-badge' import offerModal from '../_organisms/oo-organisms-ask-modal' import define from '../../lib/define' import weakMap from '../../lib/weak-map' import {asTags, asScope} from '../../lib/as' import {Scope} from '../../type/scope' define('oo-atoms-badge', badge) define('oo-organisms-ask-modal', offerModal) type Size = 'small' | 'medium' type Type = 'ask' | 'offer' const ATTR = { DATA_SIZE: 'data-size', DATA_IAM: 'data-iam', DATA_TAGS: 'data-tags', DATA_SCOPE: 'data-scope', DATA_TYPE: 'data-type' } const asSize = (data: string): Size => { if (data === 'small' || data === 'medium') { return data } return 'medium' } const asType = (data: string): Type => { if (data === 'ask' || data === 'offer') { return data } return 'ask' } const iam = weakMap() const size = weakMap() const open = weakMap() const type = weakMap() const tags = weakMap>() const scope = weakMap() export default class extends OOElement { static get observedAttributes() { return [ATTR.DATA_SIZE, ATTR.DATA_IAM, ATTR.DATA_TAGS, ATTR.DATA_TYPE, ATTR.DATA_SCOPE] } constructor() { super() open.set(this, false) type.set(this, 'ask') } attributeChangedCallback(attr, prev, next) { if (prev === next) { return } switch(attr) { case ATTR.DATA_SIZE: size.set(this, asSize(next)) break case ATTR.DATA_IAM: if (!next) { return } iam.set(this, next) break case ATTR.DATA_TAGS: tags.set(this, asTags(next)) break case ATTR.DATA_SCOPE: scope.set(this, asScope(next)) break case ATTR.DATA_TYPE: type.set(this, asType(next)) break default: break } if (this.connected) { this.update() } } render() { if (!iam.get(this)) { return } const {s, i, o, t, g = [], c} = { s: size.get(this), i: iam.get(this), o: open.get(this), t: type.get(this), g: tags.get(this), c: scope.get(this) } const label = `${t} me` return html` ${(() => { if (o) { return html` ` } return html`` })()} ` } onClickButton() { open.set(this, !open.get(this)) this.update() } onModalClose() { open.set(this, false) this.update() } }