File size: 3,772 Bytes
1602335
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
class CustomDecisionNode extends HTMLElement {
    constructor() {
        super();
        this.answerOptions = ['Yes', 'No'];
    }

    connectedCallback() {
        const nodeId = this.getAttribute('node-id') || `node-${Math.random().toString(36).substr(2, 9)}`;
        this.setAttribute('node-id', nodeId);
        const isRoot = this.hasAttribute('is-root');

        this.attachShadow({ mode: 'open' });
        this.shadowRoot.innerHTML = `
            <style>
                .node-card {
                    transition: all 0.2s;
                    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
                }
                
                .node-card:hover {
                    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
                }
                
                .answer-btn {
                    transition: all 0.2s;
                }
                
                .answer-btn:hover {
                    transform: translateY(-2px);
                    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
                }
                
                .tooltip {
                    visibility: hidden;
                    opacity: 0;
                    transition: opacity 0.2s;
                }
                
                .tooltip-btn:hover + .tooltip {
                    visibility: visible;
                    opacity: 1;
                }
            </style>
            <div class="node-card bg-white rounded-lg border border-gray-200 overflow-hidden">
                <div class="p-4">
                    <div class="flex justify-between items-start mb-3">
                        <h3 class="text-lg font-medium text-gray-800">${isRoot ? 'Root Question' : 'Decision Point'}</h3>
                        <div class="flex space-x-2 relative">
                            <button class="tooltip-btn text-gray-500 hover:text-gray-700 p-1 rounded-full">
                                <i data-feather="more-vertical" class="w-4 h-4"></i>
                            </button>
                            <div class="tooltip absolute right-0 mt-6 w-48 bg-white rounded-md shadow-lg z-10 py-1">
                                <button onclick="deleteNode('${nodeId}')" class="flex items-center px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 w-full text-left">
                                    <i data-feather="trash-2" class="w-4 h-4 mr-2"></i> Delete
                                </button>
                            </div>
                        </div>
                    </div>
                    
                    <input type="text" placeholder="Enter your question..." class="w-full px-3 py-2 border border-gray-300 rounded-md mb-4 focus:outline-none focus:ring-2 focus:ring-indigo-500">
                    
                    <div class="flex flex-wrap gap-2 mb-2">
                        ${this.answerOptions.map(answer => `
                            <button onclick="addChildNode('${nodeId}', '${answer}')" class="answer-btn bg-indigo-100 text-indigo-700 px-3 py-1 rounded-full text-sm font-medium flex items-center">
                                <i data-feather="plus" class="w-3 h-3 mr-1"></i> ${answer}
                            </button>
                        `).join('')}
                    </div>
                </div>
                
                <div class="children-container bg-gray-50 p-4 border-t border-gray-200"></div>
            </div>
        `;
        
        // Replace feather icons after rendering
        setTimeout(() => {
            if (this.shadowRoot.querySelector('[data-feather]')) {
                feather.replace({ class: 'inline-block', width: 16, height: 16 });
            }
        }, 0);
    }
}

customElements.define('custom-decision-node', CustomDecisionNode);