import type { Meta, StoryObj } from '@storybook/vue3-vite';
import { defineComponent, h } from 'vue';

const ThemePlaceholder = defineComponent({
  name: 'ThemePlaceholder',
  render() {
    return h('div');
  },
});

const meta: Meta<typeof ThemePlaceholder> = {
  title: 'CSS utility/Border',
  component: ThemePlaceholder,
  tags: ['autodocs'],
  parameters: {
    layout: 'fullscreen',
  },
};

export default meta;
type Story = StoryObj<typeof ThemePlaceholder>;

const copyScript = `
  function copyToClipboard(text, el) {
    navigator.clipboard.writeText(text).then(() => {
      el.classList.add('copied');
      setTimeout(() => el.classList.remove('copied'), 1500);
    });
  }
`;

/**
 * Surface border colors for general UI elements like cards, panels, and dividers.
 * Default is for standard borders, focus-ring for keyboard focus indicators.
 */
export const Surface: Story = {
  render: () => ({
    template: `
      <div class="p-8 bg-white dark:bg-background">
        <style>
          .copy-btn { cursor: pointer; transition: all 0.15s; }
          .copy-btn:hover { background: rgba(0,0,0,0.05); }
          .copy-btn.copied { background: #22c55e22; }
          .copy-btn.copied::after { content: ' ✓'; color: #22c55e; }
        </style>
        <script>${copyScript}</script>
        
        <div class="mb-6">
          <h2 class="heading-s text-content-on-surface-primary mb-1">surface</h2>
          <p class="body-14-regular text-content-on-surface-muted">Border colors for general UI elements and focus rings. Click class name to copy.</p>
        </div>
        
        <div class="flex flex-wrap gap-6">
          <div class="flex flex-col items-center gap-1.5">
            <div class="w-16 h-16 rounded-md bg-background-surface-primary border-4 border-border-surface-default"></div>
            <div class="text-center">
              <span class="label-12-medium text-content-on-surface-primary block">default</span>
              <code class="copy-btn label-12-regular text-content-on-surface-muted block mt-0.5 px-1 py-0.5 rounded" onclick="copyToClipboard('border-border-surface-default', this)">border-border-surface-default</code>
            </div>
          </div>
          
          <div class="flex flex-col items-center gap-1.5">
            <div class="w-16 h-16 rounded-md bg-background-surface-primary border-4 border-border-surface-focus-ring"></div>
            <div class="text-center">
              <span class="label-12-medium text-content-on-surface-primary block">focus-ring</span>
              <code class="copy-btn label-12-regular text-content-on-surface-muted block mt-0.5 px-1 py-0.5 rounded" onclick="copyToClipboard('border-border-surface-focus-ring', this)">border-border-surface-focus-ring</code>
            </div>
          </div>
        </div>
      </div>
    `,
  }),
};

/**
 * Input border colors for form fields in different states.
 * Default for resting state, hover for mouse interaction, error for validation feedback.
 */
export const Input: Story = {
  render: () => ({
    template: `
      <div class="p-8 bg-white dark:bg-background">
        <style>
          .copy-btn { cursor: pointer; transition: all 0.15s; }
          .copy-btn:hover { background: rgba(0,0,0,0.05); }
          .copy-btn.copied { background: #22c55e22; }
          .copy-btn.copied::after { content: ' ✓'; color: #22c55e; }
        </style>
        <script>${copyScript}</script>
        
        <div class="mb-6">
          <h2 class="heading-s text-content-on-surface-primary mb-1">input</h2>
          <p class="body-14-regular text-content-on-surface-muted">Border colors for input fields and form elements. Click class name to copy.</p>
        </div>
        
        <div class="flex flex-wrap gap-6">
          <div class="flex flex-col items-center gap-1.5">
            <div class="w-16 h-16 rounded-md bg-background-surface-primary border-4 border-border-input-default"></div>
            <div class="text-center">
              <span class="label-12-medium text-content-on-surface-primary block">default</span>
              <code class="copy-btn label-12-regular text-content-on-surface-muted block mt-0.5 px-1 py-0.5 rounded" onclick="copyToClipboard('border-border-input-default', this)">border-border-input-default</code>
            </div>
          </div>
          
          <div class="flex flex-col items-center gap-1.5">
            <div class="w-16 h-16 rounded-md bg-background-surface-primary border-4 border-border-input-hover"></div>
            <div class="text-center">
              <span class="label-12-medium text-content-on-surface-primary block">hover</span>
              <code class="copy-btn label-12-regular text-content-on-surface-muted block mt-0.5 px-1 py-0.5 rounded" onclick="copyToClipboard('border-border-input-hover', this)">border-border-input-hover</code>
            </div>
          </div>
          
          <div class="flex flex-col items-center gap-1.5">
            <div class="w-16 h-16 rounded-md bg-background-surface-primary border-4 border-border-input-error"></div>
            <div class="text-center">
              <span class="label-12-medium text-content-on-surface-primary block">error</span>
              <code class="copy-btn label-12-regular text-content-on-surface-muted block mt-0.5 px-1 py-0.5 rounded" onclick="copyToClipboard('border-border-input-error', this)">border-border-input-error</code>
            </div>
          </div>
        </div>
      </div>
    `,
  }),
};

/**
 * Button border color for outlined button variants that need visible boundaries.
 */
export const Button: Story = {
  render: () => ({
    template: `
      <div class="p-8 bg-white dark:bg-background">
        <style>
          .copy-btn { cursor: pointer; transition: all 0.15s; }
          .copy-btn:hover { background: rgba(0,0,0,0.05); }
          .copy-btn.copied { background: #22c55e22; }
          .copy-btn.copied::after { content: ' ✓'; color: #22c55e; }
        </style>
        <script>${copyScript}</script>
        
        <div class="mb-6">
          <h2 class="heading-s text-content-on-surface-primary mb-1">button</h2>
          <p class="body-14-regular text-content-on-surface-muted">Border colors for outlined buttons. Click class name to copy.</p>
        </div>
        
        <div class="flex flex-wrap gap-6">
          <div class="flex flex-col items-center gap-1.5">
            <div class="w-16 h-16 rounded-md bg-background-surface-primary border-4 border-border-button-outlined"></div>
            <div class="text-center">
              <span class="label-12-medium text-content-on-surface-primary block">outlined</span>
              <code class="copy-btn label-12-regular text-content-on-surface-muted block mt-0.5 px-1 py-0.5 rounded" onclick="copyToClipboard('border-border-button-outlined', this)">border-border-button-outlined</code>
            </div>
          </div>
        </div>
      </div>
    `,
  }),
};
