File size: 16,808 Bytes
1cc3d93
3eca49b
 
 
7223b58
1cc3d93
8e44f4a
7223b58
1cc3d93
bed7072
3eca49b
c396ba0
bed7072
 
cbe5bb0
bed7072
b1d7840
20f8e94
8e44f4a
bed7072
8e44f4a
bed7072
 
f434c62
 
bed7072
8e44f4a
20f8e94
77eebc9
bed7072
77eebc9
bed7072
 
8e44f4a
 
 
 
bed7072
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20f8e94
cbe5bb0
bed7072
cbe5bb0
bed7072
f434c62
8e44f4a
cbe5bb0
bed7072
 
 
 
cbe5bb0
 
bed7072
 
d6518ad
bed7072
 
 
 
 
 
 
 
 
cbe5bb0
8e44f4a
bed7072
 
 
 
 
 
 
8e44f4a
bed7072
 
8e44f4a
d6518ad
cbe5bb0
bed7072
cbe5bb0
bed7072
 
 
20f8e94
8e44f4a
77eebc9
bed7072
 
 
d6518ad
bed7072
 
3c03c16
bed7072
8e44f4a
bed7072
 
3c03c16
 
bed7072
6b429fa
bed7072
 
3c03c16
6b429fa
bed7072
5ccfed0
1cc3d93
 
bed7072
3eca49b
 
 
 
 
 
7c14877
 
 
 
 
3eca49b
b1d7840
3eca49b
 
eed94a5
b1d7840
3eca49b
6b7635f
3eca49b
6b429fa
 
7c14877
 
3c03c16
eed94a5
77eebc9
eed94a5
20f8e94
6b429fa
eed94a5
20f8e94
 
 
 
 
 
 
 
6b429fa
 
77eebc9
bed7072
41787c3
20f8e94
eed94a5
20f8e94
77eebc9
bed7072
3eca49b
77eebc9
8e44f4a
20f8e94
3c03c16
77eebc9
3c03c16
77eebc9
0bbb266
b1d7840
0bbb266
bed7072
 
 
5148f08
bed7072
 
 
77eebc9
bed7072
 
 
 
 
b1d7840
bed7072
77eebc9
bed7072
 
 
77eebc9
20f8e94
 
 
bed7072
77eebc9
bed7072
 
 
 
 
20f8e94
 
bed7072
50bca68
bed7072
 
77eebc9
bed7072
 
 
77eebc9
bed7072
77eebc9
bed7072
 
77eebc9
 
 
1dda8db
bed7072
 
 
20f8e94
cbbaf1a
bed7072
77eebc9
bed7072
 
 
 
 
 
77eebc9
 
 
 
 
 
 
8e44f4a
77eebc9
 
 
 
 
bed7072
20f8e94
bed7072
 
 
 
 
 
77eebc9
 
20f8e94
bed7072
 
77eebc9
 
eed94a5
 
20f8e94
bed7072
 
 
7223b58
8e44f4a
bed7072
20f8e94
7223b58
bed7072
eed94a5
3c03c16
eed94a5
bed7072
77eebc9
bed7072
3eca49b
bed7072
20f8e94
41787c3
bed7072
9da3382
20f8e94
77eebc9
20f8e94
 
 
3c03c16
20f8e94
bed7072
41787c3
bed7072
 
7223b58
20f8e94
41787c3
bed7072
20f8e94
8e44f4a
bed7072
20f8e94
bed7072
 
 
 
20f8e94
 
7223b58
 
3eca49b
bed7072
20f8e94
 
bed7072
20f8e94
b1d7840
bed7072
 
 
 
6b7635f
7223b58
bed7072
 
7223b58
bed7072
 
77eebc9
bed7072
 
 
 
7223b58
bed7072
20f8e94
eed94a5
 
 
 
20f8e94
6b7635f
8e44f4a
20f8e94
bed7072
20f8e94
bed7072
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
import streamlit as st
import pandas as pd
from google.oauth2.service_account import Credentials
import gspread
import time

# --- 1. CONFIGURACIÓN ---
st.set_page_config(page_title="ARZON STUDIOS", layout="wide", initial_sidebar_state="collapsed")

