File size: 7,867 Bytes
222a6fa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e73ba60
 
 
 
222a6fa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>FriendlyBot — Match Scheduling</title>
  <link rel="icon" href="/logo.png" />
  <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap" rel="stylesheet" />
  <style>
    :root {
      --bg: #0a0a1a; --surface: #12122a; --surface2: #1a1a3a; --border: rgba(255,255,255,0.08);
      --text: #fff; --text-dim: rgba(255,255,255,0.6); --gold: #FFD700;
      --accent: #5865F2; --radius: 16px; --red: #ED4245;
    }
    * { box-sizing: border-box; margin:0; padding:0; }
    body { font-family: 'Inter', sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; padding: 40px 20px; }
    header { max-width: 800px; margin: 0 auto 40px; display: flex; justify-content: space-between; align-items: center; }
    h1 { font-size: 28px; font-weight: 700; }
    .btn {
      display: inline-block; padding: 10px 20px; background: var(--accent);
      color: #fff; text-decoration: none; border-radius: 8px; font-weight: 600; font-size: 14px; border: none; cursor: pointer;
    }
    .btn-secondary { background: var(--surface2); border: 1px solid var(--border); }
    .container { max-width: 800px; margin: 0 auto; }
    .card {
      background: rgba(18,18,42,0.85); backdrop-filter: blur(8px);
      border: 1px solid var(--border); border-radius: var(--radius);
      padding: 32px; margin-bottom: 30px;
    }
    .card h2 { font-size: 20px; margin-bottom: 12px; }
    .card p { color: var(--text-dim); font-size: 14px; margin-bottom: 24px; }
    
    .config-grid { display: grid; gap: 24px; }
    .input-group label { display: block; font-size: 13px; color: var(--text-dim); margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.5px; }
    input, select {
      width: 100%; padding: 14px; background: var(--surface2); border: 1px solid var(--border);
      border-radius: 10px; color: #fff; font-size: 15px; outline: none; transition: border 0.2s;
    }
    input:focus { border-color: var(--accent); }
    
    .switch { position: relative; display: inline-block; width: 48px; height: 24px; }
    .switch input { opacity: 0; width: 0; height: 0; }
    .slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: var(--surface2); transition: .4s; border-radius: 24px; border: 1px solid var(--border); }
    .slider:before { position: absolute; content: ""; height: 18px; width: 18px; left: 2px; bottom: 2px; background-color: white; transition: .4s; border-radius: 50%; }
    input:checked + .slider { background-color: var(--gold); }
    input:checked + .slider:before { transform: translateX(24px); }

    #guild-selector { margin-bottom: 30px; }
    .server-select { width: 100%; padding: 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); color: #fff; font-size: 16px; font-weight: 600; cursor: pointer; }
    
    .save-bar { position: sticky; bottom: 20px; background: var(--surface); border: 1px solid var(--border); padding: 16px 24px; border-radius: 100px; display: flex; justify-content: space-between; align-items: center; box-shadow: 0 10px 30px rgba(0,0,0,0.5); z-index: 100; }
  </style>
</head>
<body>
  <header>
    <div style="display:flex; align-items:center; gap:16px">
      <div style="font-size:32px">📅</div>
      <h1>Match Scheduling</h1>
    </div>
    <div style="display:flex; gap:10px">
      <a href="/premium" class="btn btn-secondary">Back to Premium</a>
      <a href="/dashboard" class="btn btn-secondary">Dashboard</a>
    </div>
  </header>

  <div class="container">
    <div id="guild-selector">
      <label style="display:block; font-size:13px; color:var(--text-dim); margin-bottom:10px">Select a Server to Configure</label>
      <select id="server-list" class="server-select" onchange="loadConfig(this.value)">
        <option value="">Loading your servers...</option>
      </select>
    </div>

    <div class="card" id="config-card" style="display:none">
      <h2>Premium Match Reminders</h2>
      <p>Configure automated DM reminders for your league matches. Remind your players before the match starts.</p>
      
      <div class="config-grid">
        <div class="input-group">
          <label>Enable DM Reminders</label>
          <div style="display:flex; align-items:center; gap:12px">
            <label class="switch">
              <input type="checkbox" id="config-reminders-enabled" onchange="checkChanges()">
              <span class="slider"></span>
            </label>
            <span style="font-size:14px; color:var(--text-dim)">Send DMs to players on the lineup board</span>
          </div>
        </div>

        <div class="input-group">
          <label>Lead Time (Minutes)</label>
          <input type="number" id="config-reminders-lead" placeholder="30" min="5" max="1440" oninput="checkChanges()">
          <p style="font-size:12px; color:var(--text-dim); margin-top:8px">How many minutes before the match start time should the reminder be sent?</p>
        </div>
      </div>
    </div>
  </div>

  <div class="save-bar" id="save-bar" style="display:none; max-width:800px; margin: 0 auto;">
    <span style="font-size:14px; font-weight:500">You have unsaved changes!</span>
    <button class="btn" onclick="saveConfig()">Save Scheduling Settings</button>
  </div>

  <script>
    let currentGuildId = null;

    async function init() {
      try {
        const serversR = await fetch('/api/servers');
        const serversData = await serversR.json();
        const serverSelect = document.getElementById('server-list');
        const servers = serversData.servers || [];
        
        if (servers.length === 0) {
          serverSelect.innerHTML = '<option value="">No manageable servers found</option>';
          return;
        }

        serverSelect.innerHTML = '<option value="">-- Choose a Server --</option>' + 
          servers.map(s => `<option value="${s.id}">${s.name}</option>`).join('');
      } catch (e) { console.error(e); }
    }

    async function loadConfig(guildId) {
      if (!guildId) {
        document.getElementById('config-card').style.display = 'none';
        document.getElementById('save-bar').style.display = 'none';
        return;
      }

      currentGuildId = guildId;
      document.getElementById('config-card').style.display = 'block';

      try {
        const r = await fetch(`/api/config/${guildId}`);
        const data = await r.json();
        document.getElementById('config-reminders-enabled').checked = !!data.remindersEnabled;
        document.getElementById('config-reminders-lead').value = data.remindersLead || 30;
        document.getElementById('save-bar').style.display = 'none';
      } catch (e) { alert('Failed to load configuration'); }
    }

    function checkChanges() {
      if (!currentGuildId) return;
      document.getElementById('save-bar').style.display = 'flex';
    }

    async function saveConfig() {
      const remindersEnabled = document.getElementById('config-reminders-enabled').checked;
      const remindersLead = parseInt(document.getElementById('config-reminders-lead').value) || 30;

      try {
        const r = await fetch(`/api/config/${currentGuildId}`, {
          method: 'POST',
          headers: { 'Content-Type': 'application/json' },
          body: JSON.stringify({ remindersEnabled, remindersLead })
        });
        const data = await r.json();
        if (data.success) {
          alert('✅ Scheduling settings saved!');
          document.getElementById('save-bar').style.display = 'none';
        } else {
          alert('❌ Error: ' + data.error);
        }
      } catch (e) { alert('❌ Failed to save'); }
    }

    init();
  </script>
</body>
</html>