# `PhoenixKitLocations.Web.Components.PlacePicker`
[🔗](https://github.com/BeamLabEU/phoenix_kit_locations/blob/0.4.2/lib/phoenix_kit_locations/web/components/place_picker.ex#L1)

LiveComponent for picking a Location, and optionally a Space inside
it, in one widget — a search-combobox for the Location half and the
existing `SpaceTree` (read-only picker mode) for the Space half.

Drop one into any LiveView. Each instance owns its own search/tree
state; the parent only reacts to one message:

    {:place_picker_select, id, %{location_uuid: uuid, space_uuid: uuid_or_nil}}

`space_uuid` is `nil` when the user picks "Use this location (no
specific space)" instead of drilling into the tree. The tree stays
open after a selection, so a consumer can immediately pick a
different node without re-searching for the Location.

## Two halves

  * **Location** — a search-combobox mirroring
    `PhoenixKitCatalogue.Web.Components.ItemPicker`: type to filter,
    click a result to select. Locations are typically few, so
    filtering happens in Elixir over `Locations.list_locations/1`'s
    full result rather than a dedicated search function (unlike
    `Catalogue.search_items/2`).
  * **Space** — once a Location is picked, its tree
    (`Spaces.list_tree/1`) renders through `SpaceTree.space_tree/1`
    with `show_actions={false}` — the same read-only mode built for
    this purpose. Selecting a node, or the "Use this location"
    button above the tree, sends the `:place_picker_select` message.

## Attrs

  * `:id` (required) — unique DOM/component id, echoed back in every
    `:place_picker_select` message.
  * `:location_type_uuid` — restricts the Location search to this
    type. Resolve the uuid yourself via
    `Locations.get_location_type_by_name/1` first — this component
    doesn't resolve type names itself, keeping its own API small.
    `nil` (default) searches every active Location.
  * `:selected_location_uuid`, `:selected_space_uuid` — optional,
    default `nil`. `:selected_space_uuid` seeds the tree's **initial**
    highlight (`space_tree/1`'s `selected_uuid`). The component's
    `update/2` applies these attrs only on first mount (seed-once
    semantics); from then on it tracks selection locally as the user
    picks nodes (clearing back to `nil` on `select_location` /
    `clear_location` / "Use this location"). A consumer can pass a
    static `selected_space_uuid` without having to echo every local
    update back — the seed is honored once and then the component
    manages the highlight itself. `:selected_location_uuid` is
    accepted for symmetry but not currently consumed — the Location
    half is always driven by the search-combobox in this version.
  * `:locale` — when given, Location names (search results and the
    selected-location heading) show the translated name, same
    `_name`/`name` fallback chain as `Spaces.full_path/2`. `nil`
    (default) always shows the primary-language name. Space names
    inside the tree are not translated — `SpaceTree` itself doesn't
    support that (existing limitation, unrelated to this component).

## Usage

    type = Locations.get_location_type_by_name("Warehouse")

    <.live_component
      module={PhoenixKitLocations.Web.Components.PlacePicker}
      id="picker-1"
      location_type_uuid={type && type.uuid}
    />

---

*Consult [api-reference.md](api-reference.md) for complete listing*
