import Container from "./Container.wrn"

component Section {
  props {
    id: string = ""
    size: string = "default"
    color: string = "primary"
    variant: string = "default"
    spacing: string = "lg"
    maxWidth: string = "xl"
    fullWidth: boolean = false
    borderTop: boolean = false
    borderBottom: boolean = false
    class: string = ""
  }

  view {
    <section
      {...attrs}
      data-ui-component="Section"
      class='wire-section {class}'
      id='{id}'
      data-size='{size}'
      data-color='{color}'
      data-variant='{variant}'
      data-spacing='{spacing}'
      data-border-top='{borderTop}'
      data-border-bottom='{borderBottom}'
    >
      {#if fullWidth}
        <slot></slot>
      {:else}
        <Container
          columns="1"
          gap="md"
          maxWidth='{maxWidth}'
          size='{size}'
          color='{color}'
        >
          <slot></slot>
        </Container>
      {/if}
    </section>
  }

  style {
    .wire-section {
      --section-tint: transparent;
      --section-ink: inherit;
      position: relative;
      isolation: isolate;
      width: 100%;
      min-width: 0;
      padding-block: 3rem;
      background: var(--section-tint);
      color: var(--section-ink);
    }

    .wire-section[data-spacing="sm"] {
      padding-block: 2rem;
    }

    .wire-section[data-spacing="md"] {
      padding-block: 3rem;
    }

    .wire-section[data-spacing="xl"] {
      padding-block: 5rem;
    }

    .wire-section[data-variant="soft"] {
      --section-tint: var(--wire-color-surface-soft);
    }

    .wire-section[data-variant="raised"] {
      --section-tint: var(--wire-color-surface-raised);
    }

    /*
     * tinted and solid pick their fill from the component colour, which is
     * why these are two attributes rather than one class per pairing. The
     * previous version spent a line on every variant and colour combination.
     */
    .wire-section[data-variant="tinted"][data-color="primary"] {
      --section-tint: var(--wire-color-primary-soft);
    }

    .wire-section[data-variant="tinted"][data-color="success"] {
      --section-tint: var(--wire-color-success-soft);
    }

    .wire-section[data-variant="tinted"][data-color="warning"] {
      --section-tint: var(--wire-color-warning-soft);
    }

    .wire-section[data-variant="tinted"][data-color="danger"] {
      --section-tint: var(--wire-color-danger-soft);
    }

    .wire-section[data-variant="tinted"][data-color="info"] {
      --section-tint: var(--wire-color-info-soft);
    }

    .wire-section[data-variant="solid"][data-color="primary"] {
      --section-tint: var(--wire-color-primary);
      --section-ink: var(--wire-color-on-primary);
    }

    .wire-section[data-variant="solid"][data-color="danger"] {
      --section-tint: var(--wire-color-danger);
      --section-ink: var(--wire-color-on-danger);
    }

    .wire-section[data-border-top="true"] {
      border-top: 1px solid var(--wire-color-border);
    }

    .wire-section[data-border-bottom="true"] {
      border-bottom: 1px solid var(--wire-color-border);
    }

    @media (min-width: 640px) {
      .wire-section[data-spacing="lg"] {
        padding-block: 5rem;
      }

      .wire-section[data-spacing="xl"] {
        padding-block: 6rem;
      }
    }
  }
}