# --- 2. CSS "GOD MODE" (Hack agresivo para Móvil) ---
st.markdown("""
<style>
    /* FUENTES DE LUJO */
    @import url('https://fonts.googleapis.com/css2?family=Playfair+Display:wght@400;500;600&family=Inter:wght@300;400;500;600&display=swap');

    /* LIMPIEZA TOTAL */
    #MainMenu, footer, header, .stDeployButton {display: none;}
    .stApp { background-color: #ffffff; color: #000000; font-family: 'Inter', sans-serif; }
    
    /* MARGENES: En móvil los quitamos casi todos */
    .block-container {
        padding-top: 0rem !important;
        padding-bottom: 2rem !important;
        padding-left: 0.5rem !important;
        padding-right: 0.5rem !important;
        max-width: 100% !important;
    }

    /* =========================================
       EL HACK DEL HEADER (PARA QUE NO SE ROMPA EN CELULAR)
       ========================================= */
    
    /* Forzar contenedor horizontal */
    [data-testid="stHorizontalBlock"] {
        align-items: center !important;
        gap: 0px !important;
    }

    /* REGLAS MAESTRAS PARA COLUMNAS */
    /* En escritorio se ve normal, en móvil forzamos porcentajes */
    @media (max-width: 640px) {
        /* Forzar que las columnas se queden en línea (Row) */
        [data-testid="stHorizontalBlock"] {
            display: flex !important;
            flex-direction: row !important;
            flex-wrap: nowrap !important;
            width: 100% !important;
            justify-content: space-between !important;
        }
        
        /* Ajustar ancho de cada columna para que quepa */
        div[data-testid="column"] {
            width: auto !important;
            flex: 1 !important;
            min-width: 0px !important; /* Permite encogerse */
            padding: 0px !important;
        }
        
        /* El LOGO (Columna 3) recibe más espacio */
        div[data-testid="column"]:nth-of-type(2) {
            flex: 3 !important; /* Más ancho para el texto ARZON */
        }
    }

    /* =========================================
       ESTILO DE LOS ELEMENTOS
       ========================================= */

    /* BOTONES DE TEXTO (MENÚ / BOLSA) */
    .nav-btn button {
        background: transparent !important;
        border: none !important;
        color: #000 !important;
        font-family: 'Inter', sans-serif !important;
        font-size: 11px !important;
        font-weight: 600 !important;
        letter-spacing: 1px !important;
        text-transform: uppercase !important;
        padding: 0 !important;
        margin: 0 !important;
        box-shadow: none !important;
        width: 100% !important;
    }

    /* LOGO (TEXTO GRANDE) */
    .logo-btn button {
        font-family: 'Playfair Display', serif !important;
        font-size: 32px !important;
        letter-spacing: 3px !important;
        text-align: center !important;
        white-space: nowrap !important;
        padding: 0 !important;
        border: none !important;
        background: transparent !important;
        color: black !important;
        box-shadow: none !important;
        width: 100% !important;
    }
    
    /* AJUSTE LOGO EN CELULAR */
    @media (max-width: 640px) {
        .logo-btn button {
            font-size: 18px !important; /* Más pequeño para que quepa */
            letter-spacing: 1px !important;
            margin-top: 5px !important;
        }
        .nav-btn button {
            font-size: 10px !important;
        }
    }

    /* BOTONES DE ACCIÓN (SHOP NOW) */
    .stButton button[kind="primary"] {
        background-color: #000 !important;
        color: #fff !important;
        border: 1px solid #000 !important;
        border-radius: 0px !important;
        padding: 15px !important;
        width: 100% !important;
        text-transform: uppercase;
        font-size: 12px;
        letter-spacing: 2px;
    }
    
    /* SIDEBAR (MENU LATERAL) */
    section[data-testid="stSidebar"] {
        width: 85% !important; /* En celular ocupa casi todo */
        max-width: 400px !important;
        background: white !important;
        border-right: 1px solid #eee;
    }
    
    /* INPUTS */
    div[data-testid="stTextInput"] input {
        border: none !important; border-bottom: 1px solid #ccc !important;
        border-radius: 0 !important; background: transparent !important;
        color: black !important;
    }

</style>
""", unsafe_allow_html=True)

