<commit_before>// TODO-3 move copy to content directory
const {nav, div, a, ul, span, p} = require('../../modules/tags')
const menuItem = require('./menu_item.tmpl')
const {extend} = require('../../modules/utilities')
const {ucfirst, underscored} = require('../../modules/auxiliaries')
const icon = require('./icon.tmpl')

// TODO-2 add unread count to notices icon

// A list of all menu items and their configurations
const items = {
    home: { url: '/' },
    my_sets: { title: 'My Sets', icon: 'set' },
    log_in: { title: 'Log In', icon: 'log-in' },
    terms: { },
    contact: { },
    notices: { },  // TODO-2 poll and show unread count
    settings: { },
    log_out: { url: '#log_out', title: 'Log Out', icon: 'log-out' },
    search: { },
    current_set: { url: '/sets/{id}/tree', title: 'Current Set', icon: 'set' },
    current_unit: { url: '/units/{id}', title: 'Current Unit', icon: 'unit' },
    /* TP@ discuss_card: {
        url: '/search?kind=topic&q={id}',
        title: 'Discuss Card',
        icon: 'post',
    } */
}

// For items that don't have them
// Use the name to populate title and url automatically
// And set the default icon to be painfully obviously wrong
Object.keys(items).forEach(name => {
    items[name] = extend({
        name: name,
        title: ucfirst(name),
        url: '/' + underscored(name),
        icon: name,
    }, items[name] || {})
})

// For each state, a list of the menu items to appear
const menus = {
    loggedOut: [
        'home',
        'log_in',
        'contact',
        'terms',
    ],
    loggedIn: [
        'my_sets',
        'search',
        'notices',
        'settings',
        'contact',
        'terms',
        'log_out',
    ]
}

const addContextItems = (menuItems, {/* TP@ card, */unit, set}) => {
    menuItems = menuItems.slice()

    if (set) {
        const currentSet = extend(items.current_set)
        currentSet.url = currentSet.url.replace('{id}', set)
        menuItems.push(currentSet)
    }

    if (unit) {
        const currentUnit = extend(items.current_unit)
        currentUnit.url = currentUnit.url.replace('{id}', unit)
        menuItems.push(currentUnit)
    }

    /* TP@ if (card) {
        const discuss = extend(items.discuss_card)
        discuss.url = discuss.url.replace('{id}', card)
        menuItems.push(discuss)
    } */

    return menuItems
}

module.exports = (data) => {
    let menuItems = menus[data.kind].map((name) => items[name])
    menuItems = addContextItems(menuItems, data.context)
    return nav(
        {className: data.open ? 'menu selected' : 'menu'},
        [<commit_msg>Add create to menu<commit_after>// TODO-3 move copy to content directory
const {nav, div, a, ul, span, p} = require('../../modules/tags')
const menuItem = require('./menu_item.tmpl')
const {extend} = require('../../modules/utilities')
const {ucfirst, underscored} = require('../../modules/auxiliaries')
const icon = require('./icon.tmpl')

// TODO-2 add unread count to notices icon

// A list of all menu items and their configurations
const items = {
    home: { url: '/' },
    my_sets: { title: 'My Sets', icon: 'set' },
    log_in: { title: 'Log In', icon: 'log-in' },
    terms: { },
    contact: { },
    notices: { },  // TODO-2 poll and show unread count
    settings: { },
    log_out: { url: '#log_out', title: 'Log Out', icon: 'log-out' },
    search: { },
    discuss_card: {
        url: '/search?kind=topic&q={id}',
        title: 'Discuss Card',
        icon: 'post',
    },
    discuss_unit: {
        url: '/search?kind=topic&q={id}',
        title: 'Discuss Unit',
        icon: 'post',
    },
    discuss_set: {
        url: '/search?kind=topic&q={id}',
        title: 'Discuss Set',
        icon: 'post',
    },
    create: { }
}

// For items that don't have them
// Use the name to populate title and url automatically
// And set the default icon to be painfully obviously wrong
Object.keys(items).forEach(name => {
    items[name] = extend({
        name: name,
        title: ucfirst(name),
        url: '/' + underscored(name),
        icon: name,
    }, items[name] || {})
})

// For each state, a list of the menu items to appear
const menus = {
    loggedOut: [
        'home',
        'log_in',
        'search',
        'contact',
        'terms',
    ],
    loggedIn: [
        'my_sets',
        'search',
        'notices',
        'create',
        'settings',
        'contact',
        'terms',
        'log_out',
    ]
}

const addContextItems = (menuItems /* , TP@ {card, unit, set} */) => {
    menuItems = menuItems.slice()

    /* TP@
    if (card) {
        const discuss = extend(items.discuss_card)
        discuss.url = discuss.url.replace('{id}', card)
        menuItems.push(discuss)
        return menuItems
    }

    if (unit) {
        const discuss = extend(items.discuss_unit)
        discuss.url = discuss.url.replace('{id}', unit)
        menuItems.push(discuss)
        return menuItems
    }

    if (set) {
        const discuss = extend(items.discuss_set)
        discuss.url = discuss.url.replace('{id}', set)
        menuItems.push(discuss)
        return menuItems
    }
    */

    return menuItems
}

module.exports = (data) => {
    let menuItems = menus[data.kind].map((name) => items[name])
    menuItems = addContextItems(menuItems, data.context)
    return nav(
        {className: data.open ? 'menu selected' : 'menu'},
        [
{'fraction_non_alphanumeric': 0.164079822616408, 'fraction_numerical': 0.0011086474501108647, 'mean_word_length': 2.3228974831184774, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1774612', 'n_tokens_mistral': 1743, 'n_tokens_neox': 1724, 'n_words': 455}