import os 


def ls_html(    ):
    print('10:')
    html = [] 
    path = path.replace('/@', '@')
    path_tokens = ['ls.html' ]+path.split('/')
    #head code 
    html.append('<meta charset="UTF-8">')
    html.append('<meta name="viewport" content="width=device-width, initial-scale=1.0">')
    html.append(f'<title>{title} (len:{len(ls)})</title>')
    html.append(f'<link rel="stylesheet" href="/getFile/main.css" type="text/css" >')
    html.append("""<style>
        body{
            font-family:monospace;
            font-size: 0.9rem;
            line-height: 1.3rem;
            
        }
        a:hover{font-weight: bold;}
        img{width:100%}
                
        
    </style>""")
    
    #body 
    html.append('<body>')

    #elm/searchBox 
    html.append(f"""
        <div id="searchBox">
            <input id="searchInput" >
            <div id="liveList"></div>
        </div>
        <form action="/uploadFile/" enctype="multipart/form-data" method="post">
            <input name="path" hidden value="{path}">        
            <input name="file" type="file" required="">
            <input type="submit" value="Upload File">
        </form>

    """)
    #elm/breadcrumb  
    if 1:
        #token of breadcrumb 
        html.append(f'<div>')  
        for i, token in enumerate(path_tokens[0:-1]):
            if token == 'ls.html': token ='home'
            html.append(f'<a href="/{"/".join(path_tokens[0:i + 1])}{queryParams}">{token}</a>/')    
        
        #last token 
        html.append(f'<b>{title}</b>')  
        #html.append(f'  ?{queryParams.replace("&", " &")}')  

        #queryParams 
        html.append(f'  {queryParams}')  
        html.append('<div>')
    html.append(f'len: {len(ls)}')
    
    
    ########################################
    #ls of entry code
    target_attr = 'target='+args['target'] if 'target'in args else ''
    #print('296: target_attr:', target_attr, args)
    html.append('<div class="main-ls">')
    for entryName in sorted(ls):
        #UTF con   📂	📄	📑	🗂️	🗄️	🗃️	
        entryIcon = ''
        entry_path = f'{tmp_path}/{entryName}'
        #if path is empty than use only entryName
        
        if tpp: src = tpp+'/'+path +'/'+entryName if path else entryName 
        else  : src = path +'/'+entryName if path else entryName 
        
        
            
        if   os.path.isdir(entry_path) : 
            entryIcon = '📂'; 
            if tpp:  href_str = f'/{src}{queryParams}'
            else  :  href_str = f'/ls.html/{src}{queryParams}'
        elif os.path.isfile(entry_path): entryIcon = '📄'; href_str = f'/getFile/{src}'
        
        #this code use to obean app 
        if   entryName.endswith('.oba')    : entryIcon = f'<a href=/{src}/>(OBA)</a>'  

        html.append(f'{entryIcon} <a href="{href_str}" {target_attr} >{entryName}</a><br>')
        
        #img file view
        if 'imgView' in args and entryName.endswith(('.jpg', '.webp', '.png')):
            html.append(f'<img src="/getFile/{src}"/><br>')
    html.append('</div>')

    #js code 
    #html.append(f"""<script></script>""")
    #html.append('<script src="/getFile/main.js"></script>')
    #html.append('<script src="/getFile/lib-js/liveSearch.js"></script>')
    #html.append('<script src="/getFile/lib-js/lxReq.js"></script>')
    html.append('</body')
    #print('251:', html)
    return html