# --- 3. CONEXIÓN DATOS ---
secret_dict = {
  "type": "service_account",
  "project_id": "trhhats",
  "private_key_id": "1555421e0c8cd47026bc9907341110db25be89d3",
  "private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCpDyDrQBSXf0Bi\nr7KTd4P4c0JszG02wl4Wq0AhMK6VV97dK14WfUXhRVvR86Gg38TC1+nT0RRy1F30\ndN9doT7gOx1khZXSmKTEN9jKGRSC381FiMFA3ziinkm5Kq6dDHS2ldLOYOtmwwbd\n0MTDVLH9/qvnW2siTwJlV0oDJbqqZIoJoh9LEGXq8OHe954G1OQka+mBwOOaMhJN\n/gcB6reu6jjO2gHlmG/R544GOSqILBiVXtfkVZUAVeDRyeD9TzVNVnpWrSTpni4E\nig55j2XO295qxI0vNfkiWzNdKOs4Iv+hh7WcJT8X1kLvOaYzZZ+RaZOgCpDoq41w\ncibhw6ntAgMBAAECggEAIXPE58f+Sxv6+YwaoeN8UaU895pb4gID7ChmwCqJ4TNJ\n/imerISNV04KJTk4OkUNAiEHO8qbaT1sefrGWBiYAHayEjn8s3dQ4yLJ2vOrg1oV\nnDS7SMLiygrYO7OeaaUVUyvCUuQKsILW0P2GccBImCHUkiscv+UybCshkg3dKen4\nHYrFCi3T+w86d82KZRj5Oq89lhBu7p8izSItdkaFUWytV7OQr86kiguLZHyRftP6\nDd6gGHRqWvKVaI1/cnHy67Ygz7MINFQ0NCiLnzmb63snp1s+eHjX+8rLrEzIsrB6\nUHvg3ys5iyZAwGxEplcD4ngv4IhVn4D/sQENZRygYQKBgQDqOEWIY6LT88U92lEm\nvyWH2KgpiYlhWiWh8BI3s5ZsVTwdCXoW86S0Mwb0upRpLRRucOTXeBw/XICmzkWf\nydFIcl2/EUSS2fYV42SZbcjQfmjMJjd21R0NQWaoH6oWEKFaRLjYi2hsglnmLIZ+\nM4cvew235O/3+QRZdT7TOnaa/wKBgQC4x6vRZbaRodOQ7Ze8PfwlbEnTIcpwvSpC\nU2ZPYEEdPJUFu5C1qDabtKttjI1sAhJHFe8Q3YbSQdIPoJjJBQijJkg80Hdq6GdV\nZeio2cR31t0i9V9U0ViOnDO5sEyryaypSq6en70f16lLailX9TcmJenJ3vL+fI0p\nM+G1wzbXEwKBgCYSgZL7BzPG01ALlddjiNk9KZCe77roaWeaW4u8YH45mKzrpnHm\npuY3yTCsx4UVM9YD+d7ggk72XV8/9mdT6fYJyR1O1EO+tFa4gNjD1Lm3YpeUur1R\nRQirkeFQTFiL2X6P3zAr8Qx6X9yfbjlDbP0V1pQG3c8EJmXYPh8dyLvHAoGAW3D0\nZjufjZI30JDDdjR2g06DeihOtlvmfcwn5UAM+Rrx5FRd2IfV/lf6PcxAcCLWSLdi\nB0aZYZOREIq5EUGcdKCNPwsrDYzVFj3IVUbvIx8BcDtdYev3lxtVvZ6xUpILD/wV\nTgpe3VMsRFXU/+Ip2IcKmwvp1GZutOUn3XstuGECgYEAu6wQ1UAhnvTnbav5Yait\nIPm7bPaths/u+wDYGCCdSAZGpXqipWD/vdqfrytZOs43OMkcCEvm5SSK6SDhYfiW\nUBrVj4fBIFUuq6f7hXD2AkH4pkkQZZOV1WpplZYTAAzAcpcBZUNAkcJS7ELkEiyl\nC5Tok5nhOW4UQpu8L15xaWo=\n-----END PRIVATE KEY-----\n",
  "client_email": "gestor-rifa@trhhats.iam.gserviceaccount.com",
  "client_id": "100715747150949254160",
  "auth_uri": "https://accounts.google.com/o/oauth2/auth",
  "token_uri": "https://oauth2.googleapis.com/token",
  "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
  "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/gestor-rifa%40trhhats.iam.gserviceaccount.com",
}
WHATSAPP = "522711233984"
SHEET_URL = "https://docs.google.com/spreadsheets/d/1K6Jsg8dZ9ToXQJZuXyn2pLTQTAOFf7Snf7BOA_xS9Rs/edit?usp=sharing"

