File size: 3,311 Bytes
921d377
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import React, { useState } from 'react';
import { AgeVerificationModal } from './AgeVerificationModal';
/**
 * Content Rating Toggle
 *
 * A prominent toggle switch in the header that controls SFW/Mature mode.
 * Switching to Mature requires age verification.
 */
export const ContentRatingToggle = ({ contentRating, onRatingChange, disabled = false, }) => {
    const [showVerification, setShowVerification] = useState(false);
    const isMature = contentRating === 'mature';
    const handleToggle = () => {
        if (disabled)
            return;
        if (isMature) {
            // Switching back to SFW - no verification needed
            onRatingChange('sfw');
        }
        else {
            // Switching to Mature - show verification
            setShowVerification(true);
        }
    };
    const handleVerified = () => {
        setShowVerification(false);
        onRatingChange('mature');
    };
    return (<>
      <div className="content-rating-toggle">
        <button className={`toggle-option ${!isMature ? 'active' : ''}`} onClick={() => isMature && handleToggle()} disabled={disabled}>
          <span className="toggle-icon">&#10003;</span>
          SFW
        </button>
        <button className={`toggle-option ${isMature ? 'active mature' : ''}`} onClick={() => !isMature && handleToggle()} disabled={disabled}>
          <span className="toggle-icon">&#128286;</span>
          MATURE
        </button>

        <div className={`toggle-slider ${isMature ? 'mature' : 'sfw'}`} style={{
            transform: isMature ? 'translateX(100%)' : 'translateX(0)',
        }}/>
      </div>

      {showVerification && (<AgeVerificationModal onConfirm={handleVerified} onCancel={() => setShowVerification(false)}/>)}

      <style>{`
        .content-rating-toggle {
          display: flex;
          position: relative;
          background: var(--color-surface);
          border: 1px solid var(--color-border);
          border-radius: 8px;
          padding: 4px;
          gap: 0;
        }

        .toggle-option {
          position: relative;
          z-index: 1;
          padding: 8px 16px;
          border: none;
          background: transparent;
          color: var(--color-text-muted);
          font-weight: 500;
          font-size: 14px;
          cursor: pointer;
          transition: color 0.2s;
          display: flex;
          align-items: center;
          gap: 6px;
          min-width: 90px;
          justify-content: center;
        }

        .toggle-option:disabled {
          cursor: not-allowed;
          opacity: 0.5;
        }

        .toggle-option.active {
          color: var(--color-text);
        }

        .toggle-option.active.mature {
          color: #F59E0B;
        }

        .toggle-icon {
          font-size: 12px;
        }

        .toggle-slider {
          position: absolute;
          top: 4px;
          left: 4px;
          width: calc(50% - 4px);
          height: calc(100% - 8px);
          border-radius: 6px;
          transition: transform 0.3s ease, background 0.3s ease;
        }

        .toggle-slider.sfw {
          background: var(--color-success);
        }

        .toggle-slider.mature {
          background: linear-gradient(135deg, #8B5CF6, #F59E0B);
        }
      `}</style>
    </>);
};