terminusWidget = ({value = '', status = 'No Database Selected'} = {}) => {
const output = htl.html`<output>`;
const create = htl.html`<button onclick=${() => dbAction('create', node, value)}>CREATE</button>`
const clear = htl.html`<button onclick=${() => dbAction('clear', node, value)}>CLEAR</button>`
const del = htl.html`<button onclick=${() => dbAction('delete', node, value)}>DELETE</button>`
if (databases.length > 0) value = databases[databases.length-1].id
const node = htl.html`
<style>${style}</style>
<div class="terminus-widget">
<div class="terminus-header">
<img src="https://terminusdb.com//img/logos/logo.svg" alt="Terminus DB"/>
</div>
<div class='form'>
<label>Select or Create Database</label>
<div class="input">
<input placeholder="Database Name" value="${value}" type="text" autocomplete="off" list="terminus-db-list" oninput=${(e) => set(node, e.target.value)}></input>
<datalist id="terminus-db-list">
${databases.map(d => Object.assign(html`<option>${d.label}</option>`, { value: d.id }))}
</datalist>
</div>
<div>
${create}
${clear}
${del}
</div>
</div>
<div class="terminus-status">
${output}
</div>
</div>`;
Object.defineProperty(node, "value", {
get() {
return value;
},
set(v) {
value = v;
if (!value) {
create.setAttribute('disabled', '')
clear.setAttribute('disabled', '')
del.setAttribute('disabled', '')
} else if (databases.find(({id}) => id === value) != null) {
create.setAttribute('disabled', '')
clear.removeAttribute('disabled')
del.removeAttribute('disabled')
} else {
create.removeAttribute('disabled')
clear.setAttribute('disabled', '')
del.setAttribute('disabled', '')
}
}
});
Object.defineProperty(node, "status", {
get() {
return status;
},
set(s) {
output.value = status = s;
}
});
node.value = value;
node.status = status;
if (databases.length > 0) set(node, databases[databases.length-1].id)
return node;
}