@st.cache_data(ttl=60)
def cargar_datos():
    try:
        creds = Credentials.from_service_account_info(secret_dict, scopes=["https://www.googleapis.com/auth/spreadsheets"])
        client = gspread.authorize(creds)
        try:
            sheet = client.open_by_url(SHEET_URL).worksheet("Catalogo")
        except:
            sheet = client.open_by_url(SHEET_URL).get_worksheet(0)
        
        data = sheet.get_all_records()
        if not data: return pd.DataFrame()
        df = pd.DataFrame(data)

        cols_map = {}
        for col in df.columns:
            c = col.lower().strip()
            if 'producto' in c: cols_map[col] = 'Producto'
            elif 'precio' in c: cols_map[col] = 'Precio'
            elif 'img' in c: cols_map[col] = 'Imagen'
            elif 'talla' in c: cols_map[col] = 'Tallas'
            elif 'cat' in c: cols_map[col] = 'Categoria'
            elif 'desc' in c: cols_map[col] = 'Descripcion'
            elif 'id' in c: cols_map[col] = 'ID'
        df.rename(columns=cols_map, inplace=True)

        if 'Producto' not in df.columns: return pd.DataFrame()
        
        if 'Precio' in df.columns:
            df['Precio'] = df['Precio'].astype(str).str.replace(r'[$,]', '', regex=True).str.strip()
            df['Precio'] = pd.to_numeric(df['Precio'], errors='coerce').fillna(0)

        return df[df['Producto'].astype(str).str.strip() != '']
    except: return pd.DataFrame()

# --- 4. GESTIÓN DE ESTADO ---
if 'active_drawer' not in st.session_state: st.session_state.active_drawer = None
if 'cart' not in st.session_state: st.session_state.cart = []
if 'page' not in st.session_state: st.session_state.page = 'home'
if 'selected_product' not in st.session_state: st.session_state.selected_product = None
if 'filter_cat' not in st.session_state: st.session_state.filter_cat = 'VIEW ALL'
if 'search_query' not in st.session_state: st.session_state.search_query = ""

df = cargar_datos()

# --- 5. HEADER HÍBRIDO (ESTILO APP NATIVA) ---
# Usamos un contenedor vacío arriba para simular el navbar fijo
st.markdown('<div style="height: 10px;"></div>', unsafe_allow_html=True)

# Lógica inteligente: Si es escritorio mostramos todo, si es celular ocultamos Buscar/Favoritos
# para que quepa el logo grande.
col1, col2, col3 = st.columns([1, 2, 1])

with col1:
    # Botón Menú
    st.markdown('<div class="nav-btn">', unsafe_allow_html=True)
    if st.button("☰ MENÚ", key="nav_menu", use_container_width=True):
        st.session_state.active_drawer = 'menu' if st.session_state.active_drawer != 'menu' else None
        st.rerun()
    st.markdown('</div>', unsafe_allow_html=True)

with col2:
    # Logo Central
    st.markdown('<div class="logo-btn">', unsafe_allow_html=True)
    if st.button("ARZON STUDIOS", key="nav_logo", use_container_width=True):
        st.session_state.page = 'home'
        st.session_state.active_drawer = None
        st.rerun()
    st.markdown('</div>', unsafe_allow_html=True)

with col3:
    # Botón Bolsa
    st.markdown('<div class="nav-btn">', unsafe_allow_html=True)
    bag_label = f"BOLSA ({len(st.session_state.cart)})"
    if st.button(bag_label, key="nav_bag", use_container_width=True):
        st.session_state.active_drawer = 'cart' if st.session_state.active_drawer != 'cart' else None
        st.rerun()
    st.markdown('</div>', unsafe_allow_html=True)

# Botón Buscar debajo del header para celular (opcional, o integrado)
if st.session_state.page == 'home':
    st.markdown("<br>", unsafe_allow_html=True)
    
    # Barra de búsqueda limpia
    c_s1, c_s2 = st.columns([6, 1])
    with c_s1:
        query = st.text_input("BUSCAR", placeholder="Buscar producto...", value=st.session_state.search_query, label_visibility="collapsed")
    with c_s2:
        if st.button("🔍", key="search_go"): pass # Solo visual, el enter funciona
        
    if query != st.session_state.search_query:
        st.session_state.search_query = query
        st.rerun()

st.markdown("---")

