<commit_before>package lt.inventi.wicket.component.bootstrap;

import java.io.Serializable;

import org.apache.wicket.AttributeModifier;
import org.apache.wicket.Component;
import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.markup.head.IHeaderResponse;
import org.apache.wicket.markup.head.JavaScriptHeaderItem;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.border.Border;
import org.apache.wicket.model.AbstractReadOnlyModel;
import org.apache.wicket.model.IModel;

import lt.inventi.wicket.resource.ResourceSettings;

/**
 * Groups used inside of bootstrap accordion (Collapse).
 *
 * @author vplatonov
 * @see Accordion
 *
 */
public class AccordionGroup extends Border {

    public static class Options implements Serializable {
        private boolean collapsed = true;
        private boolean hasParent = true;

        public static Options collapsed() {
            return new Options().setCollapsed(true);
        }

        public static Options unCollapsed() {
            return new Options().setCollapsed(false);
        }

        public Options withoutParent() {
            return setHasParent(false);
        }

        public Options setHasParent(boolean hasParent) {
            this.hasParent = hasParent;
            return this;
        }

        public Options setCollapsed(boolean collapsed) {
            this.collapsed = collapsed;
            return this;
        }
    }

    private final Label label;
    private final Options options;

    public AccordionGroup(String id, IModel<String> labelModel) {
        this(id, labelModel, new Options());
    }

    public AccordionGroup(String id, IModel<String> labelModel, Options options) {
        super(id);
        setRenderBodyOnly(true);
        label = new Label("label", labelModel);
        this.options = options;
    }

    @Override
    protected void onInitialize() {
        super.onInitialize();

        WebMarkupContainer body = new WebMarkupContainer("body");
        body.setOutputMarkupId(true);

        if (options.collapsed) {
            body.add(new AttributeAppender("class", " collapse"));
        } else {
            body.add(new AttributeAppender("class", " in"));
        }
        if (options.hasParent) {
            label.add(new AttributeModifier("data-parent", idModel(getAccordionParent())));
        }
        label.add(new AttributeModifier("href", idModel(body)));

        addToBorder(label, body);
    }

    private Component getAccordionParent() {
        Component parent = getParent();
        while (!(parent instanceof Accordion)) {
            parent = getParent();
            if (parent == null) {
                throw new IllegalStateException("No Accordion parent found for group: " + this);
            }
        }<commit_msg>Fix accordion group parent resolution<commit_after>package lt.inventi.wicket.component.bootstrap;

import java.io.Serializable;

import org.apache.wicket.AttributeModifier;
import org.apache.wicket.Component;
import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.markup.head.IHeaderResponse;
import org.apache.wicket.markup.head.JavaScriptHeaderItem;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.border.Border;
import org.apache.wicket.model.AbstractReadOnlyModel;
import org.apache.wicket.model.IModel;

import lt.inventi.wicket.resource.ResourceSettings;

/**
 * Groups used inside of bootstrap accordion (Collapse).
 *
 * @author vplatonov
 * @see Accordion
 *
 */
public class AccordionGroup extends Border {

    public static class Options implements Serializable {
        private boolean collapsed = true;
        private boolean hasParent = true;

        public static Options collapsed() {
            return new Options().setCollapsed(true);
        }

        public static Options unCollapsed() {
            return new Options().setCollapsed(false);
        }

        public Options withoutParent() {
            return setHasParent(false);
        }

        public Options setHasParent(boolean hasParent) {
            this.hasParent = hasParent;
            return this;
        }

        public Options setCollapsed(boolean collapsed) {
            this.collapsed = collapsed;
            return this;
        }
    }

    private final Label label;
    private final Options options;

    public AccordionGroup(String id, IModel<String> labelModel) {
        this(id, labelModel, new Options());
    }

    public AccordionGroup(String id, IModel<String> labelModel, Options options) {
        super(id);
        setRenderBodyOnly(true);
        label = new Label("label", labelModel);
        this.options = options;
    }

    @Override
    protected void onInitialize() {
        super.onInitialize();

        WebMarkupContainer body = new WebMarkupContainer("body");
        body.setOutputMarkupId(true);

        if (options.collapsed) {
            body.add(new AttributeAppender("class", " collapse"));
        } else {
            body.add(new AttributeAppender("class", " in"));
        }
        if (options.hasParent) {
            label.add(new AttributeModifier("data-parent", idModel(getAccordionParent())));
        }
        label.add(new AttributeModifier("href", idModel(body)));

        addToBorder(label, body);
    }

    private Component getAccordionParent() {
        Component parent = getParent();
        while (!(parent instanceof Accordion)) {
            parent = parent.getParent();
            if (parent == null) {
                throw new IllegalStateException("No Accordion parent found for group: " + this);
            }
        }
{'fraction_non_alphanumeric': 0.09984480082772892, 'fraction_numerical': 0.0, 'mean_word_length': 2.694267515923567, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '1571138', 'n_tokens_mistral': 1572, 'n_tokens_neox': 1538, 'n_words': 356}