<commit_before>"use strict";

const DropdownListWidget = function (opts) {
    const init = () => {
        // Run basic sanity checks on opts, and set up sane defaults.
        opts = Object.assign(
            {
                null_value: null,
                render_text: (item_name) => item_name,
                on_update: () => {},
            },
            opts,
        );
        opts.container_id = `${opts.widget_name}_widget`;
        opts.value_id = `id_${opts.widget_name}`;
        if (opts.value === undefined) {
            opts.value = opts.null_value;
            blueslip.warn("dropdown-list-widget: Called without a default value; using null value");
        }
    };
    init();

    const render_dropdown_list = require("../templates/settings/dropdown_list.hbs");

    const render = (value) => {
        $(`#${opts.container_id} #${opts.value_id}`).data("value", value);

        const elem = $(`#${opts.container_id} #${opts.widget_name}_name`);

        if (!value || value === opts.null_value) {
            elem.text(opts.default_text);
            elem.addClass("text-warning");
            elem.closest(".input-group").find(".dropdown_list_reset_button:not([disabled])").hide();
            return;
        }

        // Happy path
        const item = opts.data.find((x) => x.value === value.toString());
        const text = opts.render_text(item.name);
        elem.text(text);
        elem.removeClass("text-warning");
        elem.closest(".input-group").find(".dropdown_list_reset_button:not([disabled])").show();
    };

    const update = (value) => {
        render(value);<commit_msg>dropdown_list_widget: Move require to top level.<commit_after>"use strict";

const render_dropdown_list = require("../templates/settings/dropdown_list.hbs");

const DropdownListWidget = function (opts) {
    const init = () => {
        // Run basic sanity checks on opts, and set up sane defaults.
        opts = Object.assign(
            {
                null_value: null,
                render_text: (item_name) => item_name,
                on_update: () => {},
            },
            opts,
        );
        opts.container_id = `${opts.widget_name}_widget`;
        opts.value_id = `id_${opts.widget_name}`;
        if (opts.value === undefined) {
            opts.value = opts.null_value;
            blueslip.warn("dropdown-list-widget: Called without a default value; using null value");
        }
    };
    init();

    const render = (value) => {
        $(`#${opts.container_id} #${opts.value_id}`).data("value", value);

        const elem = $(`#${opts.container_id} #${opts.widget_name}_name`);

        if (!value || value === opts.null_value) {
            elem.text(opts.default_text);
            elem.addClass("text-warning");
            elem.closest(".input-group").find(".dropdown_list_reset_button:not([disabled])").hide();
            return;
        }

        // Happy path
        const item = opts.data.find((x) => x.value === value.toString());
        const text = opts.render_text(item.name);
        elem.text(text);
        elem.removeClass("text-warning");
        elem.closest(".input-group").find(".dropdown_list_reset_button:not([disabled])").show();
    };

    const update = (value) => {
        render(value);
{'fraction_non_alphanumeric': 0.16012176560121766, 'fraction_numerical': 0.0, 'mean_word_length': 2.1996105160662123, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '7371018', 'n_tokens_mistral': 954, 'n_tokens_neox': 940, 'n_words': 174}