# --- 6. LOGICA DE DRAWERS (MENÚ LATERAL) ---
if st.session_state.active_drawer:
    with st.sidebar:
        # MENU
        if st.session_state.active_drawer == 'menu':
            c_close, c_sp = st.columns([1, 4])
            with c_close: 
                if st.button("✕"): 
                    st.session_state.active_drawer = None
                    st.rerun()
            
            st.markdown("<br>", unsafe_allow_html=True)
            
            cats = ["VIEW ALL"]
            if not df.empty and 'Categoria' in df.columns:
                cats += sorted(df['Categoria'].dropna().unique().tolist())
            
            for cat in cats:
                if st.button(cat.upper(), key=f"c_{cat}", use_container_width=True):
                    st.session_state.filter_cat = cat
                    st.session_state.page = 'home'
                    st.session_state.active_drawer = None
                    st.rerun()

        # BOLSA
        elif st.session_state.active_drawer == 'cart':
            c_head, c_cl = st.columns([4, 1])
            with c_head: st.write("SHOPPING BAG")
            with c_cl: 
                if st.button("✕"): 
                    st.session_state.active_drawer = None
                    st.rerun()
            st.markdown("---")

            if not st.session_state.cart:
                st.info("Tu bolsa está vacía.")
                if st.button("IR A COMPRAR", type="primary"):
                    st.session_state.active_drawer = None
                    st.rerun()
            else:
                total = 0
                for i, item in enumerate(st.session_state.cart):
                    c_img, c_info = st.columns([1, 2])
                    with c_img: st.image(item['img'], use_container_width=True)
                    with c_info:
                        st.write(f"**{item['name']}**")
                        st.caption(f"${item['price']}")
                        if st.button("ELIMINAR", key=f"d_{i}"):
                            st.session_state.cart.pop(i)
                            st.rerun()
                    try: total += float(str(item['price']))
                    except: pass
                    st.divider()
                
                st.write(f"**TOTAL: ${total:,.2f}**")
                msg = f"PEDIDO ARZON: ${total}"
                st.link_button("PAGAR WHATSAPP", f"https://wa.me/{WHATSAPP}?text={msg}", type="primary", use_container_width=True)

# --- 7. CONTENIDO (GRID RESPONSIVO) ---
if st.session_state.page == 'home':
    if df.empty:
        st.warning("Cargando catálogo...")
    else:
        d_show = df.copy()
        if st.session_state.filter_cat != "VIEW ALL" and 'Categoria' in d_show.columns:
            d_show = d_show[d_show['Categoria'] == st.session_state.filter_cat]
        if st.session_state.search_query:
            d_show = d_show[d_show.apply(lambda r: st.session_state.search_query.lower() in str(r).lower(), axis=1)]
        
        if d_show.empty:
            st.info("No hay productos.")
        else:
            # GRID: En Streamlit, las columnas se apilan solas en celular.
            # Aquí usamos 3 columnas para PC, que se volverán 1 columna grande en celular automáticamente.
            cols = st.columns(3, gap="large")
            for idx, row in d_show.iterrows():
                with cols[idx % 3]:
                    # Card Producto
                    img = row.get('Imagen', '')
                    if not str(img).startswith('http'): img = "https://via.placeholder.com/600x800"
                    
                    st.image(img, use_container_width=True)
                    st.markdown(f"<div style='text-align:center; font-weight:bold; font-size:12px; margin-top:5px;'>{row.get('Producto','').upper()}</div>", unsafe_allow_html=True)
                    st.markdown(f"<div style='text-align:center; font-size:12px; margin-bottom:10px;'>${row.get('Precio', 0):,.2f}</div>", unsafe_allow_html=True)
                    
                    if st.button("VER PRODUCTO", key=f"bp_{idx}", type="primary", use_container_width=True):
                        st.session_state.selected_product = row.to_dict()
                        st.session_state.page = 'product'
                        st.rerun()
                    st.markdown("<br>", unsafe_allow_html=True)

# PÁGINA PRODUCTO
elif st.session_state.page == 'product' and st.session_state.selected_product:
    p = st.session_state.selected_product
    if st.button("← VOLVER"):
        st.session_state.page = 'home'
        st.rerun()
        
    st.markdown("<br>", unsafe_allow_html=True)
    # En PC 2 columnas, en Celular se apilan (Foto arriba, info abajo)
    c1, c2 = st.columns([1, 1], gap="large")
    
    with c1:
        st.image(p.get('Imagen', ''), use_container_width=True)
    
    with c2:
        st.markdown(f"## {p.get('Producto').upper()}")
        st.markdown(f"### ${p.get('Precio', 0):,.2f}")
        st.write("")
        
        tallas = str(p.get('Tallas', 'UNICA')).split(',')
        size = st.selectbox("TALLA", [t.strip() for t in tallas])
        
        st.markdown("<br>", unsafe_allow_html=True)
        if st.button("AÑADIR A LA BOLSA", type="primary", use_container_width=True):
            st.session_state.cart.append({
                "id": p.get('ID'),
                "name": p.get('Producto'),
                "price": p.get('Precio'),
                "size": size,
                "img": p.get('Imagen')
            })
            st.session_state.active_drawer = 'cart'
            st.rerun()
        
        st.markdown("---")
        st.write(p.get('Descripcion', ''))