# -*- coding: utf-8 -*-
"""submit_order 디버깅"""
import sys; sys.path.insert(0, '.'); import wholesale_path
from bs4 import BeautifulSoup
import re

import importlib
import wholesale.sooin
importlib.reload(wholesale.sooin)
from wholesale import SooinSession

SooinSession._instance = None
s = SooinSession()
s.login()
s.clear_cart()

# 품목 담기
r1 = s.search_products('코자정')
s.add_to_cart(r1['items'][0]['internal_code'], qty=1, price=r1['items'][0]['price'], stock=r1['items'][0]['stock'])

# 취소
s.cancel_item(row_index=0)

# Bag.asp GET
print('=== Bag.asp GET 후 form 분석 ===')
resp = s.session.get(f'{s.BAG_VIEW_URL}?currVenCd={s.vendor_code}', timeout=15)
soup = BeautifulSoup(resp.content, 'html.parser')
form = soup.find('form', {'id': 'frmBag'})

form_data = {}
for inp in form.find_all('input'):
    name = inp.get('name', '')
    if not name:
        continue
    
    inp_type = inp.get('type', 'text').lower()
    
    if inp_type == 'checkbox':
        checked = inp.get('checked')
        print(f"체크박스 {name}: checked={checked}, type={type(checked)}")
        
        if checked is not None:
            form_data[name] = 'on'
            print(f"  → form_data['{name}'] = 'on' (취소됨, 제외)")
        else:
            print(f"  → 안 보냄 (활성, 포함)")
        continue
    
    form_data[name] = inp.get('value', '')

print(f"\n체크박스 관련 form_data: {[(k,v) for k,v in form_data.items() if 'chk' in k]}")
