# Generated by detroit
# See https://github.com/bourbonut/detroit/tree/main/api_maker

from functools import partial
from operator import is_not

class local:
    def __init__(self, content="local"):
        self.content = content

    def __repr__(self):
        return self.content

    def __str__(self):
        return self.content

    def __call__(self, *args):
        arguments = ", ".join(map(repr, args))
        return f"{self}({arguments})"

    def set(self, node=None, value=None):
        """
        Source · Sets the value of this local on the specified node to the value, and returns
        the specified value. This is often performed using selection.each:
        .. code:: javascript

            selection.each(function(d) {
              foo.set(this, d.value);
            });

        If you are just setting a single variable, consider using selection.property:
        .. code:: javascript

            selection.property(foo, (d) => d.value);


        See more informations `here <https://d3js.org/d3-selection/locals#local_set>`_.
        """
        arguments = ", ".join(map(repr, filter(partial(is_not, None), (node, value))))
        return local(content=f"{self.content}.set({arguments})")


    def get(self, node=None):
        """
        Source · Returns the value of this local on the specified node.
        .. code:: javascript

            selection.each(function() {
              const value = foo.get(this);
            });

        If the node does not define this local, returns the value from the nearest ancestor
        that defines it. Returns undefined if no ancestor defines this local.

        See more informations `here <https://d3js.org/d3-selection/locals#local_get>`_.
        """
        arguments = ", ".join(map(repr, filter(partial(is_not, None), (node,))))
        return local(content=f"{self.content}.get({arguments})")


    def remove(self, node=None):
        """
        Source · Deletes this local’s value from the specified node.
        .. code:: javascript

            selection.each(function() {
              foo.remove(this);
            });

        Returns true if the node defined this local prior to removal, and false otherwise. If
        ancestors also define this local, those definitions are unaffected, and thus local.get
        will still return the inherited value.

        See more informations `here <https://d3js.org/d3-selection/locals#local_remove>`_.
        """
        arguments = ", ".join(map(repr, filter(partial(is_not, None), (node,))))
        return local(content=f"{self.content}.remove({arguments})")


    def toString(self):
        """
        Source · Returns the automatically-generated identifier for this local. This is the
        name of the property that is used to store the local’s value on elements, and thus you
        can also set or get the local’s value using element[local] or by using
        selection.property.

        See more informations `here <https://d3js.org/d3-selection/locals#local_toString>`_.
        """
        return local(content=f"{self.content}.toString()")

