import CardStack from './card-stack';

/**\

    title: CardStackLeaf
    category: interface
    description:
        A representation of the basic structure of a leaf in
        a CardStack.

\**/
class CardStackLeaf {
    // The view is what gets rendered when the leaf shows up in the stack
    view = null;

    // allowBack lets the stack navigation know if it should render a
    // back / close button when on this leaf
    allowBack = false;

    card = null;

    constructor(card) {
        if (!(card instanceof CardStack)) {
            throw new Error('Card must be an instance of a CardStack');
        }

        this.card = card;
    }

    // getProps is called when the stack is rendered
    getProps() {
        return {
            onDone: this.onDone.bind(this)
        };
    }

    // onDone is called when the stack is removed
    onDone() {
        this.card.next();
    }
}

export default CardStackLeaf;
